Text Generation
Transformers
Safetensors
Thai
English
qwen3_moe
nvfp4
fp4
modelopt
quantized
vllm
thai
dgx-spark
agicafet
8-bit precision
Instructions to use NatdhanaiPython/ThaiLLM-30B-NVFP4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use NatdhanaiPython/ThaiLLM-30B-NVFP4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="NatdhanaiPython/ThaiLLM-30B-NVFP4")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("NatdhanaiPython/ThaiLLM-30B-NVFP4") model = AutoModelForCausalLM.from_pretrained("NatdhanaiPython/ThaiLLM-30B-NVFP4") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use NatdhanaiPython/ThaiLLM-30B-NVFP4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "NatdhanaiPython/ThaiLLM-30B-NVFP4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NatdhanaiPython/ThaiLLM-30B-NVFP4", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/NatdhanaiPython/ThaiLLM-30B-NVFP4
- SGLang
How to use NatdhanaiPython/ThaiLLM-30B-NVFP4 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 "NatdhanaiPython/ThaiLLM-30B-NVFP4" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NatdhanaiPython/ThaiLLM-30B-NVFP4", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "NatdhanaiPython/ThaiLLM-30B-NVFP4" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NatdhanaiPython/ThaiLLM-30B-NVFP4", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use NatdhanaiPython/ThaiLLM-30B-NVFP4 with Docker Model Runner:
docker model run hf.co/NatdhanaiPython/ThaiLLM-30B-NVFP4
| license: apache-2.0 | |
| language: | |
| - th | |
| - en | |
| base_model: ThaiLLM/ThaiLLM-30B | |
| base_model_relation: quantized | |
| pipeline_tag: text-generation | |
| library_name: transformers | |
| tags: | |
| - nvfp4 | |
| - fp4 | |
| - modelopt | |
| - quantized | |
| - vllm | |
| - thai | |
| - qwen3_moe | |
| - dgx-spark | |
| - agicafet | |
| <p align="center"> | |
| <b>AGIcafet Research</b> Β· <a href="https://thaillm.agicafet.com">interactive report</a> Β· <a href="https://github.com/spped2000/thaillm-nvfp4-dgx-spark">full pipeline & results</a> | |
| </p> | |
| # ThaiLLM-30B-NVFP4 | |
| **NVFP4 (4-bit) quantization of [ThaiLLM/ThaiLLM-30B](https://huggingface.co/ThaiLLM/ThaiLLM-30B)** β the Thai/English continued-pretrain of Qwen3-30B-A3B (MoE, 31B total / ~3.3B active) β produced with NVIDIA TensorRT Model Optimizer 0.43.0 and validated with a rigorous paired BF16-vs-NVFP4 evaluation on an NVIDIA DGX Spark (GB10). | |
| - **18.1 GB** (from 61.1 GB BF16 β 3.4Γ smaller); 16.9 GiB GPU-resident | |
| - **2.3β2.5Γ faster decode** on DGX Spark (27 β 63 tok/s single-stream, 69 β 175 tok/s at 4 streams), TTFT 2.0β2.7Γ lower | |
| - **Thai capability statistically unchanged** (paired McNemar tests over identical questions) | |
| - W4A4 NVFP4 (E2M1 + FP8 block scales, group 16): attention **and** all 128 experts/layer quantized; router gates + `lm_head` kept BF16; **KV cache not quantized** | |
| - Calibration: **256 Thai Wikipedia + 256 English news documents** (512Γ512 tokens) β half-Thai calibration per multilingual-quantization best practice | |
| - β οΈ Like the base model, this is a **base (non-instruct) model** β fine-tune before use as an assistant | |
| ## Serving | |
| ```bash | |
| # vLLM (Blackwell GPU, e.g. DGX Spark with nvcr.io/nvidia/vllm:26.05.post1-py3) | |
| vllm serve NatdhanaiPython/ThaiLLM-30B-NVFP4 \ | |
| --quantization modelopt \ | |
| --gpu-memory-utilization 0.70 \ | |
| --attention-backend flashinfer | |
| # vLLM auto-selects native FLASHINFER_CUTLASS NVFP4 MoE kernels on SM121/SM100. | |
| # For extra KV headroom in production add: --kv-cache-dtype fp8 | |
| ``` | |
| ## Benchmarks (paired BF16 vs NVFP4, identical questions, seed 0) | |
| | Benchmark (n) | BF16 | NVFP4 | Ξ (pt) | Paired p | Verdict | | |
| |---|---|---|---|---|---| | |
| | **ThaiExam** (letter MC, 565) | 0.6195 | 0.6142 | β0.53 | 0.79 | not significant | | |
| | **Belebele-TH** (900) | 0.7700 | 0.7656 | β0.44 | β | noise | | |
| | **XCOPA-TH** (500) | 0.6400 | 0.6340 | β0.60 | β | noise | | |
| | **XNLI-TH** (2,490) | 0.4707 | 0.4578 | β1.29 | β | β€1.3Ο | | |
| | Thai MC pooled (3,890) | β | β | β1.00 | 0.13 | **not significant** | | |
| | MMLU 5-shot @50/subj (2,850) | 0.8168 | 0.8028 | β1.40 | 0.0017 | significant | | |
| | HellaSwag (10,042) | 0.6003 | 0.5941 | β0.62 | <0.001 | significant, small | | |
| | ARC-Challenge (1,172) | 0.5614 | 0.5597 | β0.17 | β | noise | | |
| | WinoGrande (1,267) | 0.7395 | 0.7285 | β1.10 | β | β€0.9Ο | | |
| | **All MC pooled (19,786)** | β | β | **β0.81** | <1e-4 | significant, small | | |
| | Fidelity / LM quality | BF16 | NVFP4 | | |
| |---|---|---| | |
| | Thai Wikipedia bits/byte β | 0.2680 | 0.2822 | | |
| | WikiText-2 bits/byte β | 0.5660 | 0.5819 | | |
| | Thai top-1 next-token agreement | β | 92.0 % (32,424 positions) | | |
| | English top-1 agreement | β | 88.1 % (13,848 positions) | | |
| **Interpretation.** Pooled over 19,786 paired questions (ThaiExam counted once, via the letter-based template) the quantization cost is real but under one accuracy point, and it concentrates on English reasoning tails β **no Thai task degrades significantly**. A Thai-fluent 12-domain qualitative review found no systematic degradation (orthography intact, no new repetition behavior); the one caution is verbatim quotation (e.g., legal statutes), where 4-bit weights can paraphrase β use retrieval grounding or BF16 for citation-critical work. | |
| ### DGX Spark performance (vllm bench serve, median of 3, no speculative decoding) | |
| | Workload | BF16 | NVFP4 | Speedup | | |
| |---|---|---|---| | |
| | 1K in / 128 out, 1 stream | 27.1 tok/s | 63.1 tok/s | 2.33Γ | | |
| | 1K in / 128 out, 4 streams | 59.6 tok/s | 145.4 tok/s | 2.44Γ | | |
| | 128 in / 1K out, 4 streams | 69.4 tok/s | 174.8 tok/s | 2.52Γ | | |
| | TTFT p50 (1K prompt) | 326 ms | 140 ms | 2.32Γ | | |
| | Model load | 365 s | 109 s | 3.34Γ | | |
| ### Thai context vs other local models (same protocol) | |
| | Model | Belebele-TH | ThaiExam | Thai bits/byte β | | |
| |---|---|---|---| | |
| | **ThaiLLM-30B NVFP4 (this repo)** | 0.766 | 0.614 | 0.286 | | |
| | ThaiLLM-30B BF16 | 0.770 | 0.619 | 0.273 | | |
| | Typhoon2.5-30B-A3B (instruct) | 0.856 | 0.604 | 0.480 | | |
| | SEA-LION v4.5-27B (instruct) | 0.843 | 0.619 | 0.591 | | |
| | Qwen3.6-27B NVFP4 (instruct) | 0.876 | 0.658 | 0.296 | | |
| ## How it was made | |
| ```bash | |
| # TensorRT Model Optimizer 0.43.0, examples/llm_ptq/hf_ptq.py | |
| python hf_ptq.py --pyt_ckpt_path ThaiLLM/ThaiLLM-30B \ | |
| --qformat nvfp4 --kv_cache_qformat none \ | |
| --calib_size 512 --calib_seq 512 --batch_size 0 \ | |
| --dataset thai_en_calib.jsonl \ | |
| --export_path ThaiLLM-30B-NVFP4 | |
| ``` | |
| Full reproducible pipeline (calibration builder, fairness-protocol eval scripts, custom letter-scored ThaiExam lm-eval tasks, paired statistics, complete technical report): **[github.com/spped2000/thaillm-nvfp4-dgx-spark](https://github.com/spped2000/thaillm-nvfp4-dgx-spark)** | |
| ## Roadmap β planned next phases | |
| 1. **Draft-model speculative decoding**: this base has no MTP head, but a same-tokenizer drafter (e.g. Qwen3-0.6B) is expected to add ~1.3β1.6Γ decode speed losslessly (63 β ~80β100 tok/s on DGX Spark). | |
| 2. **Thai instruction SFT** on the BF16 base β re-quantize with the same recipe β re-run the eval gate. | |
| 3. **EAGLE-3 head training** post-SFT (~1.5β2Γ additional). | |
| 4. **FP8 KV cache** in production (`--kv-cache-dtype fp8`) β disabled in this study only for measurement isolation. | |
| ## Limitations | |
| - Base model: requires instruction fine-tuning before assistant use (the recommended production flow is SFT the BF16 base β re-quantize with this recipe β re-run the eval gate). | |
| - Evaluated with automatic metrics + a 12-domain expert review; no large-scale human evaluation. | |
| - Serving requires NVFP4-capable hardware (NVIDIA Blackwell) for the measured speedups. | |
| ## Attribution | |
| Base model by the [ThaiLLM](https://huggingface.co/ThaiLLM) project (Apache-2.0). Quantization, evaluation, and release by **[AGIcafet](https://agicafet.com)**, 15 July 2026. | |