Skip to content

Commit d501248

Browse files
authored
Modify the examples optimization level (#230)
* Modify the examples optimization level * Update readme
1 parent 14289c0 commit d501248

File tree

7 files changed

+15
-12
lines changed

7 files changed

+15
-12
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ Then let's take a look at applying _graph optimizations_ techniques such as oper
154154
```python
155155
from optimum.onnxruntime.configuration import OptimizationConfig
156156

157-
# optimization_config=99 enables all available graph optimisations
158-
optimization_config = OptimizationConfig(optimization_level=99)
157+
# Here the optimization level is selected to be 1, enabling basic optimizations such as redundant
158+
# node eliminations and constant folding. Higher optimization level will result in a hardware
159+
# dependent optimized graph.
160+
optimization_config = OptimizationConfig(optimization_level=1)
159161
```
160162

161163
Next, we load an _optimizer_ to apply these optimisations to our model:

docs/source/quickstart.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ As a final example, let's take a look at applying _graph optimizations_ techniqu
9595
```python
9696
>>> from optimum.onnxruntime.configuration import OptimizationConfig
9797

98-
>>> # optimization_config=99 enables all available graph optimisations
99-
>>> optimization_config = OptimizationConfig(optimization_level=99)
98+
>>> # Here the optimization level is selected to be 1, enabling basic optimizations such as redundant node eliminations and constant folding. Higher optimization level will result in a hardware dependent optimized graph.
99+
>>> optimization_config = OptimizationConfig(optimization_level=1)
100100
```
101101

102102
Next, we load an _optimizer_ to apply these optimisations to our model:

examples/onnxruntime/optimization/multiple-choice/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ limitations under the License.
1818

1919
The script [`run_swag.py`](https://github.com/huggingface/optimum/blob/main/examples/onnxruntime/quantization/multiple-choice/run_swag.py) allows us to apply graph optimizations using [ONNX Runtime](https://github.com/microsoft/onnxruntime) for multiple choice tasks.
2020

21-
The following example applies graph optimizations on a BERT fine-tuned on the SWAG dataset.
21+
The following example applies graph optimizations on a BERT fine-tuned on the SWAG dataset. Here the optimization level is selected to be 1, enabling basic optimizations such as redundant node eliminations and constant folding. Higher optimization level will result in hardware dependent optimized graph.
2222

2323
```bash
2424
python run_swag.py \
2525
--model_name_or_path ehdwns1516/bert-base-uncased_SWAG \
26+
--optimization_level 1 \
2627
--do_eval \
2728
--output_dir /tmp/optimized_bert_swag
2829
```

examples/onnxruntime/optimization/question-answering/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ allows us to apply graph optimizations using [ONNX Runtime](https://github.com/m
2222
Note that if your dataset contains samples with no possible answers (like SQuAD version 2), you need to pass along
2323
the flag `--version_2_with_negative`.
2424

25-
The following example applies graph optimizations on a DistilBERT fine-tuned on the SQuAD1.0 dataset.
25+
The following example applies graph optimizations on a DistilBERT fine-tuned on the SQuAD1.0 dataset. Here the optimization level is selected to be 1, enabling basic optimizations such as redundant node eliminations and constant folding. Higher optimization level will result in hardware dependent optimized graph.
2626

2727
```bash
2828
python run_qa.py \
2929
--model_name_or_path distilbert-base-uncased-distilled-squad \
3030
--dataset_name squad \
31-
--optimization_level 99 \
31+
--optimization_level 1 \
3232
--do_eval \
3333
--output_dir /tmp/optimized_distilbert_squad
3434
```

examples/onnxruntime/optimization/text-classification/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ The script [`run_glue.py`](https://github.com/huggingface/optimum/blob/main/exam
2222
allows us to apply graph optimizations and fusion using [ONNX Runtime](https://github.com/microsoft/onnxruntime) for sequence classification tasks such as
2323
the ones from the [GLUE benchmark](https://gluebenchmark.com/).
2424

25-
The following example applies graph optimization on a DistilBERT fine-tuned on the sst-2 task.
25+
The following example applies graph optimization on a DistilBERT fine-tuned on the sst-2 task. Here the optimization level is selected to be 1, enabling basic optimizations such as redundant node eliminations and constant folding. Higher optimization level will result in hardware dependent optimized graph.
2626

2727
```bash
2828
python run_glue.py \
2929
--model_name_or_path distilbert-base-uncased-finetuned-sst-2-english \
3030
--task_name sst2 \
31-
--optimization_level 99 \
31+
--optimization_level 1 \
3232
--do_eval \
3333
--output_dir /tmp/optimized_distilbert_sst2
3434
```

examples/onnxruntime/optimization/token-classification/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ limitations under the License.
1919
The script [`run_ner.py`](https://github.com/huggingface/optimum/blob/main/examples/onnxruntime/optimization/token-classification/run_ner.py)
2020
allows us to apply graph optimizations using [ONNX Runtime](https://github.com/microsoft/onnxruntime) for token classification tasks.
2121

22-
The following example applies graph optimizations on a DistilBERT fine-tuned on the CoNLL-2003 task
22+
The following example applies graph optimizations on a DistilBERT fine-tuned on the CoNLL-2003 task. Here the optimization level is selected to be 1, enabling basic optimizations such as redundant node eliminations and constant folding. Higher optimization level will result in hardware dependent optimized graph.
2323

2424
```bash
2525
python run_ner.py \
2626
--model_name_or_path elastic/distilbert-base-uncased-finetuned-conll03-english \
2727
--dataset_name conll2003 \
28-
--optimization_level 99 \
28+
--optimization_level 1 \
2929
--do_eval \
3030
--output_dir /tmp/optimized_distilbert_conll2003
3131
```

tests/onnxruntime/test_onnxruntime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_optimize(self):
5353
"roberta-base",
5454
"google/electra-small-discriminator",
5555
}
56-
optimization_config = OptimizationConfig(optimization_level=99, optimize_with_onnxruntime_only=False)
56+
optimization_config = OptimizationConfig(optimization_level=2, optimize_with_onnxruntime_only=False)
5757
for model_name in model_names:
5858
with self.subTest(model_name=model_name):
5959
with tempfile.TemporaryDirectory() as tmp_dir:

0 commit comments

Comments
 (0)