indictrans2-en-indic-1B-onnx

ONNX export of ai4bharat/indictrans2-en-indic-1B, the full-size IndicTrans2 translation model from AI4Bharat / IIT Madras (the distilled 200M variant is published separately at indictrans2-en-indic-dist-200M-onnx).

Direction: English into 22 Indic languages. src_lang is always eng_Latn.

Files

File Purpose
encoder_model.onnx Encoder
decoder_model.onnx + decoder_model.onnx_data Decoder, first step, no cache (external data — this graph exceeds the 2GB protobuf limit at 1B scale)
decoder_with_past_model.onnx + decoder_with_past_model.onnx_data Decoder, later steps, with KV cache (external data)
int8/ The same three graphs, int8 dynamic quantization (all three stay under the 2GB limit at this precision, no external data)
model.SRC, model.TGT, dict.SRC.json, dict.TGT.json SentencePiece models and vocabularies (source and target sides are separate)
configuration_indictrans.py, modeling_indictrans.py, tokenization_indictrans.py Custom architecture and tokenizer code, loaded with trust_remote_code=True

Sizes: fp32 6.7 GB, int8 1.7 GB.

If you load these graphs with your own code (not ORTModelForSeq2SeqLM.from_pretrained against this repo directly), fetch decoder_model.onnx_data and decoder_with_past_model.onnx_data alongside their .onnx files — the encoder has no external data at this size, but both decoder graphs do.

Preprocessing is mandatory

IndicTrans2 does not take raw text. You must run IndicProcessor from IndicTransToolkit first:

pip install IndicTransToolkit optimum[onnxruntime] transformers sentencepiece

IndicProcessor.preprocess_batch normalises the script, applies Indic-specific punctuation and numeral handling, protects entities, and prefixes the two language tags. Skipping it gives silently wrong output — the model still produces fluent-looking text, but for several target scripts (anything transliterated through Devanagari, e.g. Tamil, Bengali) it comes back correctly-worded but in the wrong script, and nothing raises.

postprocess_batch reverses the entity protection and the script transliteration. It is also required.

Language tags

The tags are plain text prefixed to the source sentence, in the order <src_lang> <tgt_lang> <sentence>. IndicProcessor adds them for you; you only pass src_lang= and tgt_lang=.

For example, ip.preprocess_batch(["This is a test."], src_lang="eng_Latn", tgt_lang="hin_Deva") produces "eng_Latn hin_Deva This is a test .".

The tags are <iso639-3>_<ISO 15924 script>. Languages with two scripts have two tags. Supported tags:

Tag Language
asm_Beng Assamese
ben_Beng Bengali
brx_Deva Bodo
doi_Deva Dogri
gom_Deva Konkani
guj_Gujr Gujarati
hin_Deva Hindi
kan_Knda Kannada
kas_Arab Kashmiri (Arabic)
kas_Deva Kashmiri (Devanagari)
mai_Deva Maithili
mal_Mlym Malayalam
mar_Deva Marathi
mni_Beng Manipuri (Bengali)
mni_Mtei Manipuri (Meitei)
npi_Deva Nepali
ory_Orya Odia
pan_Guru Punjabi
san_Deva Sanskrit
sat_Olck Santali
snd_Arab Sindhi (Arabic)
snd_Deva Sindhi (Devanagari)
tam_Taml Tamil
tel_Telu Telugu
urd_Arab Urdu
eng_Latn English

Usage

import torch
from transformers import AutoTokenizer
from optimum.onnxruntime import ORTModelForSeq2SeqLM
from IndicTransToolkit.processor import IndicProcessor

REPO = "TigreGotico/indictrans2-en-indic-1B-onnx"

tokenizer = AutoTokenizer.from_pretrained(REPO, trust_remote_code=True)
model = ORTModelForSeq2SeqLM.from_pretrained(REPO, trust_remote_code=True, use_cache=True)
ip = IndicProcessor(inference=True)          # REQUIRED - see "Preprocessing"

sentences = ["The weather is nice today and the children are playing outside.", "I would like a cup of tea with a little sugar."]
src_lang, tgt_lang = "eng_Latn", "hin_Deva"

batch = ip.preprocess_batch(sentences, src_lang=src_lang, tgt_lang=tgt_lang)
enc = tokenizer(batch, return_tensors="pt", padding=True, truncation=True, max_length=256)

with torch.inference_mode():
    out = model.generate(**enc, num_beams=4, max_new_tokens=128, length_penalty=1.0, use_cache=True)

decoded = tokenizer.batch_decode(out, skip_special_tokens=True)
print(ip.postprocess_batch(decoded, lang=tgt_lang))

To use the quantized graphs, pass subfolder="int8".

Sample output

