Run this model with HF Jobs

Run haithem-rtibi/gemma-4-e4b-tunisian-lora on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/haithem-rtibi/gemma-4-e4b-tunisian-lora. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/haithem-rtibi/gemma-4-e4b-tunisian-lora on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/haithem-rtibi/gemma-4-e4b-tunisian-lora. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.

Quantize for lower memory use

Use HF Jobs to create a 4-bit version of https://huggingface.co/haithem-rtibi/gemma-4-e4b-tunisian-lora. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.

gemma-4-e4b-tunisian-lora

GitHub Repo Open GPU Notebook Open CPU-Only Notebook Base Model Fine-Tuned

Experimental Notice: This model is not a commercial product. It is a personal, curiosity-driven open-source R&D experiment originally fine-tuned on May 4, 2026, and openly benchmarked, calibrated, and documented for researchers, engineers, and the Tunisian AI community.

Full Code, Gradio UI, Colab Notebook & Benchmark Logs: github.com/haithem-rtibi/gemma-4-e4b-tunisian-lora

A 4-bit QLoRA (r=8) adapter fine-tuned on top of unsloth/gemma-4-e4b-it-unsloth-bnb-4bit for Tunisian Arabic (Derja), Tunisian Arabizi (Latin-script Tunisian), and Tunisian–French–English technical code-switching, while preserving Gemma 4's native hybrid Thinking Mode (<|think|>).

System Architecture & Executive Overview


Executive Summary (For Non-Technical & Business Readers)

Everyday communication in Tunisia mixes Tunisian Arabic (Derja), Arabizi (Arabic written in Latin script with digits like 3, 7, 9), and French/English technical words. Out-of-the-box LLMs often hallucinate garbled Arabizi or slip into Moroccan Darija.

  • Lightweight & Accessible: Instead of retraining billions of weights, this experiment adapts Google's Gemma 4 E4B using an 84.9 MB LoRA adapter (21.2M parameters) that runs comfortably on a free Google Colab Tesla T4 GPU (11.1 GB VRAM, ~20 tok/s).
  • Cleaner Tunisian Behavior: Eliminates broken pseudo-Arabizi and Moroccan dialect drift observed in the base model, while preserving step-by-step Thinking Mode reasoning on Tunisian Arabizi math and logic prompts.
  • Open & Reproducible: Full inference scripts, Gradio demo UI, Colab notebook, and raw T4 evaluation logs are published on GitHub.

Verified Benchmark & Scorecard (GPU T4 vs. Pure CPU-Only)

Verified GPU (T4) & Pure CPU-Only Benchmark Scorecard

We evaluated Base Gemma 4 E4B IT vs. gemma-4-e4b-tunisian-lora on both NVIDIA Tesla T4 GPU (Unsloth 4-bit) and Pure CPU-Only (Unsloth Q4_K_M GGUF + 34.92 MB LoRA GGUF via llama.cpp, 0 GPU).

Hardware & Throughput Comparison: GPU vs. Pure CPU-Only

Deployment Profile Hardware Format / Engine Memory Used Cold Load Avg Speed LoRA Overhead
Base Model (GPU) NVIDIA Tesla T4 Unsloth 4-bit (bnb) ~11.0 GB VRAM ~210s 20.94 tok/s Baseline
Tunisian LoRA (GPU) NVIDIA Tesla T4 Unsloth 4-bit + 84.9 MB PEFT 11.10 GB VRAM 210.9s 19.58 tok/s ~6.5%
Thinking Mode (GPU) NVIDIA Tesla T4 Unsloth 4-bit (1024 tok) 11.10 GB VRAM 210.9s 20.22 tok/s ~5.9%
Base Model (CPU-Only) Intel Xeon (2 vCPUs, 0 GPU) Unsloth Q4_K_M GGUF (4.98 GB) 7.50 GB RAM 6.62s 1.99 tok/s Baseline
Tunisian LoRA (CPU-Only) Intel Xeon (2 vCPUs, 0 GPU) Unsloth Q4_K_M + 34.9 MB LoRA GGUF 7.53 GB RAM 4.90s 2.12 tok/s ~0% (No slowdown)

Hardware Notes:

  • Tesla T4: Because T4 (Compute Capability 7.5) lacks native bfloat16, Unsloth runs Gemma 4 activations in float32 while keeping weights in 4-bit.
  • Pure CPU-Only: Running Unsloth's gemma-4-E4B-it-Q4_K_M.gguf (4.98 GB) + our 34.92 MB F16 LoRA GGUF via llama.cpp -ngl 0 requires 0 GB GPU VRAM, 7.53 GB RAM, loads in ~4.9s, and reproduces the exact same clean Tunisian & Arabizi behavior.

Empirical Sampling Calibration (temperature Sweep)

Temperature Observed Quality on Tunisian Derja Verdict
0.4 Coherent but slightly stiff/repetitive phrasing Too conservative
0.7 Natural Tunisian cadence (خويا, لاباس, شنية, نجم, برشة, توة, فايق), high fluency Recommended
1.0 Lexical & idiom hallucination Too noisy

Qualitative Comparison: Base vs. Fine-Tuned

