Commit
·
6e11c96
1
Parent(s):
cf9b005
update
Browse files
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
generation_config.json
DELETED
|
@@ -1,7 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"_from_model_config": true,
|
| 3 |
-
"decoder_start_token_id": 0,
|
| 4 |
-
"eos_token_id": 1,
|
| 5 |
-
"pad_token_id": 0,
|
| 6 |
-
"transformers_version": "4.27.0.dev0"
|
| 7 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onnx/decoder_model_merged_quantized.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:fe9751468ddf78017d5bbb317d1162049b57bc8b11321dcf3756907835245e42
|
| 3 |
-
size 20201510
|
|
|
|
|
|
|
|
|
|
|
|
onnx/{encoder_model_quantized.onnx → encoder_model_quant.onnx}
RENAMED
|
File without changes
|
onnx/{init_decoder_quantized.onnx → init_decoder_quant.onnx}
RENAMED
|
File without changes
|
scripts/gen.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration, T5Config
|
| 2 |
+
import torch
|
| 3 |
+
from transformers.onnx import OnnxConfig, export
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
# Load the T5-efficient-tiny model and tokenizer
|
| 7 |
+
model_name = "google/t5-efficient-tiny"
|
| 8 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
| 9 |
+
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
| 10 |
+
config = T5Config.from_pretrained(model_name)
|
| 11 |
+
|
| 12 |
+
# Prepare a sample input
|
| 13 |
+
text = "Translate English to French: The house is wonderful."
|
| 14 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 15 |
+
|
| 16 |
+
# Define the model configuration for ONNX
|
| 17 |
+
class T5OnnxConfig(OnnxConfig):
|
| 18 |
+
@property
|
| 19 |
+
def inputs(self):
|
| 20 |
+
return {
|
| 21 |
+
"input_ids": {
|
| 22 |
+
"shape": [self.batch_size, self.sequence_length],
|
| 23 |
+
"dtype": torch.int64,
|
| 24 |
+
},
|
| 25 |
+
"attention_mask": {
|
| 26 |
+
"shape": [self.batch_size, self.sequence_length],
|
| 27 |
+
"dtype": torch.int64,
|
| 28 |
+
},
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
@property
|
| 32 |
+
def outputs(self):
|
| 33 |
+
return {
|
| 34 |
+
"logits": {
|
| 35 |
+
"shape": [self.batch_size, self.sequence_length, self.config.vocab_size],
|
| 36 |
+
"dtype": torch.float32,
|
| 37 |
+
},
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
onnx_config = T5OnnxConfig(config, 1, 128)
|
| 41 |
+
|
| 42 |
+
# Export the model to ONNX format
|
| 43 |
+
output_path = Path("t5-efficient-tiny.onnx")
|
| 44 |
+
export(
|
| 45 |
+
preprocessor=tokenizer,
|
| 46 |
+
model=model,
|
| 47 |
+
config=onnx_config,
|
| 48 |
+
output=output_path
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
print("Model has been successfully exported to ONNX format.")
|
quantifiy.py → scripts/quantifiy.py
RENAMED
|
File without changes
|