Instructions to use mzoelfakar/Al-Khwarizmi-3B-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use mzoelfakar/Al-Khwarizmi-3B-GGUF with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama cli -hf mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M
Use Docker
docker model run hf.co/mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M
- Llama new
- LM Studio
- Jan
- Ollama
How to use mzoelfakar/Al-Khwarizmi-3B-GGUF with Ollama:
ollama run hf.co/mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M
- Unsloth Desktop
- Pi
How to use mzoelfakar/Al-Khwarizmi-3B-GGUF with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use mzoelfakar/Al-Khwarizmi-3B-GGUF with Docker Model Runner:
docker model run hf.co/mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M
- Lemonade
How to use mzoelfakar/Al-Khwarizmi-3B-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M
Run and chat with the model
lemonade run user.Al-Khwarizmi-3B-GGUF-Q4_K_M
List all available models
lemonade list
- Hermes Agent
How to use mzoelfakar/Al-Khwarizmi-3B-GGUF with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use mzoelfakar/Al-Khwarizmi-3B-GGUF with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "mzoelfakar/Al-Khwarizmi-3B-GGUF:Q4_K_M" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
|
An AI math tutor named after Muhammad al-Khwarizmi, the 9th-century mathematician whose name is the origin of the word "algorithm". Clear, step-by-step reasoning in 9 languages. |
![]() |
Fine-tune of HuggingFaceTB/SmolLM3-3B-Base, trained in three stages — full fine-tuning, LoRA, and a final DPO alignment pass — to solve grade-school math word problems.
Highlights
- Trained on the complete OpenAI GSM8K dataset (both
mainandsocraticreasoning styles) across two LoRA passes, on top of an initial full fine-tune - 87.21% mean token accuracy on held-out validation data — up from 84.75% after the initial full fine-tune, and 82.4% at the very first checkpoint
- Validation loss reduced by ~19% across the full pipeline (0.678 → 0.462), with training and validation loss tracking closely throughout every stage — no overfitting observed
- Added a final DPO (Direct Preference Optimization) stage on custom translated dataset Mini-GSM8K-Multilingual-Alignment with full explained steps as 'chosen' and vague digits-only answers as 'rejected' to make sure the model reasons well in the user's language.
- This is confirmed by the perfect chosen-vs-rejected discrimination: reward accuracy reached 100%.
- Available in this repo as GGUF with quantization for efficient usage on CPU and smaller sizes. Safetensors version available here
Training Details
Stage 1 — Full fine-tuning
| Dataset | OpenAI/GSM8K (main), 1,000 samples, 90/10 train/val split |
| Steps | 450 (1 epoch) |
| Learning rate | 5e-5, cosine schedule |
| Final validation loss / accuracy | 0.569 / 84.75% |
Stage 2 — LoRA fine-tuning
| Method | LoRA, r=16, all-linear target modules |
| Dataset | Full OpenAI/GSM8K — both main and socratic reasoning styles |
| Steps | 3,550 (combined across two passes) |
| Learning rate | 5e-5, cosine schedule |
| Final validation loss / accuracy | 0.462 / 87.21% |
Run as two consecutive passes over the dataset, with the main/socratic split swapped between them so every problem was seen in both reasoning styles.
Stage 3 — Direct Preference Optimization (DPO)
| Method | LoRA-based DPO (r=16, alpha=32, targeted layers: q_proj, k_proj, v_proj, o_proj), beta=0.5 |
| Dataset | mzoelfakar/Mini-GSM8K-Multilingual-Alignment, 480 samples |
| Steps | 30 (1 epoch) |
| Learning rate | 2e-5 peak, cosine schedule, 5 warmup steps |
| Reward accuracy | 100% |
Evaluation
| Variant | Size | GSM8K* (0-shot) |
Recovery** (Preserved accuracy compared to full model) |
Notes |
| BF16 | 6.16 GB | 62.9% | N/A | Full model |
| Q8_0 | 3.28 GB | 61.3% | 97.4% | 8-bit quantized, smaller and faster with minimal accuracy loss |
| i1-Q4_K_M | 1.92 GB | 61.0% | 97.0% | 4-bit quantized with imatrix and 'mzoelfakar/Mini-GSM8K-Multilingual-Alignment' as the calibration dataset Small enough to run on mobile phones (best with 6+ GB RAM), fastest with a small accuracy loss |
*Extractive match, standard error about ±1.3 points.
**Recovery is computed from unrounded scores; differences between variants are within the margin of error.
Supported Languages
English, Arabic, French, Spanish, German, Italian, Portuguese, Chinese, and Russian.
Limitations
Fine-tuned primarily on GSM8K-style problems (single correct numeric answer, grade-school arithmetic/word problems) — performance on more complex, multi-part, or differently-structured math problems is untested. Occasional arithmetic slips on multi-step problems can still occur, consistent with known limitations of models at this scale.
Recommended Settings
For the best efficiency, please use the following:
- Temperature: 0.7
- Context length: The base model supports up to 128k, this model was fine-tuned with a max sequence length of 2,048 tokens
System prompt:
You are a professional math tutor called Al-Khwarizmi.
You are always careful. Before answering:
- Use only the numbers and quantities explicitly stated in the problem. Do not introduce, assume, or carry over any value that wasn't given.
- Compute each arithmetic operation one at a time, and verify each result before using it in the next step.
- If asked to recheck or redo a calculation, ignore your previous answer entirely and recompute from the stated numbers.
- Before finalizing your answer, check whether every quantity mentioned in the problem (fees, taxes, discounts, additions) has been included in the final result — not just the main calculation.
- When asked to redo or resolve a problem "based on" a previous correction, use that corrected value as the starting point. Do not revert to an earlier, uncorrected path.
- Avoid sharing numbers only, always include text explanations. Apologize if you don't know the answer.
LANGUAGE RULES:
- You MUST ALWAYS reply in the SAME LANGUAGE AND SCRIPT from the user's last message, NEVER use another lanaguage, examples:
Query: مرحبا
Reply: اهلا كيف يمكنني مساعدك؟
Query: Bojour
Reply: Bonjour ! Comment ça va ?
- If the user switched language and script mid-conversation, use their new language and script, example:
Query: اسمك إيه؟
Reply: الخوارزمي
Query: All good?
Reply: I'm fine thanks, how about you?
REFRAIN from repeating unnecessary information.
NEVER help with ANY topics OTHER than math like cooking, sports etc. If asked, redirect gently.
Usage
from llama_cpp import Llama
llm = Llama.from_pretrained(
repo_id="mzoelfakar/Al-Khwarizmi-3B-GGUF",
filename="Al-Khwarizmi-3B.i1-Q4_K_M.gguf",
n_ctx=2048,
verbose=False,
)
messages = [
{"role": "system", "content": "You are a math tutor. Solve problems step by step."},
{"role": "user", "content": "If a train travels 120 miles in 2 hours, what is its average speed?"}
]
output = llm.create_chat_completion(messages=messages, max_tokens=300, temperature=0.7)
print(output["choices"][0]["message"]["content"])
Calculator-in-the-loop
Al-Khwarizmi-3B writes GSM8K-style <<expression=result>> annotations, so at inference time you can pause generation as soon as the model emits = inside a <<…>> block, calculate the precise result with a calculator, append the exact result, and resume generating from the extended text (the online chat demo includes a ready-made StoppingCriteria loop), which corrects arithmetic slips without changing the weights.
Note on raw output formatting
Because this model was fine-tuned on GSM8K (including the socratic reasoning style), raw generations may contain training artifacts not meant for direct display:
<<...>>— calculator intermediate annotations**— separator between a sub-question and its calculation in Socratic-style reasoning (not Markdown bold)#### <answer>— marker preceding the final numeric answer*— used as a multiplication sign (e.g.8*9); if two or more appear in the same response, Markdown may pair them as emphasis delimiters, causing text between them to render in italic with the asterisks hidden
If you're piping output through a Markdown renderer or displaying it in a UI, you'll likely want to strip or reformat these first, since ** in particular can be misread as Markdown bold syntax if left unescaped.
Training Code
The full training code is available here.
Credits
Fine-tuned by Mohamed Zoelfakar, as part of Hugging Face's smol-course, at Nvidia Studio Cairo.
License
Released under the Apache License 2.0.
- Downloads last month
- 1,580
Model tree for mzoelfakar/Al-Khwarizmi-3B-GGUF
Base model
HuggingFaceTB/SmolLM3-3B-Base


