Instructions to use batteryphil/Inkling-2-Mini-PRIME-Quant with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use batteryphil/Inkling-2-Mini-PRIME-Quant with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="batteryphil/Inkling-2-Mini-PRIME-Quant") 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("batteryphil/Inkling-2-Mini-PRIME-Quant") model = AutoModelForMultimodalLM.from_pretrained("batteryphil/Inkling-2-Mini-PRIME-Quant", 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 batteryphil/Inkling-2-Mini-PRIME-Quant with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "batteryphil/Inkling-2-Mini-PRIME-Quant" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "batteryphil/Inkling-2-Mini-PRIME-Quant", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/batteryphil/Inkling-2-Mini-PRIME-Quant
- SGLang
How to use batteryphil/Inkling-2-Mini-PRIME-Quant 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 "batteryphil/Inkling-2-Mini-PRIME-Quant" \ --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": "batteryphil/Inkling-2-Mini-PRIME-Quant", "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 "batteryphil/Inkling-2-Mini-PRIME-Quant" \ --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": "batteryphil/Inkling-2-Mini-PRIME-Quant", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use batteryphil/Inkling-2-Mini-PRIME-Quant with Docker Model Runner:
docker model run hf.co/batteryphil/Inkling-2-Mini-PRIME-Quant
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoProcessor, AutoModelForMultimodalLM
processor = AutoProcessor.from_pretrained("batteryphil/Inkling-2-Mini-PRIME-Quant")
model = AutoModelForMultimodalLM.from_pretrained("batteryphil/Inkling-2-Mini-PRIME-Quant", 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]:]))- Inkling-2-Mini β PRIME-Quant (
8.83 GBAll-2-Bit MoE &10.87 GBloop_top8P2/P4 Hybrid)- 1. Included Checkpoints & Headline Benchmarks
- 2. Full 5-Domain KL-Divergence & Perplexity Evaluation
- 3. Adversarial Coding Arena:
PRIME-Quant loop_top8(10.87 GB) vs Unquantized OfficialBF16(52.8 GB) - 4. Kernel & Runtime Engineering Highlights (
52β56 tok/son RX 9060 XT) - 5. Quick Start (Run Locally on a 12 GB or 16 GB GPU)
- 6. Licensing & Attribution
Inkling-2-Mini β PRIME-Quant (8.83 GB All-2-Bit MoE & 10.87 GB loop_top8 P2/P4 Hybrid)
Run Thinking Machines' 26.4B 3-Pass Looped MoE (Inkling-2-Mini) 100% resident on a single 12 GB or 16 GB consumer GPU at 52β56 tok/s β zero CPU offload, up to 16K context on 16 GB VRAM.
Upstream thinkingmachines/Inkling-2-Mini ships as a 20.16 GB NVFP4+MXFP8 checkpoint (52.8 GB BF16-dequantized) with 32 GB+ VRAM recommended. PRIME-Quant compresses 99.85% (26.35B / 26.39B) of its parameters using signed-scale Prime-Harmonic 2-bit (P2_G32, 2.50 bpw) and 4-bit (P4_G32, 4.50 bpw) codebooks paired with a pure-Triton fused decode runtime and single HIP/CUDA-graph execution engine.
1. Included Checkpoints & Headline Benchmarks
All speeds and VRAM numbers below were measured end-to-end on a single AMD Radeon RX 9060 XT (16 GB GDDR6, 320 GB/s, gfx1200 RDNA4, ROCm 7.2 / PyTorch 2.14) β and the bundled Triton runtime also runs on NVIDIA CUDA GPUs.
| Model / Checkpoint | Disk & Resident VRAM | Compression vs BF16 | Mean KLD (1,849 toks) |
PPL (ref = 2.1416) |
Top-1 Agree (All / Python / C++) | Decode (4K / 16K ctx) |
Fits 100% On |
|---|---|---|---|---|---|---|---|
Official Unquantized BF16 (24-core Xeon + GPU hybrid) |
52.8 GB (12.1G GPU + 40.7G RAM) |
1.00Γ |
0.0000 |
2.1416 |
100% |
2.62 tok/s (offloaded) |
64 GB+ |
Official NVFP4+MXFP8 (Blackwell / DGX Spark) |
20.16 GB |
2.62Γ |
β | β | β | OOM on 16 GB | 24β32 GB+ |
inkling2_mini_p2_looptop8.safetensors β Recommended |
10.87 GB |
4.86Γ |
0.0542 |
2.1542 (+0.0059 loss) |
93.35% / 97.50% / 97.61% |
54.22 / 48.60 tok/s |
16 GB GPUs (up to 16K ctx) |
inkling2_mini_p2_maxcomp.safetensors (Max Compression) |
8.83 GB |
5.98Γ |
0.1138 |
2.2143 (+0.0334 loss) |
91.35% / 95.39% / 96.90% |
56.23 tok/s (4K) |
12 GB & 16 GB GPUs |
Why loop_top8 (10.87 GB) Hits Such Low 2-Bit KL Divergence (0.0542)
Inkling-2-Mini has 24 physical transformer layers where the middle 12 layers (L6..17) execute 3 looped passes per token (48 logical layer applications). Quantization error in looped layers compounds 3Γ per token:
maxcomp(8.83 GB): All 24 MoE expert banks (128experts Γ24layers) are compressed toP2_G32(2.50 bpw), while attention projections, embeddings,lm_head, and the 23-layer ViT useP4_G32(4.50 bpw).loop_top8(10.87 GB): Promotes only the top-8 highest-sensitivity looped/boundary MoE layers (L5, L8, L9, L11, L12, L14, L15, L16) fromP2_G32toP4_G32, leaving the other 16 MoE expert banks at 2-bitP2_G32. That cuts mean KL divergence in half (0.1138 β 0.0542, Python KLD0.0409 β 0.0217, Top-1 coding agreement97.5%β97.6%) for just+2.04 GBVRAM and only-3.6%decode throughput.- Exact Parameter Coverage:
99.85%(26.35B / 26.39B) of parameters are quantized (P2_G32orP4_G32). Only0.15%(40.2Mparams =124.6 MB) remains BF16/FP32 by design: rank-64 loopedmessage_gate(84.9 MB), MoE routers (28.3 MB), and per-head sink / relative-position / 4-tap short-conv / Attention-Residual / RMSNorm parameters (11.4 MB).
2. Full 5-Domain KL-Divergence & Perplexity Evaluation
Evaluated over 1,849 held-out tokens across 5 technical domains directly against exact unquantized BF16 reference log-probabilities (benchmarks/kld_looptop8.json, benchmarks/kld_p2_maxcomp.json):
Domain (n_tokens) |
BF16 Ref PPL | maxcomp (8.83 GB) PPL / KLD / Top-1 |
loop_top8 (10.87 GB) PPL / KLD / Top-1 |
|---|---|---|---|
python_code (521) |
1.3042 |
1.3034 / 0.0409 / 95.39% |
1.3190 / 0.0217 / 97.50% |
systems_cpp (419) |
1.2216 |
1.2724 / 0.0337 / 96.90% |
1.2525 / 0.0181 / 97.61% |
math_reasoning (390) |
1.7601 |
1.9600 / 0.1382 / 91.03% |
1.8209 / 0.0437 / 93.59% |
technical_prose (216) |
6.9495 |
8.3906 / 0.2283 / 77.31% |
7.6525 / 0.1021 / 83.33% |
inkling_chat_tool (303) |
6.0739 |
5.3638 / 0.2372 / 87.13% |
5.3300 / 0.1395 / 87.13% |
Overall (1,849 tokens) |
2.1416 |
2.2143 / 0.1138 / 91.35% |
2.1542 / 0.0542 / 93.35% |
Per-layer MoE weight SNR (benchmarks/inkling2_looptop8_report.json): 10.04β10.12 dB on 2-bit P2_G32 layers, 23.80β23.89 dB on 4-bit P4_G32 layers (14.68 dB / 14.65 dB mean across all 24 gate_up / down expert banks).
3. Adversarial Coding Arena: PRIME-Quant loop_top8 (10.87 GB) vs Unquantized Official BF16 (52.8 GB)
To test real multi-step software engineering beyond perplexity, we ran both checkpoints head-to-head on a 2-module, 15-test adversarial reactive spreadsheet compiler + DAG engine (benchmarks/test_spreadsheet_engine.py):
- Stage A (
formula_parser.py, 6 tests): Noeval/exec, multi-letter reversed 2D ranges (AB2:Z1), exact precedence (2^3^2 == 512,-2^2 == -4,2^-3 == 0.125,--5 + +-3 == 2), non-chaining comparisons, strict short-circuitIF(), and empty-vs-explicit-zero aggregate semantics. - Stage B (
spreadsheet_engine.py, 15 tests): Iterative 3-color DFS cycle detection & transactional rollback (including cycles hidden inside 2D ranges), atomicbatch_updatedependency swaps (A1 β B1), error propagation & self-healing, and incremental Kahn topological recalculation over a 40-layer diamond DAG (2^40paths) alongside 1,000 unrelated cells in< 0.2s.
A. Apples-to-Apples Head-to-Head (max_new_tokens=4500, temp=1.0, top_p=1.0, identical prompts & seeds 701β703)
| Metric | PRIME-Quant loop_top8 (10.87 GB) |
Official Unquantized BF16 (52.8 GB) |
Delta |
|---|---|---|---|
| Memory Footprint | 10.87 GB VRAM (100% GPU) |
52.8 GB (12.09G VRAM + 40.7G RAM) |
4.86Γ smaller |
Load Time (meta β GPU) |
7.6 s |
75.8 s |
10.0Γ faster |
| Decode Speed | 46.9 β 49.3 tok/s |
2.57 β 2.62 tok/s (24-core Xeon + GPU) |
18.6Γ faster |
| Stage A Iter 1 | 4/6 (266 lines, 1.7 min) |
3/6 (310 lines, 29.3 min) |
PRIME-Quant |
| Stage A Iter 2 | 0/6 (truncated mid-_eval) |
0/6 (truncated mid-_eval) |
Same native truncation |
| Stage A Iter 3 | 6/6 PASS (230 lines, 4,290 toks) |
4/6 FAIL (334 lines, trunc @ 4,500) |
PRIME-Quant (+2) |
| Stage A Wall Time | 5.3 min (3 iters) |
92.5 min (3 iters) |
17.4Γ faster |
| Stage B (Full 15-Test DAG) | 14/15 PASS (93.3%) (8.4 min, 4 iters) |
Stopped after Stage A | PRIME-Quant |
(Honest engineering audit: Both models exhibited the exact same native Inkling-2-Mini verbosity ceiling at 4,500 tokens β Inkling-2's tokenizer encodes Python at 2.64β2.87 chars/tok (~11.5β14.7 tok/line), so a 340-line class-based module plus 4,990900 thinking tokens requires `tokens. In Stage B,loop_top8passed the 40-layer diamond DAG, 1,000-cell incremental perf check, 2D-range cycle rollback, and atomicbatch_updateswap, missing onlytest_08due to an eager upstream-error check before short-circuitIF. Generated outputs are included verbatim in benchmarks/formula_parser_looptop8.pyandbenchmarks/spreadsheet_engine_looptop8.py`.)
B. Fixed 16K-Context / 8,192-Token Guard Run (run_inkling2_prime.py)
After upgrading Inkling2GraphEngine with 16K chunked-prefill KV cache, graceful sentence-boundary thinking wrap-up, --min-answer-tokens, and post-answer duplicate-rewrite prevention:
- Truncation rate dropped to
0%(6/6turns hitfinish_reason='stop'cleanly) across Stage A & Stage B. - Stage A solved
6/6on Iteration 2 (335-line full class-based AST in4,381tokens, saved inbenchmarks/formula_parser_v2_16k.py). - Peak VRAM at
ctx=16384:12.08β15.67 GB(100% resident on 16 GB RX 9060 XT) at46.8β49.2 tok/s.
4. Kernel & Runtime Engineering Highlights (52β56 tok/s on RX 9060 XT)
The bundled read-only inference runtime (prime_infer_runtime.py, inkling2_kernels.py, run_inkling2_prime.py) achieves near-bandwidth-limit speed on consumer GPUs:
- L0-cached 4-float LUT 2-bit
P2_G32GEMV & MoE kernels:300.7 GB/sachieved out of320 GB/stheoretical peak on RDNA4 (~94%hardware bandwidth utilization). - Parallel-K FP32 MoE
down_proj+ weighted reduction (BLOCK_R=4, GROUPS_K=4) and fusedgate_up + SoftcappedSwiGLUactivation (1.54Γfaster than 2-pass). - Fused Triton Inkling-2 decode ops for all 48 looped passes: 4-tap static & dynamic short convolutions (
192calls/tok), rank-64message_gate(96calls/tok), single-passAttnRes(120calls/tok), single-CTArouter_topk(4.25Γfaster),unweighted_rmsnorm(8.06Γfaster), and ring-buffer GQA + RelativePositionBias + Per-Head Sink decode attention (48calls/tok). - Chunked prefill attention (
Q_CHUNK=128) & chunkedAttnRes(T=512): cuts 12Kβ16K prefill activation VRAM by ~80Γ (2+ GB β ~25 MB), enabling16Kcontext on 16 GB VRAM. - Single-HIP/CUDA-Graph replay verified bit-exact (
24/24greedy token parity vs eagermodel.generate()) and backed by a 23/23 passing parity test suite.
5. Quick Start (Run Locally on a 12 GB or 16 GB GPU)
Install Dependencies
pip install -r requirements.txt
# Note: Inkling-2-Mini requires transformers >= 5.24.0 (or current transformers main)
Download This Repository
huggingface-cli download batteryphil/Inkling-2-Mini-PRIME-Quant --local-dir ./Inkling-2-Mini-PRIME-Quant
cd ./Inkling-2-Mini-PRIME-Quant
Run Interactive Chat or Coding Prompts (10.87 GB loop_top8 β Default)
# On AMD ROCm (RX 9060 XT / RDNA3 / RDNA4):
TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1 python run_inkling2_prime.py \
--checkpoint ./inkling2_mini_p2_looptop8.safetensors \
--max-cache-len 16384 --max-new-tokens 8192 --max-thinking-tokens 900 \
--interactive
# On NVIDIA CUDA (16 GB RTX 4060 Ti / 4080 / 5060 Ti / 5080):
python run_inkling2_prime.py \
--checkpoint ./inkling2_mini_p2_looptop8.safetensors \
--max-cache-len 16384 --max-new-tokens 8192 --max-thinking-tokens 900 \
--interactive
Run on a 12 GB GPU (8.83 GB maxcomp All-2-Bit MoE, 56.2 tok/s)
python run_inkling2_prime.py \
--checkpoint ./inkling2_mini_p2_maxcomp.safetensors \
--max-cache-len 4096 --max-new-tokens 2048 --max-thinking-tokens 600 \
--prompt "Write a concise Python LRU cache with O(1) get and put."
Recommended Sampling Settings
- Follow official Thinking Machines defaults:
--temperature 1.0 --top-p 1.0 --top-k 0 --min-p 0.0(avoid low temperatures< 0.6on reasoning prompts to prevent CoT repetition loops). - For long coding generations (>250 lines): Use
--max-cache-len 16384 --max-new-tokens 8192 --max-thinking-tokens 900 --min-answer-tokens 6000so Inkling-2's tokenizer has full answer runway without truncating mid-function.
6. Licensing & Attribution
- Original PRIME-Quant Codecs, Triton Kernels, Inference Runtime, and Compressed Checkpoint Layouts: Copyright (c) 2026 Philip Bartsch (
@batteryphil). Licensed under the Bartsch Personal-Free & 5% Commercial Profit-Share License v1.0 β free (0% royalty) for personal, hobbyist, academic, and non-profit use; 5% net profit share (or optional flat-fee buyout) for commercial deployments. - Upstream Base Weights (
thinkingmachines/Inkling-2-Mini): Authored by Thinking Machines Lab, Inc. under the Apache License 2.0 (seeNOTICE).
(Note: This repository contains the quantized weights, benchmarks, and a minimal read-only inference runtime. The full PRIME-Quant quantization, Schur-GPTQ, Shadowless PRIMAL distillation, and scratch-training suite remains in the author's private research repository.)
- Downloads last month
- -
Model tree for batteryphil/Inkling-2-Mini-PRIME-Quant
Base model
thinkingmachines/Inkling-2-Mini
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="batteryphil/Inkling-2-Mini-PRIME-Quant") 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)