CoolFace
Modelpublic

nassimjp/MiniCPM5-2B-SFT-Pashto-Instruct

sourceHugging Faceapache-2.0updated 17d agoView on Hugging Face
0likes1.9kdownloads
Model Card

🧬 MiniCPM5-2B-SFT-Pashto-Instruct

Pashto Instruction-Tuned Model (Tokenizer Surgery + SFT) 🚀🧬🇦🇫

MiniCPM5-2B-SFT-Pashto-Instruct is a specialized Pashto instruction-tuned model developed as part of the iPashto.ai initiative.

Two-Stage Development Pipeline:

  1. 1.Stage 1: Tokenizer Surgery 🔧
  2. 2.Applied tokenizer surgery to openbmb/MiniCPM5-2B
  3. 3.Added 46 missing Pashto/Urdu characters as single tokens
  4. 4.Result: nassimjp/MiniCPM5-2B-Pashto
  1. 1.Stage 2: Supervised Fine-Tuning 🎯
  2. 2.Fine-tuned the surgically-enhanced model on Pashto instruction data
  3. 3.Used LoRA/QLoRA adapter techniques with very low learning rate (5e-6)
  4. 4.Fully merged into 16-bit (bfloat16) safetensors format

📋 Model Overview

PropertyValue
Developed byNassimjp / iPashto.ai
Base Model (Pre-Surgery)openbmb/MiniCPM5-2B
Tokenizer Surgery Modelnassimjp/MiniCPM5-2B-Pashto
Final Modelnassimjp/MiniCPM5-2B-SFT-Pashto-Instruct
Original Vocab Size130,560
Vocab Size After Surgery130,606
Atoms Added46
LanguagePashto (ps), English (en)
LicenseApache-2.0
ArchitectureCausal LM (MiniCPM Architecture)
Precision16-bit (bfloat16 Merged)
Training MethodSupervised Fine-Tuning (SFT) via LoRA/QLoRA
Training Samples< 10,000 Pashto instruction pairs
Sequence LengthUp to 40K tokens per sample
Learning Rate5e-6 (very low, conservative fine-tuning)
HardwareNVIDIA RTX 4070 Ti SUPER (16GB VRAM)

🎯 Why This Model Exists

The Problem:

  • —❌ Pashto is a low-resource language with limited AI support
  • —❌ Original MiniCPM5-2B tokenizer splits many Pashto characters into multiple tokens
  • —❌ Inefficient tokenization → poor instruction following
  • —❌ No open-weight Pashto instruction-tuned models available

The Solution (Two-Stage Approach):

  1. 1.✅ Stage 1: Tokenizer surgery — added 46 missing Pashto/Urdu atoms as single tokens
  2. 2.✅ Stage 2: Fine-tuned on < 10K high-quality Pashto instruction pairs with conservative LR (5e-6)
  3. 3.✅ Supports long-form generation (up to 40K tokens per sample)
  4. 4.✅ Preserves Pashto script integrity
  5. 5.✅ Openly available for the community

📊 Stage 1: Tokenizer Surgery Report

✅ Existing Single-Token Atoms (20)

AtomIDAtomID
ا20541د57692
ب79922ر37101
پ120234ز124105
ت55761س75848
ح118797ش107172
ع84439ک77297
ف79312ل29673
ق74411م36367
ن35964ه64732
و41636ی46703

⚠️ Split Atoms — FIXED via Surgery (46)