Direction Input Output
eng_Latnhin_Deva An appearance is a bunch of attributes related to the service person, like their shoes, clothes, tie, jewellery, hairstyle, make-up, watch, cosmetics, perfume, etc. उपस्थिति सेवा करने वाले व्यक्ति से संबंधित विशेषताओं का एक समूह है, जैसे कि उनके जूते, कपड़े, टाई, आभूषण, केश विन्यास, मेकअप, घड़ी, सौंदर्य प्रसाधन, इत्र आदि।
eng_Latnben_Beng An appearance is a bunch of attributes related to the service person, like their shoes, clothes, tie, jewellery, hairstyle, make-up, watch, cosmetics, perfume, etc. চেহারা হল পরিচর্যাকারী ব্যক্তির সঙ্গে সম্পর্কিত একগুচ্ছ বৈশিষ্ট্য, যেমন তাদের জুতো, জামাকাপড়, টাই, গহনা, চুলের স্টাইল, মেক-আপ, ঘড়ি, প্রসাধনী, সুগন্ধি ইত্যাদি।
eng_Latntam_Taml An appearance is a bunch of attributes related to the service person, like their shoes, clothes, tie, jewellery, hairstyle, make-up, watch, cosmetics, perfume, etc. தோற்றம் என்பது சேவை செய்பவரின் காலணிகள், உடைகள், டை, நகைகள், சிகை அலங்காரம், ஒப்பனை, கடிகாரம், அழகுசாதனப் பொருட்கள், வாசனை திரவியங்கள் போன்ற பண்புகளுடன் தொடர்புடைய பண்புகளின் தொகுப்பாகும்.

Parity against the PyTorch original

100 sentences from ai4bharat/IN22-Gen (English source, 3 Indic targets: Hindi, Bengali, Tamil), both greedy (num_beams=1) and beam search (num_beams=4), max_new_tokens=128, length_penalty=1.0, against AutoModelForSeq2SeqLM.from_pretrained(..., trust_remote_code=True, torch_dtype=torch.float32). Preprocessing/postprocessing via the vendored IndicProcessor on both sides.

Precision Mode Exact match chrF (ONNX vs PyTorch)
fp32 greedy 100% 100.00
fp32 beam4 100% 100.00
int8 greedy — (not string-compared) see quality chrF below

Quality against human reference (IN22-Gen)

chrF of the model's own output against the dataset's human reference translation (this measures translation quality, not fp32/ONNX parity, which is the table above):

Target fp32 greedy fp32 beam4 int8 greedy
Hindi (hin_Deva) 54.01 54.29 54.11
Bengali (ben_Beng) 48.84 48.98 48.85
Tamil (tam_Taml) 52.57 52.63 52.57

Differential / language-identification check

The same English sentence translated into Hindi, Bengali and Tamil produces three distinct outputs, each independently confirmed to be in the requested language by linguonnx's GlotLID detector (linguonnx.load_detector()): hi → detected hi, bn → detected bn, ta → detected ta. No <unk>, , , or repeated-phrase loops found across any of the greedy/beam4/int8 outputs checked for this release.

Limits

Maximum sequence length is 256 tokens on both sides. The sinusoidal position table is frozen into the graph at export time, so longer inputs are not supported. Truncate with max_length=256.

Export route

Exported with optimum.exporters.onnx.onnx_export_from_model and a custom OnnxConfig registered for the IndicTrans model type. The config subclasses M2M100OnnxConfig and remaps the field names IndicTrans2 uses (encoder_embed_dim instead of d_model, encoder_vocab_size for the dummy-input vocab bound since IndicTrans2 has separate source/target vocabularies). Recipe and gotchas (registration casing, the vocab split, the .onnx.data.onnx_data external-data rename, the decoder-merge protobuf limit at this scale) are documented in scripts/export/README.md in the linguonnx repo.

optimum-cli export onnx alone does not work: it has no config for the IndicTrans architecture.

Attribution

The model is the work of AI4Bharat, IIT Madras.

@article{gala2023indictrans2,
  title   = {IndicTrans2: Towards High-Quality and Accessible Machine Translation Models for all 22 Scheduled Indian Languages},
  author  = {Jay Gala and Pranjal A. Chitale and Raghavan AK and Varun Gumma and Sumanth Doddapaneni and Aswanth Kumar and Janki Nawale and Anupama Sujatha and Ratish Puduppully and Vivek Raghavan and Pratyush Kumar and Mitesh M. Khapra and Raj Dabre and Anoop Kunchukuttan},
  journal = {Transactions on Machine Learning Research},
  year    = {2023}
}

Licence: MIT, same as the original.

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

Model tree for TigreGotico/indictrans2-en-indic-1B-onnx

Quantized
(5)
this model