Test Dimension Base Gemma 4 E4B IT gemma-4-e4b-tunisian-lora
Zero-Shot Arabizi (no system prompt) Garbled pseudo-Arabizi (mteharriss, 5ayefou, Matnātch) Clean comprehension of 3aslema, kifech najem n7assen el anglais mta3i fisaa?, zero token corruption
Zero-Shot Tunisian Arabic (no system prompt) Drifted into Moroccan Darija (إذا بغيتي... الخدمة ديالك) Eliminated Moroccan cross-dialect drift; natural Tunisian Derja with persona prompt
Tunis Local Grounding Hallucinated "Jardin d'Antibes" and mislabeled Bardo Museum Accurately recommended Tunis landmarks (القصبة / Kasbah, المتحف الوطني التونسي, شارع الحبيب بورقيبة)
**Thinking Mode (`< think >)** (1500 DTArabizi budget,1024` tok)

Training Telemetry (May 4, 2026)

Training Telemetry

Parameter Value
Base Model unsloth/gemma-4-e4b-it-unsloth-bnb-4bit
Fine-Tuning Date May 4, 2026
Method & Stack 4-bit QLoRA SFT (Unsloth + TRL + PEFT 0.18.1)
LoRA Rank / Alpha r = 8, lora_alpha = 8 (scaling 1.0), lora_dropout = 0.0
Target Modules q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
Trainable Parameters 21,200,896 (21.2M) across 884 FP32 tensors (84.9 MB)
Steps & Tokens 1,200 steps (0.377 epoch) · 597,624 tokens · train_batch_size = 2
Learning Rate Linear warmup to 2.0e-4 -> linear decay to 5.0e-7
Training Loss 3.34 (step 1) -> 0.135 (last 50-step avg; min 0.0687)
Training Runtime 84.1 minutes (5,046.6s, 118.4 train tokens/sec)

Quickstart

For a turnkey Colab notebook, CLI script, and Gradio chat UI, see the GitHub Repository.

pip install --upgrade unsloth "transformers>=4.51.0" peft accelerate bitsandbytes
import torch
from peft import PeftModel
from unsloth import FastModel

BASE_MODEL = "unsloth/gemma-4-e4b-it-unsloth-bnb-4bit"
ADAPTER_ID = "haithem-rtibi/gemma-4-e4b-tunisian-lora"

base_model, processor = FastModel.from_pretrained(
    model_name=BASE_MODEL,
    max_seq_length=4096,
    load_in_4bit=True,
    dtype=None,
)
model = PeftModel.from_pretrained(base_model, ADAPTER_ID)
FastModel.for_inference(model)

system_prompt = (
    "أنت مساعد ذكي تحكي بالدارجة التونسية بطلاقة وبطريقة طبيعية وودودة. "
    "تفهم العربي التونسي، الأرابيزي (الدارجة بالحروف اللاتينية)، والأمثال والمصطلحات التونسية."
)
messages = [
    {"role": "system", "content": [{"type": "text", "text": system_prompt}]},
    {"role": "user", "content": [{"type": "text", "text": "عسلامة خويا! شنوة تنصحني نعمل في الويكاند في تونس العاصمة؟"}]},
]

enable_thinking = False  # Set True for <|channel>thought...<channel|> reasoning (use max_new_tokens >= 1024)
formatted = processor.apply_chat_template(
    messages,
    add_generation_prompt=True,
    tokenize=False,
    enable_thinking=enable_thinking,
)
inputs = processor(text=formatted, return_tensors="pt").to(model.device)
input_len = inputs["input_ids"].shape[-1]

with torch.inference_mode():
    output_ids = model.generate(
        **inputs,
        max_new_tokens=1024 if enable_thinking else 384,
        do_sample=True,
        temperature=0.7,
        top_p=0.95,
        top_k=64,
        repetition_penalty=1.08,
    )

tokenizer = getattr(processor, "tokenizer", processor)
raw = tokenizer.decode(output_ids[0][input_len:], skip_special_tokens=False)
print(raw.replace("<turn|>", "").strip())

Known Limitations & Engineering Notes

  1. Curiosity-Driven Prototype: Not a commercial product; intended for open experimentation and dialect NLP research.
  2. System Prompt Recommended for Pure Derja Output: In zero-shot mode (system_prompt=""), the adapter eliminates Moroccan Darija drift and garbled pseudo-Arabizi while defaulting to clean Modern Standard Arabic; using the recommended Tunisian system prompt reliably activates conversational Tunisian Derja.
  3. Partial Epoch Coverage (0.377 epoch): Trained for 1,200 steps without a logged held-out eval_loss; niche regional slang and traditional culinary specifics can still reflect base-model priors.
  4. Thinking Mode Token Budget: Internal <|channel>thought reasoning typically consumes 450–650 tokens before emitting <channel|>. Always use max_new_tokens >= 1024 when enable_thinking=True.
  5. PEFT KV-Sharing Key Warning (transformers >= 5.x): Loading the adapter emits a harmless UserWarning for k_proj/v_proj keys in layers 24–41 due to Gemma 4 KV-cache sharing; safely ignored at inference.
  6. Multimodal LoRA Tensors: Adapter weights include vision_tower (224 tensors) and audio_tower (72 tensors) alongside language_model (588 tensors).

Links & License

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support