mt-hitz-ca-eu-onnx

ONNX export of HiTZ/mt-hitz-ca-eu, a MarianMT machine translation model for ca -> eu produced by HiTZ, the Basque Center for Language Technology at the University of the Basque Country (UPV/EHU).

All credit for training and releasing the original model goes to the HiTZ team. This repo only contains an ONNX conversion (fp32 and int8) for fast CPU inference with optimum[onnxruntime], done by TigreGotico.

License

apache-2.0, as declared on the source model card.

Export command

optimum-cli export onnx --model HiTZ/mt-hitz-ca-eu --task text2text-generation-with-past --no-post-process ca-eu

int8 dynamic quantization was applied afterwards with onnxruntime.quantization.quantize_dynamic (QUInt8) into the int8/ subfolder.

File layout

ca-eu/
  encoder_model.onnx              # fp32
  decoder_model.onnx              # fp32
  decoder_with_past_model.onnx    # fp32
  config.json, generation_config.json
  source.spm, target.spm, vocab.json, tokenizer_config.json, special_tokens_map.json
  int8/
    encoder_model.onnx
    decoder_model.onnx
    decoder_with_past_model.onnx

Parity vs. the original PyTorch model

Measured on 8 held-out ca->eu sentences, beam search (num_beams=4, max_new_tokens=64), exact-match against the original PyTorch MarianMTModel output:

  • fp32: 100.0% exact match
  • int8: 87.5% exact match (semantically consistent but not gated on this number; dynamic quantization trades some fluency, especially on longer sentences, for ~2.5x smaller size and faster CPU inference)

Example (ca -> eu):

  • PyTorch: Kaixo, zer moduz zaude?
  • ONNX fp32: Kaixo, zer moduz zaude?
  • ONNX int8: Kaixo, zer moduz zaude?

Usage

from transformers import AutoTokenizer
from optimum.onnxruntime import ORTModelForSeq2SeqLM

tok = AutoTokenizer.from_pretrained("TigreGotico/mt-hitz-ca-eu-onnx")

# fp32 (default, root of the repo)
model = ORTModelForSeq2SeqLM.from_pretrained("TigreGotico/mt-hitz-ca-eu-onnx")

# int8 (smaller / faster, subfolder)
# download the repo and load from the local "int8" folder, e.g.:
# from huggingface_hub import snapshot_download
# path = snapshot_download("TigreGotico/mt-hitz-ca-eu-onnx")
# model = ORTModelForSeq2SeqLM.from_pretrained(path + "/int8")

batch = tok(["your sentence here"], return_tensors="pt")
generated = model.generate(**batch, num_beams=4, max_new_tokens=64)
print(tok.batch_decode(generated, skip_special_tokens=True))

Attribution

Downloads last month
18
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for TigreGotico/mt-hitz-ca-eu-onnx

Quantized
(1)
this model