Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 0e85879

Browse files
author
DEKHTIARJonathan
committed
[TF-TRT] v2.0.0 - XLA FP16 Fix && HF BERT/BART Re-Alignment
1 parent 41bbfde commit 0e85879

File tree

9 files changed

+201
-174
lines changed

9 files changed

+201
-174
lines changed

tftrt/benchmarking-python/CHANGELOG.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ Description of the change
3030
## How To Update The Changelog for a New Release ?
3131

3232
- **Major Version:** Major refactoring, or changes that make the data
33-
non-comparable with any previous release of the benchmark.
34-
Changes in shell scripts are to be expected.
33+
non-comparable with any previous release of the benchmark.
34+
Changes in shell scripts are to be expected.
3535

3636
- **Minor Version:** Changes that add a new functionality though not modifying
37-
existing metrics or models scripts in a way that would make
38-
metrics not comparable between minor releases.
37+
existing metrics or models scripts in a way that would make
38+
metrics not comparable between minor releases.
3939

4040
- **Patch Version:** Changes that are expected to have no change to the
4141
operation of the benchmark nor the way metrics are
@@ -46,6 +46,16 @@ Description of the change
4646

4747
<!-- YOU CAN EDIT FROM HERE -->
4848

49+
## [2.0.0] - 2022.08.04 - @DEKHTIARJonathan
50+
51+
- Fix for XLA FP16 actually not being applied due to `"min_graph_nodes": -1`
52+
missing. Therefore AMP skipped when XLA is able to compile the whole graph in
53+
virtually one node.
54+
55+
- HF BERT & BART target changed:
56+
- `TFBertForPreTraining` -> `TFBertModel`
57+
- `TFBartForConditionalGeneration` -> `TFBartModel`
58+
4959
## [1.2.0] - 2022.07.31 - @DEKHTIARJonathan
5060

5161
Setting up the benchmarking suite to allow remote upload and storage of the

tftrt/benchmarking-python/benchmark_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# The `__version__` number shall be updated everytime core benchmarking files
1111
# are updated.
1212
# Please update CHANGELOG.md with a description of what this version changed.
13-
__version__ = "1.2.0"
13+
__version__ = "2.0.0"
1414

1515

1616
def get_commit_id():

tftrt/benchmarking-python/benchmark_runner.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,20 @@ def load_model_from_disk(
243243
signature_key=signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY,
244244
precision="FP32"
245245
):
246+
247+
tf.config.optimizer.set_experimental_options({
248+
"disable_model_pruning": False,
249+
"debug_stripper": True,
250+
"auto_mixed_precision": precision != "FP32",
251+
"layout_optimizer": True,
252+
"dependency_optimization": True,
253+
"min_graph_nodes": -1 # do not skip small graphs
254+
})
255+
246256
saved_model_loaded = tf.saved_model.load(export_dir=path, tags=tags)
247257

248258
graph_func = saved_model_loaded.signatures[signature_key]
249259

250-
if precision == "FP16":
251-
tf.config.optimizer.set_experimental_options({
252-
"auto_mixed_precision": True
253-
})
254-
255260
# Known TF Issue: https://github.com/tensorflow/tensorflow/issues/37615#issuecomment-767804930
256261
# it looks like if the original trackable object is released by
257262
# the Python garbage collector once it goes out of scope, and

tftrt/benchmarking-python/huggingface/bert/base_run_inference.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ MIN_SEGMENT_SIZE=5
6262
VOCAB_SIZE=-1
6363
MAX_WORKSPACE_SIZE=$((2 ** (32 + 1))) # + 1 necessary compared to python
6464
MAX_SAMPLES=1
65-
OUTPUT_TENSORS_NAME="prediction_logits,seq_relationship_logits"
65+
OUTPUT_TENSORS_NAME="last_hidden_state,pooler_output"
6666

6767
case ${MODEL_NAME} in
6868
"bert_base_uncased" | "bert_large_uncased")
@@ -76,7 +76,7 @@ case ${MODEL_NAME} in
7676
"bart_base" | "bart_large")
7777
VOCAB_SIZE=50265
7878
MIN_SEGMENT_SIZE=90
79-
OUTPUT_TENSORS_NAME="encoder_last_hidden_state,logits"
79+
OUTPUT_TENSORS_NAME="encoder_last_hidden_state,last_hidden_state"
8080
;;
8181
esac
8282

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/bash
2+
3+
BASE_DIR="/models/huggingface/transformers"
4+
5+
GPT2_MODELS=(
6+
"bert-base-uncased"
7+
"bert-base-cased"
8+
"bert-large-uncased"
9+
"bert-large-cased"
10+
"facebook/bart-base"
11+
"facebook/bart-large"
12+
)
13+
14+
15+
for model_name in "${GPT2_MODELS[@]}"; do
16+
echo "Processing: ${model_name} ..."
17+
sleep 1
18+
19+
MODEL_DIR=${model_name#*/} # Remove `facebook/`
20+
MODEL_DIR=${MODEL_DIR//-/_} # Replace "-" by "_"
21+
22+
MODEL_DIR="${BASE_DIR}/${MODEL_DIR}"
23+
rm -rf ${MODEL_DIR} && mkdir -p ${MODEL_DIR}
24+
echo "Model Dir: ${MODEL_DIR}"
25+
26+
set -x
27+
python generate_saved_models.py --output_directory ${MODEL_DIR} --model_name ${model_name}
28+
saved_model_cli show --dir "${MODEL_DIR}/pb_model" --all 2>&1 | tee ${MODEL_DIR}/pb_model/analysis.txt
29+
set +x
30+
done

tftrt/benchmarking-python/huggingface/bert/generate_save_models_from_hf.py

Lines changed: 0 additions & 157 deletions
This file was deleted.

0 commit comments

Comments
 (0)