Instructions to use ai4bharat/indictrans2-en-indic-1B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ai4bharat/indictrans2-en-indic-1B 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="ai4bharat/indictrans2-en-indic-1B", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForSeq2SeqLM model = AutoModelForSeq2SeqLM.from_pretrained("ai4bharat/indictrans2-en-indic-1B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Unable to use indictrans2-en-indic-1B for a translation project
I am trying to develop a translation toolkit using free tools. During this, uncovered these issue. We ran the code provided in the model usage section and it didn't work either.
Environment: Kaggle notebook, Python 3.12, transformers (current release as of Sept 2026 β appears to be past the v5 line based on symptoms below), tokenizers==0.22.2, IndicTransToolkit (latest pip package), model: ai4bharat/indictrans2-en-indic-1B.
Summary: Six distinct incompatibilities between IndicTrans2's vendored trust_remote_code files / IndicTransToolkit, and current transformers internals. Individually patchable, but the last two (#5, #6) reveal an unresolvable version conflict: the model code needs an older transformers (pre-Cache-refactor), while the toolkit code needs a newer one β no single pinned version satisfies both without patching.
Issue 1 β IndicTransToolkit import fails on current transformers
ImportError: cannot import name 'PreTrainedTokenizerBase' from 'transformers.tokenization_utils'
IndicTransToolkit/collator.py does from transformers.tokenization_utils import PreTrainedTokenizerBase. That module used to re-export the class (real home: transformers.tokenization_utils_base) for backward compatibility; current transformers no longer does.
Issue 2 β configuration_indictrans.py imports a removed module
ModuleNotFoundError: No module named 'transformers.onnx'
from transformers.onnx import OnnxConfig, OnnxSeq2SeqConfigWithPast β transformers.onnx has been removed from current transformers (deprecated long ago in favor of optimum).
Issue 3 β Tokenizer constructor ordering breaks under current transformers
AttributeError: IndicTransTokenizer has no attribute _special_tokens_map
tokenization_indictrans.py's IndicTransTokenizer.init sets self.unk_token = ... (and other special tokens) before calling super().init(). Current PreTrainedTokenizerBase.setattr requires self._special_tokens_map to already exist before any special-token attribute assignment β it doesn't yet at that point in the custom init.
Issue 4 β tie_weights() signature mismatch
TypeError: IndicTransForConditionalGeneration.tie_weights() got an unexpected keyword argument 'recompute_mapping'
Current transformers' PreTrainedModel.init_weights() calls self.tie_weights(recompute_mapping=False). The vendored modeling_indictrans.py overrides tie_weights(self): with no parameters, written before this kwarg existed.
Issue 5 β KV-cache format incompatibility (reproduces with AI4Bharat's own official example, unmodified)
TypeError: 'EncoderDecoderCache' object is not subscriptable
Ran the exact generate() example from the ai4bharat/indictrans2-en-indic-1B model card as-is. Current transformers wraps past_key_values in an EncoderDecoderCache object (introduced 4.36+) rather than a plain tuple; the vendored model code still indexes it like a tuple/list, written before this refactor.
Issue 6 β No single transformers version satisfies both the model code and the toolkit
Attempted downgrading to transformers==4.35.2 (predates the EncoderDecoderCache introduction in 4.36, which should fix #5). This required also downgrading tokenizers to <0.19 and pulled in huggingface-hub==0.16.4 as a dependency. But then:
ImportError: cannot import name 'pad_without_fast_tokenizer_warning' from 'transformers.data.data_collator'
IndicTransToolkit/collator.py needs pad_without_fast_tokenizer_warning, which doesn't exist in transformers 4.35.2 (added later). So the model code (modeling_indictrans.py) wants an older transformers, while the toolkit code (collator.py) wants a newer one β these two pieces of AI4Bharat's own released code have contradictory minimum-version requirements, with no overlapping compatible version.
Suggested fix for maintainers: Either update the vendored modeling_indictrans.py/tokenization_indictrans.py to target current transformers' Cache API and post-4.51 tokenizer internals, or pin/document a specific known-working transformers+tokenizers combination in the model card and IndicTransToolkit's requirements.txt, since right now neither the toolkit nor the model's own trust_remote_code files state a compatible upper/lower bound clearly enough to avoid this.