Instructions to use Nimruz/Mizan-v2-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Nimruz/Mizan-v2-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Nimruz/Mizan-v2-4B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("Nimruz/Mizan-v2-4B") model = AutoModelForMultimodalLM.from_pretrained("Nimruz/Mizan-v2-4B", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Nimruz/Mizan-v2-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Nimruz/Mizan-v2-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Nimruz/Mizan-v2-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/Nimruz/Mizan-v2-4B
- SGLang
How to use Nimruz/Mizan-v2-4B 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 "Nimruz/Mizan-v2-4B" \ --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": "Nimruz/Mizan-v2-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "Nimruz/Mizan-v2-4B" \ --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": "Nimruz/Mizan-v2-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use Nimruz/Mizan-v2-4B with Docker Model Runner:
docker model run hf.co/Nimruz/Mizan-v2-4B
Mizan v2 · 4B · میزان
▶ Try it live: Mizan demo Space · by Nimruz
Which Mizan?
- Images (camera frames, receipts, product photos): this model, Mizan v2.
- Text only: use Mizan v3 3B. It's smaller (1.9 GB in 4-bit), 1.5× faster, and better at following your policies and scoring rubrics.
- All models: Mizan collection.
A Persian-first decision model that reads text and images. You give it a record (text, JSON, a camera frame, a receipt photo, a product photo) and typed questions. It returns a calibrated probability for every allowed answer, in one forward pass. There is no text generation, no parsing and no hallucinated labels.
- Text: 82.8% on 3,000 real Persian records, up from 82.0% in Mizan 1.5, and within 1 point of Jev and Clef-Flash 9B.
- Images, new in v2: security-camera questions (anyone in the red zone? which vehicle? how many people?) score 86–97% balanced accuracy on images it never saw. Receipts score 99% on "total above X?".
- One model, two ways to run it:
- text only: just the main GGUF, 2.7 GB in 4-bit;
- text + images: add the 0.37 GB vision projector.
- Jev / SystemOne compatible: the same request and response body as
/v1/systemone, plus an optionalimageslist. - Apache-2.0. Files: Mizan-v2-4B-GGUF.
Images: what it can and can't do
Scored on about 1,600 images never used in training. "Balanced" weights every answer equally, so always saying "no" can't look good; the grey tick in the chart is that baseline.
| Question | Balanced accuracy | Notes |
|---|---|---|
| Is there a person / vehicle / animal? | 96–99% | camera-style frames, day and night |
| Vehicle type · animal type | 93% | most prominent one, or "none" |
| Is a person / vehicle inside the red zone? | 92% / 96% | draw a red box on the frame to mark the zone |
| How many people (0, 1, 2–3, 4–9, 10+) | 86% | |
| Bag · phone or laptop visible? | 90% · 93% | |
| Receipt total above X? | 99% | real receipt photos (CORD) |
| Number of receipt line items | 86% | |
| Which product is on the line? (factory) | 100% | VisA products |
| Is the product defective? | 75% | useful for flagging, not for auto-rejecting; keep a human in the loop |
| Where is the defect? | not reliable | don't use it yet |
Known issue: zone questions on night-mode frames. In about a quarter of the zone examples, a bug turned the red box grey (night mode was applied after the box was drawn). Zone questions are reliable on colour frames (correct on every colour test frame we checked) and weaker on grayscale ones. This is fixed in the data pipeline for the next version.
Limits. Training images were public photos (COCO, VisA, CORD) given a camera look: overlays, night mode, compression. They weren't real CCTV footage. Test it on a few hundred of your own frames before automating. Don't use it to identify people. It was trained only on presence and behaviour questions.
Text
| Task (real Persian data) | Mizan v2 | Mizan 1.5 | Mizan 1.0 | Clef-Flash 9B | Jev (API) |
|---|---|---|---|---|---|
| Food-review sentiment (SnappFood) | 87.8 | 87.5 | 87.0 | 88.0 | 86.0 |
| Product recommend (Digikala) | 76.0 | 73.8 | 74.8 | 76.2 | 74.8 |
| Aspect question in Persian (ParsiNLU) | 79.0 | 80.0 | 71.5 | 80.0 | 80.0 |
| Offensive moderation (Pars-OFF) | 86.8 | 86.5 | 80.8 | 82.2 | 87.5 |
| Intent routing (MASSIVE fa-IR) | 79.0 | 78.5 | 72.5 | 87.7 | 78.2 |
| Article topic routing (Digikala Mag) | 81.8 | 81.5 | 80.8 | 77.0 | 82.2 |
| Claim supported by passage (FarsTail) | 89.8 | 86.5 | 83.5 | 90.0 | 97.5 |
| Mean | 82.8 | 82.0 | 78.7 | 83.0 | 83.7 |
| Calibration error (ECE) | 0.073 | 0.064 | 0.110 | 0.078 | 0.092 |
The GGUF builds score 82.8% (Q8) and 82.7% (Q4) on the same benchmark.
Inference
llama.cpp (recommended, CPU or GPU)
Needs llama.cpp b11443 or newer.
huggingface-cli download Nimruz/Mizan-v2-4B-GGUF mizan-v2-4b-Q4_K_M.gguf mmproj-mizan-v2-4b-Q8_0.gguf --local-dir .
# text + images; drop --mmproj for text only
llama-server -m mizan-v2-4b-Q4_K_M.gguf --mmproj mmproj-mizan-v2-4b-Q8_0.gguf -c 8192 -b 8192 -ub 8192 -ngl 99 --port 8080
import base64, httpx
frame = "data:image/jpeg;base64," + base64.b64encode(open("cam03.jpg", "rb").read()).decode()
body = {
"state": {"منبع": "دوربین پارکینگ"},
"images": [frame],
"questions": {
"person_in_zone": {"type": "noul", "instructions": "آیا کسی داخل کادر قرمز هست؟"},
"vehicle": {"type": "choice", "instructions": "وسیله نقلیه غالب کدام است؟",
"criteria": {"car": "سواری", "truck": "کامیون", "motorcycle": "موتور", "none": "هیچکدام"}},
},
}
print(httpx.post("http://localhost:8080/v1/systemone", json=body, timeout=60).json()["answers"])
Text requests are the same without images.
Speed:
- On an NVIDIA L4 (Q4): about 80 ms per text request and about 470 ms with an image, median.
- Images through llama.cpp score about the same as the full model; see the GGUF card.
- Measured on CPU only (Q4, Mizan 1.5, same architecture): about 3 s median per text request on 16 cores, and about 18 s on 2 cores. For real-time use, run it on a GPU; an entry-level 8 GB card is enough.
Python (transformers, text + images)
import json, sys, torch
from huggingface_hub import snapshot_download
from PIL import Image
path = snapshot_download("Nimruz/Mizan-v2-4B")
sys.path.insert(0, path)
from joint_schema_model import collate_records, encode_record, load_release_model
model, processor = load_release_model(path, device="cuda")
temps = json.load(open(f"{path}/unsloth_decision_config.json"))["temperature"] # choice, score, noul
record = {"state": "تصویر پیوست", "images": [Image.open("cam03.jpg")],
"questions": {"person": {"type": "noul", "instructions": "آیا کسی در تصویر هست؟"}}}
encoded = encode_record(processor.tokenizer, record, processor=processor)
logits = model(collate_records([encoded], processor.tokenizer.pad_token_id, torch.device("cuda")))[0]
for q, z in zip(encoded.questions, logits):
t = {0: temps[2], 1: temps[0], 2: temps[1]}[q.question_type] # calibrated temperature for this type
print(q.question_id, dict(zip(q.option_ids, (z.float() / t).softmax(-1).tolist())))
Unsloth's FastDecisionModel also loads this repo, for text only.
Training
- Start: Mizan 1.5. Its text-decision skills come from Unsloth training: Persian business workflows, mined real mistakes and an English decision mixture.
- v2 stage: a custom loop around the Clef reference code (
joint_schema_model.py), because Unsloth's decision trainer doesn't pass images.- LoRA r=32 on the language model, a 10× lower-rate LoRA on the vision merger and last 4 vision blocks, and the decision head.
- 500 steps on 1× H100 (59 min), with soft-label cross-entropy per question.
- Data:
- Images (~3,000 rows):
- COCO frames given a security-camera look (camera name and Persian timestamp, night mode, compression, red zone boxes), with Persian and English questions. Answers come from COCO's human annotations, and questions are skipped when tiny, cut-off or crowded objects make the answer uncertain.
- VisA factory photos, normal and defective, with product names.
- CORD real receipts, with totals and item counts from their parsed labels.
- Only images under licenses that allow commercial use: COCO's CC BY / CC BY-SA / public-domain subset, VisA (CC BY 4.0) and CORD (CC BY 4.0).
- Text replay: 2,500 Persian and 1,800 English rows, so text skills hold.
- Images (~3,000 rows):
- Calibration: per-type temperatures refitted on held-out text.
License
Apache-2.0. Image training data: COCO (commercial-use licenses only), VisA (CC BY 4.0), CORD (CC BY 4.0).
- Downloads last month
- 92

