# ai4bharat/indictrans2 architecture

> Architecture diagram of the GitHub repository ai4bharat/indictrans2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ai4bharat/indictrans2
- Repository: https://github.com/ai4bharat/indictrans2

## Overview

IndicTrans2 provides multilingual Indic translation models, inference interfaces, and data-preparation and fine-tuning utilities. The main user workflow is to submit text with source and target languages to an inference interface and receive translated text; the sampled engine includes language tagging and normalization, while the Triton backend loads direction-specific checkpoints. The repository also includes a Hugging Face model implementation and conversion/fine-tuning tools, plus dataset preparation and baseline evaluation. Some connections are omitted because the relevant source was not excerpted.

Main entry points: [`inference/engine.py`](https://github.com/ai4bharat/indictrans2/blob/main/inference/engine.py) (Translation engine), [`huggingface_interface/convert_indictrans_checkpoint_to_pytorch.py`](https://github.com/ai4bharat/indictrans2/blob/main/huggingface_interface/convert_indictrans_checkpoint_to_pytorch.py) (Checkpoint conversion), [`inference/custom_interactive.py`](https://github.com/ai4bharat/indictrans2/blob/main/inference/custom_interactive.py) (Fairseq interface), [`inference/triton_server/triton_repo/nmt/1/model.py`](https://github.com/ai4bharat/indictrans2/blob/main/inference/triton_server/triton_repo/nmt/1/model.py) (Triton backend)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_serving["Translation serving"]
  node_engine["Translation engine<br/>[engine.py]"]
  node_interactive["Fairseq interface"]
  node_triton["Triton backend<br/>[model.py]"]
  node_triton_client["Triton client<br/>[client.py]"]
  node_lang_codes["Language codes"]
  node_punctuation["Punctuation normalization"]
  node_regex_normalization["Text protection"]
  node_indic_numbers["Indic numeral map<br/>[indic_num_map.py]"]
  node_infer_arch["Fairseq architectures"]
end

subgraph group_model["Model interfaces"]
  node_hf_config["Hugging Face config"]
  node_hf_model["Hugging Face model"]
  node_checkpoint_conversion["Checkpoint conversion"]
  node_lora["LoRA fine-tuning<br/>[train_lora.py]"]
  node_hf_example["Hugging Face example<br/>[example.py]"]
  node_train_arch["Training architectures"]
end

subgraph group_data["Data preparation"]
  node_data_preprocess["Translation preprocessing"]
  node_data_postprocess["Translation postprocessing"]
  node_tag_data["Language tag data"]
  node_data_cleanup["Dataset cleanup"]
end

subgraph group_research["Evaluation"]
  node_baseline_azure["Azure baseline<br/>[azure_translate.py]"]
  node_baseline_google["Google baseline"]
  node_baseline_m2m["M2M100 baseline"]
  node_baseline_mbart["mBART baseline<br/>[mbart_inference.py]"]
  node_baseline_nllb["NLLB baseline"]
end

node_user(("Translation user"))

node_user -->|"requests translation"| node_engine
node_engine -->|"uses interface"| node_interactive
node_engine -->|"uses codes"| node_lang_codes
node_engine -->|"normalizes punctuation"| node_punctuation
node_engine -->|"protects text"| node_regex_normalization
node_regex_normalization -->|"maps numerals"| node_indic_numbers
node_interactive -->|"loads architectures"| node_infer_arch
node_triton -->|"loads translation model"| node_engine
node_user -.->|"submits inference"| node_triton_client
node_triton_client -.->|"sends requests"| node_triton
node_hf_model -->|"uses configuration"| node_hf_config
node_checkpoint_conversion -->|"creates configuration"| node_hf_config
node_checkpoint_conversion -->|"instantiates model"| node_hf_model
node_user -.->|"runs translation"| node_hf_example
node_user -.->|"fine-tunes model"| node_lora
node_user -.->|"prepares training data"| node_data_preprocess
node_user -.->|"processes translations"| node_data_postprocess
node_user -.->|"adds language tags"| node_tag_data
node_user -.->|"cleans datasets"| node_data_cleanup
node_user -.->|"evaluates baseline"| node_baseline_azure
node_user -.->|"evaluates baseline"| node_baseline_google
node_user -.->|"evaluates baseline"| node_baseline_m2m
node_user -.->|"evaluates baseline"| node_baseline_mbart
node_user -.->|"evaluates baseline"| node_baseline_nllb

click node_engine "https://github.com/ai4bharat/indictrans2/blob/main/inference/engine.py"
click node_interactive "https://github.com/ai4bharat/indictrans2/blob/main/inference/custom_interactive.py"
click node_triton "https://github.com/ai4bharat/indictrans2/blob/main/inference/triton_server/triton_repo/nmt/1/model.py"
click node_triton_client "https://github.com/ai4bharat/indictrans2/blob/main/inference/triton_server/client.py"
click node_lang_codes "https://github.com/ai4bharat/indictrans2/blob/main/inference/flores_codes_map_indic.py"
click node_punctuation "https://github.com/ai4bharat/indictrans2/blob/main/inference/normalize_punctuation.py"
click node_regex_normalization "https://github.com/ai4bharat/indictrans2/blob/main/inference/normalize_regex_inference.py"
click node_indic_numbers "https://github.com/ai4bharat/indictrans2/blob/main/inference/indic_num_map.py"
click node_infer_arch "https://github.com/ai4bharat/indictrans2/blob/main/inference/model_configs/custom_transformer.py"
click node_hf_config "https://github.com/ai4bharat/indictrans2/blob/main/huggingface_interface/configuration_indictrans.py"
click node_hf_model "https://github.com/ai4bharat/indictrans2/blob/main/huggingface_interface/modeling_indictrans.py"
click node_checkpoint_conversion "https://github.com/ai4bharat/indictrans2/blob/main/huggingface_interface/convert_indictrans_checkpoint_to_pytorch.py"
click node_lora "https://github.com/ai4bharat/indictrans2/blob/main/huggingface_interface/train_lora.py"
click node_hf_example "https://github.com/ai4bharat/indictrans2/blob/main/huggingface_interface/example.py"
click node_train_arch "https://github.com/ai4bharat/indictrans2/blob/main/model_configs/custom_transformer.py"
click node_data_preprocess "https://github.com/ai4bharat/indictrans2/blob/main/scripts/preprocess_translate.py"
click node_data_postprocess "https://github.com/ai4bharat/indictrans2/blob/main/scripts/postprocess_translate.py"
click node_tag_data "https://github.com/ai4bharat/indictrans2/blob/main/scripts/add_tags_translate.py"
click node_data_cleanup "https://github.com/ai4bharat/indictrans2/blob/main/scripts/remove_train_devtest_overlaps.py"
click node_baseline_azure "https://github.com/ai4bharat/indictrans2/blob/main/baseline_eval/azure_translate.py"
click node_baseline_google "https://github.com/ai4bharat/indictrans2/blob/main/baseline_eval/google_translate.py"
click node_baseline_m2m "https://github.com/ai4bharat/indictrans2/blob/main/baseline_eval/m2m100_inference.py"
click node_baseline_mbart "https://github.com/ai4bharat/indictrans2/blob/main/baseline_eval/mbart_inference.py"
click node_baseline_nllb "https://github.com/ai4bharat/indictrans2/blob/main/baseline_eval/nllb_moe_cpu_inference.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_engine,node_interactive,node_triton,node_triton_client,node_lang_codes,node_punctuation,node_regex_normalization,node_indic_numbers,node_infer_arch,node_user toneBlue
class node_hf_config,node_hf_model,node_checkpoint_conversion,node_lora,node_hf_example,node_train_arch toneAmber
class node_data_preprocess,node_data_postprocess,node_tag_data,node_data_cleanup toneMint
class node_baseline_azure,node_baseline_google,node_baseline_m2m,node_baseline_mbart,node_baseline_nllb toneRose
```

## Components

### Translation serving

- [Translation engine](https://github.com/ai4bharat/indictrans2/blob/main/inference/engine.py): `inference/engine.py`
- [Fairseq interface](https://github.com/ai4bharat/indictrans2/blob/main/inference/custom_interactive.py): `inference/custom_interactive.py`
- [Triton backend](https://github.com/ai4bharat/indictrans2/blob/main/inference/triton_server/triton_repo/nmt/1/model.py): `inference/triton_server/triton_repo/nmt/1/model.py`
- [Triton client](https://github.com/ai4bharat/indictrans2/blob/main/inference/triton_server/client.py): `inference/triton_server/client.py`
- [Language codes](https://github.com/ai4bharat/indictrans2/blob/main/inference/flores_codes_map_indic.py): `inference/flores_codes_map_indic.py`
- [Punctuation normalization](https://github.com/ai4bharat/indictrans2/blob/main/inference/normalize_punctuation.py): `inference/normalize_punctuation.py`
- [Text protection](https://github.com/ai4bharat/indictrans2/blob/main/inference/normalize_regex_inference.py): `inference/normalize_regex_inference.py`
- [Indic numeral map](https://github.com/ai4bharat/indictrans2/blob/main/inference/indic_num_map.py): `inference/indic_num_map.py`
- [Fairseq architectures](https://github.com/ai4bharat/indictrans2/blob/main/inference/model_configs/custom_transformer.py): `inference/model_configs/custom_transformer.py`

### Model interfaces

- [Hugging Face config](https://github.com/ai4bharat/indictrans2/blob/main/huggingface_interface/configuration_indictrans.py): `huggingface_interface/configuration_indictrans.py`
- [Hugging Face model](https://github.com/ai4bharat/indictrans2/blob/main/huggingface_interface/modeling_indictrans.py): `huggingface_interface/modeling_indictrans.py`
- [Checkpoint conversion](https://github.com/ai4bharat/indictrans2/blob/main/huggingface_interface/convert_indictrans_checkpoint_to_pytorch.py): `huggingface_interface/convert_indictrans_checkpoint_to_pytorch.py`
- [LoRA fine-tuning](https://github.com/ai4bharat/indictrans2/blob/main/huggingface_interface/train_lora.py): `huggingface_interface/train_lora.py`
- [Hugging Face example](https://github.com/ai4bharat/indictrans2/blob/main/huggingface_interface/example.py): `huggingface_interface/example.py`
- [Training architectures](https://github.com/ai4bharat/indictrans2/blob/main/model_configs/custom_transformer.py): `model_configs/custom_transformer.py`

### Data preparation

- [Translation preprocessing](https://github.com/ai4bharat/indictrans2/blob/main/scripts/preprocess_translate.py): `scripts/preprocess_translate.py`
- [Translation postprocessing](https://github.com/ai4bharat/indictrans2/blob/main/scripts/postprocess_translate.py): `scripts/postprocess_translate.py`
- [Language tag data](https://github.com/ai4bharat/indictrans2/blob/main/scripts/add_tags_translate.py): `scripts/add_tags_translate.py`
- [Dataset cleanup](https://github.com/ai4bharat/indictrans2/blob/main/scripts/remove_train_devtest_overlaps.py): `scripts/remove_train_devtest_overlaps.py`

### Evaluation

- [Azure baseline](https://github.com/ai4bharat/indictrans2/blob/main/baseline_eval/azure_translate.py): `baseline_eval/azure_translate.py`
- [Google baseline](https://github.com/ai4bharat/indictrans2/blob/main/baseline_eval/google_translate.py): `baseline_eval/google_translate.py`
- [M2M100 baseline](https://github.com/ai4bharat/indictrans2/blob/main/baseline_eval/m2m100_inference.py): `baseline_eval/m2m100_inference.py`
- [mBART baseline](https://github.com/ai4bharat/indictrans2/blob/main/baseline_eval/mbart_inference.py): `baseline_eval/mbart_inference.py`
- [NLLB baseline](https://github.com/ai4bharat/indictrans2/blob/main/baseline_eval/nllb_moe_cpu_inference.py): `baseline_eval/nllb_moe_cpu_inference.py`

### Other components

- **Translation user**

## Connections

- Translation user → Translation engine: requests translation
- Translation engine → Fairseq interface: uses interface (evidence: `inference/engine.py`)
- Translation engine → Language codes: uses codes (evidence: `inference/engine.py`)
- Translation engine → Punctuation normalization: normalizes punctuation (evidence: `inference/engine.py`)
- Translation engine → Text protection: protects text (evidence: `inference/engine.py`)
- Text protection → Indic numeral map: maps numerals (evidence: `inference/normalize_regex_inference.py`)
- Fairseq interface → Fairseq architectures: loads architectures (evidence: `inference/custom_interactive.py`)
- Triton backend → Translation engine: loads translation model (evidence: `inference/triton_server/triton_repo/nmt/1/model.py`)
- Translation user → Triton client: submits inference
- Triton client → Triton backend: sends requests
- Hugging Face model → Hugging Face config: uses configuration (evidence: `huggingface_interface/modeling_indictrans.py`)
- Checkpoint conversion → Hugging Face config: creates configuration (evidence: `huggingface_interface/convert_indictrans_checkpoint_to_pytorch.py`)
- Checkpoint conversion → Hugging Face model: instantiates model (evidence: `huggingface_interface/convert_indictrans_checkpoint_to_pytorch.py`)
- Translation user → Hugging Face example: runs translation
- Translation user → LoRA fine-tuning: fine-tunes model
- Translation user → Translation preprocessing: prepares training data
- Translation user → Translation postprocessing: processes translations
- Translation user → Language tag data: adds language tags
- Translation user → Dataset cleanup: cleans datasets
- Translation user → Azure baseline: evaluates baseline
- Translation user → Google baseline: evaluates baseline
- Translation user → M2M100 baseline: evaluates baseline
- Translation user → mBART baseline: evaluates baseline
- Translation user → NLLB baseline: evaluates baseline