#AtomOld IDsNew ID
1ښ[172, 270]130560
2څ[172, 249]130561
3ځ[172, 245]130562
4ڼ[172, 142]130563
5ږ[172, 266]130564
6ډ[172, 253]130565
7ټ[171, 142]130566
8ړ[172, 263]130567
9ې[173, 260]130568
10ۍ[173, 257]130569
11ګ[172, 126]130570
12ث[170, 126]130571
13ج[170, 127]130572
14چ[172, 250]130573
15خ[170, 128]130574
16ذ[170, 130]130575
17ص[170, 135]130576
18ض[170, 136]130577
19ط[170, 137]130578
20ظ[170, 138]130579
21غ[170, 140]130580
22ئ[170, 121]130581
23ے[173, 262]130582
24ۀ[173, 244]130583
25ٹ[171, 139]130584
26ڈ[172, 252]130585
27ڑ[172, 261]130586
28ں[172, 140]130587
29ھ[172, 144]130588
30گ[172, 129]130589
31أ[170, 118]130590
32إ[170, 120]130591
33آ[170, 117]130592
34ؤ[170, 119]130593
35ء[170, 116]130594
36ٱ[171, 131]130595
37۰[173, 130]130596
38۱[173, 131]130597
39۲[173, 132]130598
40۳[173, 133]130599
41۴[173, 134]130600
42۵[173, 135]130601
43۶[173, 136]130602
44۷[173, 137]130603
45۸[173, 138]130604
46۹[173, 139]130605

🔬 Embedding Forensics (After Surgery)

MetricValue
Mean embedding norm0.882395
Max cosine similarity0.27078322
Most Similar Pairب ↔ م (cosine = 0.27078322)

✅ No exact duplicate embeddings detected


📊 Stage 2: Training Highlights & Loss Metrics

The fine-tuning run was executed locally using an NVIDIA RTX 4070 Ti SUPER (16GB VRAM) across 8,952 steps.

Key Training Parameters

ParameterValue
Learning Rate5e-6 (very low, conservative)
Training Steps8,952
Training Samples< 10,000 Pashto instruction pairs
Max Sequence Length40K tokens
TokenizerSurgically enhanced (46 new Pashto tokens)

Loss Metrics

MetricValue
Initial Training Loss4.61
Final Training Loss~0.54
Evaluation Loss~0.91 (no overfitting)
Gradient Norm1.4 - 2.2 (stable updates)

Why 5e-6 Learning Rate?

Using a very low learning rate (5e-6) was a deliberate choice:

  • —✅ Preserves surgically-added token embeddings — prevents catastrophic forgetting of the 46 new tokens
  • —✅ Conservative adaptation — the base model already has strong language capabilities; we only need to teach it to follow instructions
  • —✅ Prevents overfitting — with < 10K samples, aggressive LR would cause overfitting
  • —✅ Stable gradient norms — maintained 1.4-2.2 throughout training
  • —✅ Excellent convergence — loss dropped from 4.61 to 0.54 without instability

🚀 Quickstart & Usage

1. Using Transformers (Python)

python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_id = "nassimjp/MiniCPM5-2B-SFT-Pashto-Instruct"

tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True
)

# Example 1: Pashto Question
prompt = "د پښتو ژبې او مصنوعي ځیرکتیا پرمختګ څه اهمیت لري؟"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")

outputs = model.generate(
    **inputs,
    max_new_tokens=256,
    temperature=0.7,
    do_sample=True,
    pad_token_id=tokenizer.eos_token_id
)

print(tokenizer.decode(outputs[0], skip_special_tokens=True))

# Example 2: Check that Pashto atoms are single tokens
test_chars = "ښڅځڼږډټړېۍګ"
for char in test_chars:
    ids = tokenizer.encode(char, add_special_tokens=False)
    print(f"'{char}' → {ids}")  # All should be single tokens!

2. Long-Form Generation (up to 40K tokens)

python
long_prompt = "د افغانستان تاریخ..."  # Can be up to 40K tokens
inputs = tokenizer(long_prompt, return_tensors="pt", truncation=True, max_length=40000)

3. Streaming Generation

python
from transformers import TextStreamer

streamer = TextStreamer(tokenizer, skip_prompt=True)
outputs = model.generate(
    **inputs,
    max_new_tokens=512,
    temperature=0.7,
    streamer=streamer
)

4. Batch Inference

