Optimized-Persian-LLM
huggingface-cli download iman1377/Optimized-Persian-LLM \
gguf/Optimized-Persian-LLM-1B-Q4_0.gguf --local-dir ./opl
llama-cli -m ./opl/gguf/Optimized-Persian-LLM-1B-Q4_0.gguf -ngl 99 -fa on -c 4096 -cnv
pip install llama-cpp-python huggingface_hub
import time
from llama_cpp import Llama
from huggingface_hub import hf_hub_download
path = hf_hub_download("iman1377/Optimized-Persian-LLM",
"gguf/Optimized-Persian-LLM-1B-Q4_0.gguf")
llm = Llama(model_path=path, n_gpu_layers=-1, n_ctx=2048, verbose=False) # CPU: n_gpu_layers=0
PROBES = [
("پایتخت ایران کجاست؟ فقط در یک جمله پاسخ بده.", "تهران"),
("پایتخت ایران کجاست؟", "تهران"),
("یک تابع پایتون برای جمع دو عدد بنویس.", "def"),
("سه کاربرد یادگیری ماشین را کوتاه فهرست کن.", None),
]
def persian_ratio(t):
L = [c for c in t if c.isalpha()]
return sum("\u0600" <= c <= "\u06FF" for c in L) / max(1, len(L))
passed = 0
for q, must in PROBES:
a = llm.create_chat_completion(messages=[{"role": "user", "content": q}],
temperature=0, max_tokens=200)["choices"][0]["message"]["content"].strip()
ok = (must in a) if must else (len(a) > 20 and persian_ratio(a) >= 0.5)
passed += ok
print(f"[{'PASS' if ok else 'FAIL'}] {q}\n {a[:160]}\n")
t = time.time()
r = llm.create_chat_completion(messages=[{"role": "user", "content": "یک پاراگراف درباره تاریخ ایران بنویس."}],
temperature=0, max_tokens=256)
n = r["usage"]["completion_tokens"]
print(f"quality: {passed}/{len(PROBES)} speed: {n/(time.time()-t):.1f} tok/s")
English
Ready-to-run Gemma 3 1B for Persian and English, built on Google's quantization-aware checkpoint. One Q4_0 GGUF file (687 MiB), no custom code, runs with llama.cpp on CPU, one GPU or many.
Benchmarks
Tesla T4, llama.cpp, flash attention on.
| Metric | Value | Conditions |
|---|---|---|
| Generation (tg128) | 162.37 tok/s | 1xT4, single stream |
| Prompt processing (pp512) | 7,035 tok/s | 1xT4, single stream |
| Batched throughput | ~2,200 tok/s | 1xT4, 256 concurrent |
| Batched throughput | ~4,300 tok/s | 2xT4 independent, 256 each |
| Quality vs F16 (held-out Persian) | -18.57% perplexity | previous IQ4_XS build: +24.51% |
Test
Run the Python script above. Expected output is quality: 4/4; the speed line reflects your own hardware.
Derived from google/gemma-3-1b-it-qat-q4_0-unquantized, released under the Gemma licence.