-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable ONNXRT layoutlmft & layoutlmv3 examples (#837)
Signed-off-by: yuwenzho <yuwen.zhou@intel.com>
- Loading branch information
Showing
32 changed files
with
2,943 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2600,3 +2600,10 @@ cdrdv | |
NeuralCompressor | ||
zp | ||
TensorflowTopK | ||
FUNSD | ||
LayoutLMv | ||
layoutlmv | ||
funsd | ||
layoutlmft | ||
nielsr | ||
HYPJUDY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ngface_model/token_classification/layoutlmft/quantization/ptq_dynamic/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
Step-by-Step | ||
============ | ||
|
||
This example load LayoutLMv3 model and confirm its accuracy and speed based on [FUNSD](https://huggingface.co/datasets/nielsr/funsd) dataset. | ||
|
||
# Prerequisite | ||
|
||
## 1. Environment | ||
```shell | ||
pip install neural-compressor | ||
pip install -r requirements.txt | ||
bash install_layoutlmft.sh | ||
``` | ||
> Note: Validated ONNX Runtime [Version](/docs/source/installation_guide.md#validated-software-environment). | ||
## 2. Prepare Model | ||
Finetune on FUNSD | ||
|
||
```bash | ||
python main.py \ | ||
--model_name_or_path microsoft/layoutlm-base-uncased \ | ||
--output_dir ./layoutlm-base-uncased-finetuned-funsd \ | ||
--do_train \ | ||
--max_steps 1000 \ | ||
--warmup_ratio 0.1 | ||
``` | ||
|
||
Export a model to ONNX with `optimum.exporters.onnx`. | ||
|
||
```bash | ||
optimum-cli export onnx --model ./layoutlm-base-uncased-finetuned-funsd ./layoutlm-base-uncased-finetuned-funsd-onnx/ --task=token-classification | ||
``` | ||
|
||
# Run | ||
|
||
## 1. Quantization | ||
|
||
Dynamic quantization: | ||
|
||
```bash | ||
bash run_tuning.sh --input_model=./layoutlm-base-uncased-finetuned-funsd-onnx/model.onnx \ # model path as *.onnx | ||
--output_model=/path/to/model_tune | ||
``` | ||
|
||
|
||
## 2. Benchmark | ||
|
||
```bash | ||
bash run_benchmark.sh --input_model=/path/to/model \ # model path as *.onnx | ||
--batch_size=batch_size \ | ||
--mode=performance # or accuracy | ||
``` |
3 changes: 3 additions & 0 deletions
3
...face_model/token_classification/layoutlmft/quantization/ptq_dynamic/install_layoutlmft.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
git clone https://github.com/microsoft/unilm.git | ||
cd unilm/layoutlmft | ||
pip install -e . |
Oops, something went wrong.