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.
Instructions to use haithem-rtibi/gemma-4-e4b-tunisian-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use haithem-rtibi/gemma-4-e4b-tunisian-lora with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/gemma-4-e4b-it-unsloth-bnb-4bit") model = PeftModel.from_pretrained(base_model, "haithem-rtibi/gemma-4-e4b-tunisian-lora") - Transformers
How to use haithem-rtibi/gemma-4-e4b-tunisian-lora with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="haithem-rtibi/gemma-4-e4b-tunisian-lora") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("haithem-rtibi/gemma-4-e4b-tunisian-lora", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use haithem-rtibi/gemma-4-e4b-tunisian-lora with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "haithem-rtibi/gemma-4-e4b-tunisian-lora" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "haithem-rtibi/gemma-4-e4b-tunisian-lora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/haithem-rtibi/gemma-4-e4b-tunisian-lora
- SGLang
How to use haithem-rtibi/gemma-4-e4b-tunisian-lora with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "haithem-rtibi/gemma-4-e4b-tunisian-lora" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "haithem-rtibi/gemma-4-e4b-tunisian-lora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "haithem-rtibi/gemma-4-e4b-tunisian-lora" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "haithem-rtibi/gemma-4-e4b-tunisian-lora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Desktop
- Docker Model Runner
How to use haithem-rtibi/gemma-4-e4b-tunisian-lora with Docker Model Runner:
docker model run hf.co/haithem-rtibi/gemma-4-e4b-tunisian-lora
gemma-4-e4b-tunisian-lora
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|>).
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 E4Busing an84.9 MBLoRA adapter (21.2Mparameters) 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)
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 infloat32while keeping weights in 4-bit.- Pure CPU-Only: Running Unsloth's
gemma-4-E4B-it-Q4_K_M.gguf(4.98 GB) + our34.92 MBF16 LoRA GGUF viallama.cpp -ngl 0requires0 GBGPU VRAM,7.53 GBRAM, 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)
| 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
- Curiosity-Driven Prototype: Not a commercial product; intended for open experimentation and dialect NLP research.
- 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. - Partial Epoch Coverage (
0.377epoch): Trained for1,200steps without a logged held-outeval_loss; niche regional slang and traditional culinary specifics can still reflect base-model priors. - Thinking Mode Token Budget: Internal
<|channel>thoughtreasoning typically consumes450–650tokens before emitting<channel|>. Always usemax_new_tokens >= 1024whenenable_thinking=True. - PEFT KV-Sharing Key Warning (
transformers >= 5.x): Loading the adapter emits a harmlessUserWarningfork_proj/v_projkeys in layers24–41due to Gemma 4 KV-cache sharing; safely ignored at inference. - Multimodal LoRA Tensors: Adapter weights include
vision_tower(224tensors) andaudio_tower(72tensors) alongsidelanguage_model(588tensors).
Links & License
- GitHub Repository (Code, UI, Colab Notebook & Benchmarks): github.com/haithem-rtibi/gemma-4-e4b-tunisian-lora
- Author: Haithem Rtibi
- License: Derived from Google's Gemma 4 E4B Instruct (
unsloth/gemma-4-e4b-it-unsloth-bnb-4bit). Governed by the Gemma Terms of Use.
- Downloads last month
- -


