Instructions to use TigreGotico/opus-mt-ca-en-onnx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TigreGotico/opus-mt-ca-en-onnx with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "translation" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # 'pip install "transformers<5.0.0' from transformers import pipeline pipe = pipeline("translation", model="TigreGotico/opus-mt-ca-en-onnx")# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("TigreGotico/opus-mt-ca-en-onnx") model = AutoModelForSeq2SeqLM.from_pretrained("TigreGotico/opus-mt-ca-en-onnx", device_map="auto") - Notebooks
- Google Colab
- Kaggle
opus-mt-ca-en-onnx
ONNX export (fp32 + dynamic int8 quantized) of Helsinki-NLP/opus-mt-ca-en, a Marian (ca -> en) translation model from the Helsinki-NLP OPUS-MT project.
License: apache-2.0 (inherited from the base model; verify at the source link above).
Export
optimum-cli export onnx --model Helsinki-NLP/opus-mt-ca-en --task text2text-generation-with-past /home/miro/tmp/claude-1000/-home-miro/849a3674-94c9-4aa5-b1f9-e596235b0a36/scratchpad/opusmt-onnx/out/ca-en
Quantized to int8 with onnxruntime.quantization.quantize_dynamic (QUInt8 weights).
File layout
./ fp32 ONNX graphs (encoder_model.onnx, decoder_model.onnx, decoder_with_past_model.onnx) + tokenizer files
./int8/ int8 dynamic-quantized ONNX graphs
fp32 size: ~789 MB | int8 size: ~352 MB
Sanity check
Compared PyTorch (MarianMTModel) vs ONNX fp32 (ORTModelForSeq2SeqLM, num_beams=4, max_new_tokens=48) on 3 sentences. Match: 3/3.
- src: Hola, com estàs avui?
- pytorch: Hey, how are you today?
- onnx fp32: Hey, how are you today? (match)
- src: Fa bon temps aquest matí.
- pytorch: It's been a long time this morning.
- onnx fp32: It's been a long time this morning. (match)
- src: M'agradaria demanar un cafè, si us plau.
- pytorch: I'd like a cup of coffee, please.
- onnx fp32: I'd like a cup of coffee, please. (match)
int8 sample output (not gated, for reference only):
- Hey, how are you today?
Usage
from optimum.onnxruntime import ORTModelForSeq2SeqLM
from transformers import AutoTokenizer
repo = "TigreGotico/opus-mt-ca-en-onnx"
tok = AutoTokenizer.from_pretrained(repo)
model = ORTModelForSeq2SeqLM.from_pretrained(repo) # fp32; pass subfolder="int8" for the quantized graphs
inputs = tok("Hello, how are you?", return_tensors="pt")
out = model.generate(**inputs, num_beams=4, max_new_tokens=48)
print(tok.decode(out[0], skip_special_tokens=True))
Exported for the OVOS / TigreGotico offline translation stack.
- Downloads last month
- 14
Model tree for TigreGotico/opus-mt-ca-en-onnx
Base model
Helsinki-NLP/opus-mt-ca-en