180 lines
7.3 KiB
Markdown
180 lines
7.3 KiB
Markdown
|
|
---
|
||
|
|
license: apache-2.0
|
||
|
|
base_model: Qwen/Qwen3-8B
|
||
|
|
tags:
|
||
|
|
- qwen3
|
||
|
|
- tanglish
|
||
|
|
- tamil
|
||
|
|
- code-mixed
|
||
|
|
- chennai
|
||
|
|
- conversational
|
||
|
|
- lora
|
||
|
|
- sft
|
||
|
|
language:
|
||
|
|
- ta
|
||
|
|
- en
|
||
|
|
pipeline_tag: text-generation
|
||
|
|
library_name: transformers
|
||
|
|
---
|
||
|
|
|
||
|
|
# Qwen3-8B · Tanglish LoRA v1
|
||
|
|
|
||
|
|
Fine-tune of [`Qwen/Qwen3-8B`](https://huggingface.co/Qwen/Qwen3-8B) that
|
||
|
|
replies in casual **Tanglish** — code-mixed Tamil transliterated into the Latin
|
||
|
|
alphabet, as spoken every day in Chennai and across South India.
|
||
|
|
|
||
|
|
Trained on [sugiv/tanglish-pairs-v1](https://huggingface.co/datasets/sugiv/tanglish-pairs-v1)
|
||
|
|
(81,261 SFT examples) with LoRA r=16, alpha=32 on the bf16 base (**not**
|
||
|
|
QLoRA/4-bit — L40S 48 GB has enough VRAM for cleaner training). This repo ships
|
||
|
|
the **fully merged bf16 model** (16.4 GB) plus a standalone PEFT adapter and all
|
||
|
|
27 intermediate resume checkpoints.
|
||
|
|
|
||
|
|
## Highlights (from Phase 4 eval)
|
||
|
|
|
||
|
|
- **Beats stock Qwen3-8B on every LLM-judge dimension** on both single-turn and multi-turn
|
||
|
|
Tanglish prompts. Full report at [`eval/PHASE_4_EVAL.md`](eval/PHASE_4_EVAL.md).
|
||
|
|
- Judge: `qwen3-235b-a22b-instruct-2507`, temperature=0, 40/40 parses successful.
|
||
|
|
|
||
|
|
| Dimension (1-5, higher = better) | tng | base | delta |
|
||
|
|
| --- | ---: | ---: | ---: |
|
||
|
|
| single-turn intelligibility | 4.87 | 4.20 | +0.67 |
|
||
|
|
| single-turn **tanglish_authenticity** | **4.33** | 3.00 | **+1.33** |
|
||
|
|
| single-turn helpfulness | 4.00 | 3.33 | +0.67 |
|
||
|
|
| single-turn naturalness | 4.60 | 3.53 | +1.07 |
|
||
|
|
| multi-turn intelligibility | 5.00 | 4.80 | +0.20 |
|
||
|
|
| multi-turn tanglish_authenticity | 4.00 | 3.60 | +0.40 |
|
||
|
|
| multi-turn **helpfulness** | **4.60** | 3.60 | **+1.00** |
|
||
|
|
| multi-turn naturalness | 4.80 | 4.00 | +0.80 |
|
||
|
|
|
||
|
|
- **7.5x faster inference than base**: 1.91 s vs 14.39 s mean single-turn on L4.
|
||
|
|
Base emits a `<think>Okay, the user is asking...</think>` reasoning dump on
|
||
|
|
every casual chat; this fine-tune was trained on outputs that keep
|
||
|
|
`<think></think>` empty so it goes straight to the Tanglish reply.
|
||
|
|
- **Zero Tamil-script leaks** on 15 held-out prompts (base has 3/15).
|
||
|
|
|
||
|
|
## Training (verified from `training/qwen_train.log` + `trainer_state.json`)
|
||
|
|
|
||
|
|
| Setting | Value |
|
||
|
|
| --- | --- |
|
||
|
|
| Base model | `Qwen/Qwen3-8B` (bf16, flash_attention_2, gradient_checkpointing) |
|
||
|
|
| Adapter | LoRA r=16, alpha=32, target = all-linear |
|
||
|
|
| Precision | bf16 (**not** QLoRA / 4-bit) |
|
||
|
|
| Corpus | [sugiv/tanglish-pairs-v1](https://huggingface.co/datasets/sugiv/tanglish-pairs-v1), 77,198 train + 4,063 val |
|
||
|
|
| Effective batch size | 32 (per-device 4 x grad-accum 8) |
|
||
|
|
| Learning rate | 2e-4 cosine, warmup steps = 100 |
|
||
|
|
| Total training steps | ~14,475 (3 full epochs, last saved checkpoint at 13,500) |
|
||
|
|
| **Best `eval_loss`** | **0.8126** at step 13,500 |
|
||
|
|
| First eval (step 500) | 1.1184 |
|
||
|
|
| Eval-loss trajectory | monotonically decreasing across all 27 checkpoints |
|
||
|
|
| Optimizer | AdamW |
|
||
|
|
| Hardware | 1x L40S 48 GB SECURE (RunPod, US-KS-1) |
|
||
|
|
| Wall time | ~11 hours |
|
||
|
|
| Cost | ~$13.36 |
|
||
|
|
|
||
|
|
Full step-by-step training log at [`training/qwen_train.log`](training/qwen_train.log)
|
||
|
|
(2.1 MB, 702 log entries). Config at [`training/qwen_train_tanglish.yaml`](training/qwen_train_tanglish.yaml).
|
||
|
|
|
||
|
|
## Usage
|
||
|
|
|
||
|
|
### Merged model (recommended, no PEFT install needed)
|
||
|
|
|
||
|
|
```python
|
||
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||
|
|
|
||
|
|
model = AutoModelForCausalLM.from_pretrained(
|
||
|
|
"sugiv/qwen3-8b-tanglish",
|
||
|
|
torch_dtype="bfloat16",
|
||
|
|
device_map="cuda",
|
||
|
|
token="hf_...",
|
||
|
|
)
|
||
|
|
tok = AutoTokenizer.from_pretrained("sugiv/qwen3-8b-tanglish", token="hf_...")
|
||
|
|
|
||
|
|
msgs = [
|
||
|
|
{"role": "system", "content": "You are a friendly Tanglish-speaking assistant. Reply naturally in casual, code-mixed Tanglish..."},
|
||
|
|
{"role": "user", "content": "machi, nalaikku Chennai la enna weather?"},
|
||
|
|
]
|
||
|
|
prompt = tok.apply_chat_template(msgs, add_generation_prompt=True, return_tensors="pt").to("cuda")
|
||
|
|
out = model.generate(prompt, max_new_tokens=200, temperature=0.7, top_p=0.9, do_sample=True)
|
||
|
|
print(tok.decode(out[0][prompt.shape[-1]:], skip_special_tokens=True))
|
||
|
|
# => 'da, innum hot ah iruku, morning la 28 degree nu solraanga.'
|
||
|
|
```
|
||
|
|
|
||
|
|
### LoRA adapter (attach to a stock Qwen3-8B)
|
||
|
|
|
||
|
|
```python
|
||
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||
|
|
from peft import PeftModel
|
||
|
|
|
||
|
|
base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-8B", torch_dtype="bfloat16", device_map="cuda")
|
||
|
|
model = PeftModel.from_pretrained(base, "sugiv/qwen3-8b-tanglish", subfolder="lora", token="hf_...")
|
||
|
|
```
|
||
|
|
|
||
|
|
### vLLM / RunPod Serverless (production)
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# On Runpod Hub: pick `runpod-workers/worker-vllm`, set:
|
||
|
|
# MODEL_NAME = sugiv/qwen3-8b-tanglish
|
||
|
|
# DTYPE = bfloat16
|
||
|
|
# MAX_MODEL_LEN = 2048
|
||
|
|
# HF_TOKEN = hf_...
|
||
|
|
# GPU: L40S 48 GB SECURE recommended (fits with headroom).
|
||
|
|
```
|
||
|
|
|
||
|
|
### Resume from any of the 27 intermediate checkpoints
|
||
|
|
|
||
|
|
Every checkpoint under `checkpoints/checkpoint-{500,1000,...,13500}/` contains
|
||
|
|
the LoRA adapter, optimizer state, LR scheduler state, RNG state, and
|
||
|
|
`trainer_state.json` — enough to resume TRL SFTTrainer from that exact step.
|
||
|
|
|
||
|
|
## Repo contents
|
||
|
|
|
||
|
|
| Path | Bytes | What |
|
||
|
|
| --- | ---: | --- |
|
||
|
|
| `model-000{1..4}-of-00004.safetensors` | ~16.4 GB | Merged bf16 weights (base + LoRA collapsed) |
|
||
|
|
| `config.json` + `tokenizer*` + `chat_template.jinja` | ~14 MB | Same as base Qwen3-8B, unmodified |
|
||
|
|
| `lora/adapter_model.safetensors` | ~175 MB | LoRA-only best adapter (step 13500) |
|
||
|
|
| `lora/{adapter_config,training_args,tokenizer*}` | ~14 MB | PEFT metadata + tokenizer |
|
||
|
|
| `checkpoints/checkpoint-*/` | ~14 GB (27 dirs) | Resume checkpoints every 500 steps, includes optimizer.pt + scheduler.pt |
|
||
|
|
| `eval/MANIFEST.json` | ~80 KB | 40 records with LLM-judge scores across 4 dimensions |
|
||
|
|
| `eval/PHASE_4_EVAL.md` | ~6 KB | Human-readable eval report with side-by-side samples |
|
||
|
|
| `training/qwen_train.log` | ~2 MB | Full stdout from the 11-hour training run |
|
||
|
|
| `training/*.yaml` | ~5 KB | Training config used |
|
||
|
|
|
||
|
|
## Known limitations
|
||
|
|
|
||
|
|
- **Soft-refusal on safety**: the model deflects "how do I hack a database"
|
||
|
|
with playful Tanglish banter instead of a textbook refusal. Judge deducts
|
||
|
|
helpfulness=1 but flags the response as safe. If you need a stricter tone,
|
||
|
|
layer a system-prompt refusal template at the agent layer.
|
||
|
|
- **Verbose reasoning mode is trained out**: the base Qwen3-8B emits
|
||
|
|
`<think>...</think>` reasoning blocks on casual chat, and this fine-tune
|
||
|
|
suppresses that behaviour. If you *want* explicit reasoning, use the base
|
||
|
|
model — this one goes straight to the answer.
|
||
|
|
- **Language support**: Tanglish (Latin-script Tamil + English code-mix) is
|
||
|
|
the trained target. It can still reply in pure Tamil script or pure
|
||
|
|
English if prompted, but the training corpus is 100% transliterated
|
||
|
|
Tanglish.
|
||
|
|
|
||
|
|
## License
|
||
|
|
|
||
|
|
Apache-2.0 (inherited from `Qwen/Qwen3-8B`). Commercial use allowed. Attribution
|
||
|
|
to both this repo and the base model is appreciated.
|
||
|
|
|
||
|
|
## Citation
|
||
|
|
|
||
|
|
```bibtex
|
||
|
|
@misc{tanglish_qwen3_2026,
|
||
|
|
title={Qwen3-8B Tanglish LoRA},
|
||
|
|
author={sugiv},
|
||
|
|
year={2026},
|
||
|
|
url={https://huggingface.co/sugiv/qwen3-8b-tanglish}
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
## Related
|
||
|
|
|
||
|
|
- Companion training corpus: [sugiv/tanglish-pairs-v1](https://huggingface.co/datasets/sugiv/tanglish-pairs-v1)
|
||
|
|
- Companion voice TTS: [sugiv/fish-speech-1.5-tanglish](https://huggingface.co/sugiv/fish-speech-1.5-tanglish)
|
||
|
|
- Underlying audio dataset: [sugiv/tanglish-audio-v1](https://huggingface.co/datasets/sugiv/tanglish-audio-v1)
|
||
|
|
- Base model: [Qwen/Qwen3-8B](https://huggingface.co/Qwen/Qwen3-8B)
|