Commit
•
cbad939
1
Parent(s):
cd2b3b0
Update README.md
Browse files
README.md
CHANGED
@@ -2,44 +2,6 @@
|
|
2 |
license: apache-2.0
|
3 |
---
|
4 |
|
5 |
-
## Convert pytorch model to onnx format.
|
6 |
-
|
7 |
-
```
|
8 |
-
import torch
|
9 |
-
import onnx
|
10 |
-
import onnxruntime
|
11 |
-
from onnxruntime import InferenceSession
|
12 |
-
from transformers import RobertaTokenizer, RobertaModel
|
13 |
-
from transformers.convert_graph_to_onnx import convert
|
14 |
-
import numpy as np
|
15 |
-
from onnxruntime.transformers import optimizer
|
16 |
-
from pathlib import Path
|
17 |
-
from onnxruntime.quantization import quantize_dynamic, QuantType
|
18 |
-
from sentence_transformers import SentenceTransformer, util
|
19 |
-
|
20 |
-
sbert = SentenceTransformer('sentence-transformers/all-roberta-large-v1')
|
21 |
-
sbert.save('sbert-all-roberta-large-v1')
|
22 |
-
|
23 |
-
tokenizer = RobertaTokenizer.from_pretrained('sentence-transformers/all-roberta-large-v1')
|
24 |
-
model = RobertaModel.from_pretrained('sentence-transformers/all-roberta-large-v1')
|
25 |
-
model.save_pretrained('./all-roberta-large-v1/')
|
26 |
-
tokenizer.save_pretrained('./all-roberta-large-v1/')
|
27 |
-
|
28 |
-
opt_model_path = "onnx-model/sbert-roberta-large.onnx"
|
29 |
-
convert(framework='pt', model='./all-roberta-large-v1/', output= Path(opt_model_path), opset=12, use_external_format=False, pipeline_name='feature-extraction')
|
30 |
-
|
31 |
-
quantize_dynamic(
|
32 |
-
model_input='onnx-model/sbert-roberta-large.onnx',
|
33 |
-
model_output='onnx-model/sbert-roberta-large-quant.onnx',
|
34 |
-
per_channel=True,
|
35 |
-
reduce_range=True,
|
36 |
-
activation_type=QuantType.QUInt8,
|
37 |
-
weight_type=QuantType.QInt8,
|
38 |
-
optimize_model=False,
|
39 |
-
use_external_data_format=False
|
40 |
-
)
|
41 |
-
```
|
42 |
-
##Copy pooling layer and tokenizer files to the output directory
|
43 |
|
44 |
```
|
45 |
##How to download the model?
|
|
|
2 |
license: apache-2.0
|
3 |
---
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
```
|
7 |
##How to download the model?
|