Fine-tuning Qwen2.5-3B-Instruct for Gulf enterprise Arabic-English code-switching using QLoRA, tracked with MLflow, benchmarked with custom eval suite.
Gulf enterprise professionals communicate in Arabic-English code-switching — Arabic prose with English technical terms embedded naturally ("الـ supply chain efficiency" not "كفاءة سلسلة التوريد"). Base LLMs collapse to pure Arabic on this input, losing the register Gulf professionals actually use.
| Metric | Base Qwen2.5-3B | Fine-tuned | Improvement |
|---|---|---|---|
| Avg Code-Switch Ratio | 5.1% | 34.7% | +584% |
| Supply Chain prompt | 3.2% | 46.0% | +1337% |
| ML/DL prompt | 6.9% | 36.0% | +421% |
| Data preprocessing prompt | 5.2% | 31.4% | +504% |
| Overfitting prompt | 5.1% | 25.7% | +403% |
Input: كيف نحسن الـ supply chain efficiency في الـ manufacturing؟
Base model (5.1% CS ratio):
تحسين كفاءة الشبكة الصناعية يمكن أن يشمل عدة خطوات رئيسية... (collapses to pure Arabic, drops English terms)
Fine-tuned (46.0% CS ratio):
هناك عدة طرق يمكن استخدامها لتحسين الـ supply chain efficiency في الـ manufacturing، منها تحسين الـ inventory management باستخدام الـ ERP systems و الـ CRM systems... (maintains Gulf professional register)
- Base Model: Qwen2.5-3B-Instruct
- Fine-tuning: QLoRA via HuggingFace PEFT (LoRA r=16, alpha=32)
- Experiment Tracking: MLflow
- Hardware: Apple M5 Max (MPS)
- Dataset: synthetically generated via Groq Llama API
01_download_data.py → Pull public Arabic instruction datasets (7,620 samples)
02_generate_codeswitched.py → Synthetic code-switching via Groq LLaMA (653 clean samples)
03_prepare_dataset.py → Format + push dataset to HuggingFace
04_train.py → QLoRA training with MLflow tracking (3 epochs, loss: 1.388)
05_merge_and_push.py → Merge adapter + push model to HuggingFace
06_serve_local.py → Local inference + comparison
eval/benchmark.py → Quantitative base vs fine-tuned evaluation
Why QLoRA over full fine-tuning? Full fine-tuning 3B parameters requires 24GB+ VRAM. QLoRA injects trainable rank decomposition matrices (r=16) into attention layers only — 1% of parameters trained, same task adaptation, fits on consumer hardware.
Why r=16, alpha=32? r=16 balances capacity vs memory. r=4 insufficient for register learning. r=64 approaches full fine-tuning cost. alpha=2x rank is standard scaling — LoRA contribution scaled by alpha/r=2, enough influence without overwriting pretrained weights.
Why Qwen2.5 over Llama 3.2? Qwen2.5 has stronger Arabic in pretraining mixture. Better multilingual base = less fine-tuning data needed for same result.
Why MLflow over W&B? Open source, self-hosted, zero external dependencies. Anyone cloning this repo runs identical experiment tracking locally.
- Model: pranav63/qwen2.5-3b-arabic-en-instruct
- Dataset: pranav63/arabic-english-codeswitched-instructions
- Epochs: 3
- Final train loss: 1.388
- Batch size: 1 (gradient accumulation: 8, effective batch: 8)
- Learning rate: 2e-4 with cosine schedule
- Training time: ~6 minutes on M5 Max
- Trainable parameters: ~1% of total