python
prompts = [
    "پښتو ژبه څنګه زده کړم؟",
    "د افغانستان پلازمینه څه ده؟",
    "پښتو ادب په اړه وږغاړئ"
]

inputs = tokenizer(prompts, padding=True, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=128, temperature=0.7)

5. Running via llama.cpp / GGUF

bash
./llama-cli -m ./MiniCPM5-2B-SFT-Pashto-Instruct.F16.gguf \
  -p "د پښتو ژبې او مصنوعي ځیرکتیا پرمختګ څه اهمیت لري؟" \
  -n 256 \
  -t 8

⚙️ Training Details

Dataset

  • —Size: < 10,000 Pashto instruction-response pairs
  • —Format: Instruction + Response pairs
  • —Language: Pashto (ps) with some English (en) examples
  • —Max Length: Up to 40K tokens per sample

Training Configuration

ParameterValue
MethodLoRA/QLoRA
Precisionbfloat16
OptimizerAdamW
Learning Rate5e-6 (very low, conservative)
LR SchedulerCosine decay
Warmup Steps100-200
Batch SizeTuned for 16GB VRAM
LoRA Rank16-32
LoRA Alpha32-64
Dropout0.05

Hardware

  • —GPU: NVIDIA RTX 4070 Ti SUPER
  • —VRAM: 16GB
  • —Training Duration: Several days (8,952 steps)

📂 Model Files

MiniCPM5-2B-SFT-Pashto-Instruct/
├── config.json                      ~1 KB
├── generation_config.json           ~1 KB
├── model.safetensors                ~4-5 GB
├── tokenizer.json                   ~9 MB (surgically enhanced)
├── tokenizer_config.json            ~1 KB
├── special_tokens_map.json          ~1 KB
└── training_logs.json               Training metrics

⚠️ Important Notes

NoteDescription
TokenizerSurgically enhanced — all 66 Pashto/Urdu atoms are single tokens
Base ModelBuilt on nassimjp/MiniCPM5-2B-Pashto (surgically modified)
LanguagePrimarily Pashto (ps), with some English instruction examples
Size~2B parameters, ~4-5 GB in bfloat16
Long ContextSupports up to 40K tokens per sample
Learning Rate5e-6 — very conservative to preserve token embeddings
Fine-tuningLoRA/QLoRA merged weights (not just adapter)

🧪 Testing Results

All 66 Pashto/Urdu atoms are now single tokens:

CategoryCountStatus
Pashto-Specific11✅ All single tokens
Shared Arabic/Persian30✅ All single tokens
Positional Forms3✅ All single tokens
Urdu/South Asian6✅ All single tokens
Arabic Variants6✅ All single tokens
Eastern Arabic Digits10✅ All single tokens
TOTAL66✅ 100% Coverage

🔗 Related Resources


📝 Citation

If you use this model, please cite:

bibtex
@misc{minicpm5-pashto-instruct,
  author = {Nassimjp},
  title = {MiniCPM5-2B-SFT-Pashto-Instruct: Pashto Instruction-Tuned Model with Tokenizer Surgery},
  year = {2026},
  publisher = {Hugging Face},
  howpublished = {\url{https://huggingface.co/nassimjp/MiniCPM5-2B-SFT-Pashto-Instruct}}
}

@article{minicpm2024,
  title={MiniCPM: Unveiling the Potential of Small Language Models},
  author={Hu, Shengding and Ding, Ning and others},
  journal={arXiv preprint arXiv:2404.06395},
  year={2024}
}

📄 License

This model is released under the Apache License 2.0.


🤝 Acknowledgements

  • —OpenBMB for developing MiniCPM5-2B
  • —Hugging Face for the transformers library and model hosting
  • —iPashto.ai community for dataset contributions and testing

🌐 Project Context

Developed under the iPashto.ai framework dedicated to advancing Pashto Natural Language Processing (NLP), specialized datasets, and open-weight AI accessibility for low-resource languages.


📬 Contact & Support


Created with ❤️ for the Pashto community


---