Views
No views yet
mgpt2 fine-tuned on 30,000 multilingual instruction–response pairs across 5 language variants:
English, Hindi (Devanagari), Hindi (Latin transliteration), Kannada (Kannada script), and Kannada
(Latin transliteration). Training data from ai4bharat/indic-align (Anudesh, Dolly-T, OpenAssistant-T).mgpt2 base — same 124M architecture, same custom multilingual tokenizer.
Uses masked cross-entropy (loss computed over response tokens only).1import sys, torch
2import torch.nn.functional as F
3from huggingface_hub import snapshot_download
4
5local = snapshot_download("ace-1/mgpt2-sft")
6sys.path.insert(0, local)
7from model import GPT
8from tokenizer.regex_tokenizer import RegexTokenizer
9
10ckpt = torch.load(f"{local}/pytorch_model.pt", weights_only=False, map_location="cpu")
11model = GPT(ckpt["config"])
12model.load_state_dict(ckpt["model"])
13model.eval()
14
15enc = RegexTokenizer()
16enc.load(f"{local}/tokenizer/artifacts/mgpt2.model")
17
18# Prompt: plain text, no special template needed
19prompts = [
20 "What is the capital of Karnataka?", # English
21 "कर्नाटक की राजधानी क्या है?", # Hindi (Devanagari)
22 "ಕರ್ನಾಟಕದ ರಾಜಧಾನಿ ಯಾವುದು?", # Kannada script
23]
24
25for prompt in prompts:
26 ids = enc.encode(prompt)
27 x = torch.tensor(ids, dtype=torch.long).unsqueeze(0)
28 with torch.no_grad():
29 for _ in range(120):
30 logits, _ = model(x[:, -1024:])
31 probs = F.softmax(logits[:, -1, :] / 0.7, dim=-1)
32 next_id = torch.multinomial(probs, num_samples=1)
33 if next_id.item() == 50256: break
34 x = torch.cat([x, next_id], dim=1)
35 print(f"Prompt : {prompt}")
36 print(f"Response: {enc.decode(x[0, len(ids):].tolist())}")
37 print()| Property | Value |
|---|---|
| Architecture | GPT-2 (12 layers / 12 heads / 768d) |
| Parameters | ~124M |
| Vocabulary | 50,257 (mgpt2 BPE) + padded to 50,304 |
| Context length | 1,024 tokens |
| Training stage | SFT (instruction-tuned) |
| Git commit | d07224070033 |
| Parameter | Value |
|---|---|
seed | 1337 |
batch_size | 64 |
micro_batch_size | 8 |
epochs | 3 |
warmup_steps | 50 |
max_lr | 0.0003 |
min_lr_ratio | 0.1 |
weight_decay | 0.1 |
eval_interval | 50 |
| Metric | Value | Notes |
|---|---|---|
| Val loss (masked CE) | 1.2404 | Response tokens only, held-out SFT set |
| Val PPL (SFT set) | 3.46 | Not comparable to pretrain LM PPL |
| Training steps | 1262 | 3 epochs over 30K examples |
SFT val PPL is measured on the SFT held-out set (narrower domain) and is not comparable to the pretrain LM eval PPL (12.4), which measures general language modelling ability.
| Language | Count | Source |
|---|---|---|
English (eng_Latn) | 16,500 | ai4bharat/indic-align Anudesh |
Hindi Devanagari (hin_Deva) | 5,400 | indic-align Dolly-T + OpenAssistant-T |
Kannada script (kan_Knda) | 3,900 | indic-align Dolly-T + OpenAssistant-T |
Hindi Latin translit (hin_Latn) | 2,100 | indic-align Dolly-T + OpenAssistant-T |
Kannada Latin translit (kan_Latn) | 2,100 | indic-align Dolly-T + OpenAssistant-T |
mgpt2), trained on the same corpus mixture.
Same vocabulary size as tiktoken-gpt2 (50,257 tokens), but with Indic-aware merge priorities:| Bucket | tiktoken-gpt2 | mgpt2 | Δ |
|---|---|---|---|
| Overall | 480 tok/kB | 223 tok/kB | −54% |
| Devanagari | 592 tok/kB | 215 tok/kB | −64% |
| Kannada | 981 tok/kB | 213 tok/kB | −78% |
| Latin | 257 tok/kB | 230 tok/kB | −10% |
hin_Latn and kan_Latn may switch scripts mid-generation. Cause: ASCII tokens shared with English; no Unicode anchor. Mitigated but not eliminated at this data scale.1@misc{mgpt2,
2 title = {mgpt2: Multilingual GPT-2 with custom Indic tokenizer},
3 year = {2026},
4 note = {Pretrain → SFT → DPO pipeline for English/Hindi/Kannada},
5 url = {https://huggingface.co/ace-1/mgpt2-sft}
6}