Text Generation
Transformers
English
multilingual
inkling2_loop
image-text-to-text
prime-quant
2-bit
4-bit precision
Mixture of Experts
inkling-2
inkling-2-mini
looped-transformer
triton
rocm
cuda
quantization
coding
conversational
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
Add model card, Bartsch LICENSE, Apache-2.0 NOTICE, tokenizer, standalone read-only Triton runtime & verified benchmarks
53ce2f5 verified |
Download README.md from batteryphil/Inkling-2-Mini-PRIME-Quant: direct link, hf CLI and curl.
- Browser
- Download file 12.8 kB
-
https://huggingface.co/batteryphil/Inkling-2-Mini-PRIME-Quant/resolve/main/README.md
- Command line
-
hf download hf://batteryphil/Inkling-2-Mini-PRIME-Quant/README.md
-
curl -L -o README.md https://huggingface.co/batteryphil/Inkling-2-Mini-PRIME-Quant/resolve/main/README.md
12.8 kB
| license: other | |
| license_name: bartsch-personal-free-5pct-commercial | |
| license_link: LICENSE | |
| base_model: thinkingmachines/Inkling-2-Mini | |
| base_model_relation: quantized | |
| library_name: transformers | |
| pipeline_tag: text-generation | |
| language: | |
| - en | |
| - multilingual | |
| tags: | |
| - prime-quant | |
| - 2-bit | |
| - 4-bit | |
| - moe | |
| - inkling-2 | |
| - inkling-2-mini | |
| - looped-transformer | |
| - triton | |
| - rocm | |
| - cuda | |
| - quantization | |
| - coding | |
| # 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`](https://huggingface.co/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 (`128` experts × `24` layers) are compressed to **`P2_G32` (`2.50 bpw`)**, while attention projections, embeddings, `lm_head`, and the 23-layer ViT use **`P4_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`)** from `P2_G32` to `P4_G32`, leaving the other **16 MoE expert banks at 2-bit `P2_G32`**. That cuts mean KL divergence **in half** (`0.1138 → 0.0542`, Python KLD `0.0409 → 0.0217`, Top-1 coding agreement **`97.5%–97.6%`**) for just `+2.04 GB` VRAM and only `-3.6%` decode throughput. | |
| - **Exact Parameter Coverage:** **`99.85%`** (`26.35B / 26.39B`) of parameters are quantized (`P2_G32` or `P4_G32`). Only **`0.15%`** (`40.2M` params = `124.6 MB`) remains BF16/FP32 by design: rank-64 looped `message_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):** No `eval`/`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-circuit `IF()`, 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), atomic `batch_update` dependency swaps (`A1 ↔ B1`), error propagation & self-healing, and incremental Kahn topological recalculation over a **40-layer diamond DAG (`2^40` paths) 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 `900` thinking tokens requires `~4,990` tokens. In Stage B, `loop_top8` passed the 40-layer diamond DAG, 1,000-cell incremental perf check, 2D-range cycle rollback, and atomic `batch_update` swap, missing only `test_08` due to an eager upstream-error check before short-circuit `IF`. Generated outputs are included verbatim in `benchmarks/formula_parser_looptop8.py` and `benchmarks/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/6` turns hit `finish_reason='stop'` cleanly)** across Stage A & Stage B. | |
| - **Stage A solved `6/6` on Iteration 2** (335-line full class-based AST in `4,381` tokens, saved in `benchmarks/formula_parser_v2_16k.py`). | |
| - **Peak VRAM at `ctx=16384`:** `12.08–15.67 GB` (**100% resident on 16 GB RX 9060 XT**) at **`46.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_G32` GEMV & MoE kernels:** `300.7 GB/s` achieved out of `320 GB/s` theoretical peak on RDNA4 (`~94%` hardware bandwidth utilization). | |
| - **Parallel-K FP32 MoE `down_proj` + weighted reduction (`BLOCK_R=4, GROUPS_K=4`)** and fused `gate_up + SoftcappedSwiGLU` activation (`1.54×` faster than 2-pass). | |
| - **Fused Triton Inkling-2 decode ops** for all 48 looped passes: 4-tap static & dynamic short convolutions (`192` calls/tok), rank-64 `message_gate` (`96` calls/tok), single-pass `AttnRes` (`120` calls/tok), single-CTA `router_topk` (`4.25×` faster), `unweighted_rmsnorm` (`8.06×` faster), and ring-buffer GQA + RelativePositionBias + Per-Head Sink decode attention (`48` calls/tok). | |
| - **Chunked prefill attention (`Q_CHUNK=128`) & chunked `AttnRes` (`T=512`):** cuts 12K–16K prefill activation VRAM by ~80× (`2+ GB → ~25 MB`), enabling `16K` context on 16 GB VRAM. | |
| - **Single-HIP/CUDA-Graph replay** verified bit-exact (`24/24` greedy token parity vs eager `model.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 | |
| ```bash | |
| pip install -r requirements.txt | |
| # Note: Inkling-2-Mini requires transformers >= 5.24.0 (or current transformers main) | |
| ``` | |
| ### Download This Repository | |
| ```bash | |
| 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) | |
| ```bash | |
| # 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`) | |
| ```bash | |
| 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.6` on 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 6000` so 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](LICENSE)** — **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** (see [`NOTICE`](NOTICE)). | |
| *(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.)* | |