squid5090 - one graphics card, 545 tokens per second, vision, no python
squid5090 is a single Zig + CUDA binary, with zero Python at runtime, that serves Inkling-2-Mini (text and native vision) on one RTX 5090. It started at 76 tok/s (exact, B=1) and now runs at 316–545 tok/s in the accuracy-first FP8 default (0.0059–0.0093 long-context KLD, ΔPPL −0.0068 to +0.0056, 17.5–17.7K tok/s live HTTP cold prefill, 4.4 ms native 23-layer BF16 vision, 512K + vision in 22.9 GiB) — and up to 398 tok/s greedy chat, 508 tok/s copy, or 1,048,576 tokens of context in opt-in NVFP4.
The second half covers runtime-gated abliteration: suppressing refusals with a 1.8 MB Fisher-LDA sidecar without modifying any model weights, leaving 53/53 tested harmless chat prompts bit-for-bit identical.
Attribution: Key Blackwell kernel techniques (PDL overlap, 16-CTA cluster DSMEM/part 1 — inferencembarriercontrollers & single-pass router, single-barrierwarp_reduce_scatter/block_sum_bcast, 1-launch cluster decode attention, coalesced 128B-sectoruint4MXFP8 BF16 Tensor Core MoE decode, spill-free 16-colU=3FP8/NVFP4mma.m16n8k16GEMVs & LM-head, 128-CTA stochastic sampling, Top-K1024radix Markov drafting with an embedded corpus-frequency 32K shortlist,128×128×64MoE prefill,{2, 4, 8}CUDA Graph switch drafting, the native 23-layer BF16 Vision Tower) and the 1.8 MB runtime-gated Fisher-LDA abliteration format were adapted from satellitedown/inkling-2-mini-abliterated-ingine (Apache-2.0). Image decoding uses vendoredstb_image.h(MIT/Public Domain) and optionallibwebp(BSD-3-Clause). Opt-in prompt-lookup drafting was inspired by AtomicBot-ai/atomic-engine (MIT), and the roofline workflow follows sybil-solutions/inference-optimisation-skill.
why inference is slow — and how we made it up to 8× faster
prefill vs decode: compute vs memory bandwidth
On an RTX 5090, model weights live in VRAM and math runs on the Tensor Cores. Between them sits a single bottleneck: memory bandwidth, measured at 1,513 GB/s on this card. The two phases of LLM inference stress completely different sides of that hardware:
- Prefill (reading the prompt): A 20,000-token prompt loads each weight matrix from VRAM once and reuses it across all 20,000 tokens in parallel. Tensor Cores stay saturated (~100% busy, up to 20,007 tok/s chunk peak). Prefill is compute-bound.
- Decode (generating the reply): Tokens are generated one at a time because each token depends on the previous one. Every single token requires streaming 2.8–3.7 GB of weights from VRAM, performing one multiply-add per weight, and discarding them while ~90% of the Tensor Cores sit idle. Decode is memory-bandwidth-bound.
Every decode optimization comes down to two levers: move fewer bytes per token, or produce more tokens per weight pass.
in decode, each token streams billions of weights from VRAM once and leaves ~90% of Tensor Cores idle. switch to prefill to see one weight pass reused across 20,000 tokens.
step 1: measure bandwidth first
Following inference-optimisation-skill, the first step was measuring actual device read bandwidth (1,513 GB/s, not the spec sheet) and dividing by the weight bytes touched per token.
That ratio is the hardware ceiling. At 30% of ceiling, you are losing time to launch overhead or poor memory access patterns. At 80–99% of ceiling, kernel micro-tuning has almost nothing left to give — you have to reduce bytes per token or verify multiple tokens per weight pass.
step 2: cut launch overhead (zig, cuda graphs, clusters, pdl)
Eager execution dispatches ~600 separate CUDA kernels per token from the CPU. Even a few microseconds of launch latency per kernel adds up fast, especially through Python.
- Zig + CUDA Graphs + 1-Launch Clusters: We replaced Python with a single ~20 MiB compiled Zig binary (BPE tokenizer, runtime, vision encoder, HTTP/SSE server) and captured the decode step into a CUDA Graph so the CPU issues one
cudaGraphLaunchper token. Using Blackwell Thread Block Clusters (DSMEM+mbarrier), we collapsed 4-launch controllers, 2-launch routers, and 4-launch decode attention down to 1 launch each (with single-barrierwarp_reduce_scatter/block_sum_bcastand CUDA 13.4+L2::evict_firststreaming hints so single-use weights don't evict KV cache from L2). - Blackwell PDL (Programmatic Dependent Launch): On sm_120a, kernel N+1 can begin loading weights while kernel N finishes its compute tail, eliminating inter-kernel idle gaps while 16-CTA clusters exchange partial sums directly through distributed shared memory instead of VRAM.
pdl overlaps the next kernel's weight loads with the previous kernel's compute tail, removing idle gaps between stages.
step 3: selective quantization, 4.4 ms vision & 1M context
Shrinking weight formats raises the bandwidth ceiling, but quantizing every layer to 4 bits degrades output quality. We evaluated exact FP64 KL divergence against the unmodified exact/bf16 reference over 7,784 tokens (7.6× past the 1,024-token local window, exercising all 8 global KV layers) and settled on two precision tiers:
- Accuracy-First Default (
--mode fp8,17.11 GiBtext /17.71 GiB+ Vision): Keeps all 24 MoE expert layers in official checkpoint precision (L0–19 native NVFP4 + L20–23 native MXFP8 via coalesced 128B-sectoruint4BF16 Tensor Core MMA, zero re-quantization) and keeps routers and controllers in BF16 inside single-pass 16-CTA cluster kernels. Only dense attention andlm_headmove from BF16 to FP8 E4M3 (3.69 GB/tok) on spill-free 16-columnU=3mma.m16n8k16. That yields0.0059KLD (fp8/fp8,ΔPPL −0.0068, 29/30 30-task reasoning) or0.0093KLD (fp8/q4,ΔPPL +0.0056) at 316–545 tok/s live HTTP. - Opt-In Max-Speed / 1M (
--mode nvfp4,14.66 GiBtext /15.26 GiB+ Vision): Quantizes dense attention,lm_head, and L20–23 experts to native 4-bit NVFP4 (2.80 GB/tok), reaching 398.2 tok/s greedy chat and 324.9 tok/sT=1.0prose while fitting 1,048,576 tokens in23.5 GiB(0.0267KLD,ΔPPL +0.0520). - Native 23-Layer BF16 Vision (
4.4 msencode,0.0 msmulti-turn cache):squid5090 serveloads Inkling-2-Mini's 23-layer BF16 Vision Transformer (~609 MiBinside the single weight arena; pass--no-visionto reclaim it). PNG/JPEG/GIF/BMP/WebP decoding runs natively in C++, composites transparent images onto an 8×8 grey checkerboard, downscales to40×40visual tiles, and encodes in ~4.4 ms on Tensor Cores. Each image is assigned content-addressed negative synthetic token IDs (SplitMix64over final RGB pixels), so follow-up turns about the same image hit the prefix cache in 0.0 ms. - 512K–1M Context (
Q4 KV) & 72 ms Prefix Cache: Of the 48 logical layer visits, 40 use a fixed 1,024-token local sliding window (small BF16 ring buffer) and only 8 global visits store full context (40 + 8 = 48). Quantizing those 8 global KV caches toQ4fits 512K + Vision in22.9 GiB(fp8/q4, verified with verbatim needle-in-a-haystack recall at 64K, 128K, 256K, and 512K) or 1,048,576 tokens in23.5 GiB(nvfp4/q4). Local state snapshots to host RAM after HTTP[DONE](0extra VRAM), so Turn 2 of a 16K–82.5K session resumes in 62–72 ms.
| mode | 7.8K KLD | Top-1 | ΔPPL | Code (T=0/1) | Copy (T=0/1) | 18.9K Prefill |
|---|---|---|---|---|---|---|
exact/bf16 | 0.0000 | 100.0% | +0.0000 | 246.7 / 225.2 | 419.2 / 237.2 | 9,875 tok/s |
fp8/fp8 | 0.0059 | 97.4% | −0.0068 | 425.6 / 442.5 | 545.1 / 477.5 | 17,741 tok/s |
fp8/q4 | 0.0093 | 96.7% | +0.0056 | 412.4 / 460.3 | 540.5 / 519.4 | 17,476 tok/s |
nvfp4/q4 | 0.0267 | 94.6% | +0.0520 | 425.2 / 424.6 | 508.4 / 490.9 | 14,758 tok/s |
only the 8 highlighted global visits grow with conversation length — the other 40 stay locked to a 1,024-token ring buffer. switch to nvfp4 / q4 and click 1M to see 1,048,576 tokens + Vision fit with ~8 GiB left over.
step 4: speculative decoding (verify 8 tokens in one pass)
After Steps 1–3 (plus CUDA 13.4 L2::evict_first and coalesced uint4 MXFP8 MoE), single-token decode hits 279.3 tok/s CLI in fp8/fp8. Reaching 425–545 tok/s live HTTP uses the ~90% idle Tensor Cores: verifying 8 tokens in parallel reads the dense weights and LM head from VRAM once, so checking 8 candidate tokens costs nearly the same time as generating 1.
- FP8 DSpark + Embedded 32K Shortlist (~0.24 ms on GPU): Inkling-2-Mini includes a 3-layer neural drafter running in FP8 Tensor Core MMA with a 4-stage multi-CTA radix Top-K
1024selector and full-vocab BF16 Markov head. Replacing a naive0..32699token table (which missed 84.4% of frequent tokens) with an embedded corpus-frequency 32K shortlist (src/draft_shortlist.bin) + 16,384 dynamic context rows predicts the next 7 tokens along with confidence and exact draft probability qi(v). - Opt-In O(1) Prompt-Lookup (
--prompt-lookup, 5 ns on CPU): With the embedded 32K shortlist, overlapped DSpark beats CPU lookup on general text, so--prompt-lookupis opt-in for verbatim RAG or code-copy workloads atT=0(matching the last 16 tokens in 5 ns and copying 7 verbatim, up to 771.6 tok/s). Attemp > 0, it steps aside so rejection sampling always receives calibrated DSpark probabilities. - Adaptive GPU Switch (
{2, 4, 8}): Drafting 7 tokens helps predictable code but slows down high-entropy chat when bad guesses waste verification work. A device-side conditional switch (cudaGraphCondTypeSwitch,--spec-threshold 0.80) checks DSpark's confidence on the GPU and selects verify width 2, 4, or 8 per round without CPU involvement, paired with 128-CTA stochastic sampling at 64-bit Gumbel precision. - Exactness at both
temp = 0andtemp = 1.0: Attemp = 0(greedy), the target model keeps matching prefixes plus one bonus token of its own. Attemp > 0(server defaulttemp = 1.0, top_p = 0.95), the CUDA Graph runs Leviathan–Chen rejection sampling:
dspark drafted 7 tokens with high confidence (0.91), so the gpu switch picked B=8. one weight pass grades all 7: five match, "10" disagrees (replaced by "n"), ")" drops — 6 exact tokens from 1 trip.
step 5: profiling prefill (9K → 20,007 tok/s)
Our initial 128×128 FP16 Tensor Core MoE prefill processed 2,048 tokens per chunk at 9,677 tok/s (after 2D-tiling the 4-tap short convolutions across all 170 SMs). Profiling a 2,048-token chunk with nsys identified four bottlenecks:
- Dequantizing weights to FP16 before GEMM: Switching dense projections to startup-tuned native FP8
cublasLtMatmul(667–692 TFLOPS vs213 TFLOPSFP16) and MoE to native Blackwellsm_120ablock-scaled MMA (kind::mxf4nvf4&kind::mxf8f6f4) cutdense_tc2.69× (42.7 → 15.9 ms) andmoe2.47× (94.5 → 38.3 ms). - Writing 151 MB of temporary MoE slots to VRAM: Instead of writing 8 separate FP32 expert slots per token (
151 MB) to HBM and reducing them in a second kernel,fp8/nvfp4MoE Down accumulates directly via hardware FP32atomicAddinto an 18.8 MB buffer resident in the RTX 5090's 96 MB L2 cache — 8× less DRAM traffic. - Splitting local attention into 4 sub-chunks: Four 512-token launches scheduled only
128blocks on a170-SM GPU (leaving 25% of SMs idle). One 2,048-token launch (512blocks) with async BF16 Tensor Core MMA cutattn_sub2.31× (32.2 → 14.0 ms). - Scalar elementwise kernels: Vectorizing depth-norm, controllers, and post-sconv into 1-pass
float4cutpre_sub1.78× (30.6 → 17.2 ms).
Cold 18.9K HTTP prefill rose to 17,741 tok/s (fp8/fp8, 17,476 tok/s fp8/q4, 18,318 tok/s CLI, 20,007 tok/s B=2048 chunk peak) — 1.61× faster than ingine and ahead of basalt v0.5.7. Toggle each fix below.
empty track on the right is time reclaimed from the 209 ms baseline — cutting chunk latency in half with zero accuracy regression.
step 6: loopcd-hidden (extrapolating across loop passes)
Inkling-2-Mini loops its middle 12 layers 3 times (h1 → h2 → h3) before entering the 6 Coda layers (L18..L23). Normally h1 and h2 are discarded once pass 3 completes.
LoopCD-Hidden (arXiv:2610.02185) extrapolates slightly past h3 along the trajectory from an earlier pass right at the Loop → Coda boundary:
Fused directly into the existing visit-42 handoff kernel, it adds zero extra kernel launches, zero extra KV cache, and zero CUDA Graph rebuilds when set per HTTP request ("loopcd_omega": 0.1). On our 30-task Math + Code + Logic thinking benchmark, --loopcd-omega 0.1 raised accuracy from 25/30 (83.3%) → 27/30 (90.0%) with 5.5% fewer thinking tokens. It defaults to 0.0 so direct-mode behavior stays unchanged.
h₁ → h₂ → h₃ curves toward the right answer. a small nudge (ω = 0.1–0.2) lands squarely inside the target zone; cranking ω ≥ 0.5 overshoots into noise (24/30).
part 2 — geometric abliteration
abliteration, explained geometrically
At any layer, Inkling-2-Mini's hidden state is a 2,304-dimensional vector. Running 336 harmless prompts produces a cluster centered at μharmless; running 336 prompts the model refuses produces a shifted cluster centered at μharmful.
Subtracting the two means and normalizing to unit length isolates the refusal direction:
That translation is what abliteration does: shift a harmful prompt's activation along −r̂ until it lands inside the harmless cluster so the model answers instead of refusing. Applying that shift unconditionally also drifts harmless prompts off course, so squid5090 places a 1.8 MB runtime Fisher-LDA gate in front of the translation. Step through the three stages below and scrub the slider.
drag the slider from 0% to 100%: harmful prompts past the Fisher-LDA gate translate along −r̂ into the harmless cluster while harmless prompts inside the ellipse stay at 0.00 shift (0 diff on 53/53 prompts).
Normal harmless activations have high variance across unrelated topics (code, prose, math) and low variance along the refusal axis, forming an elongated ellipsoid rather than a sphere. Fisher-LDA whitens by the harmless covariance matrix Σ so the gate fires only when an activation exceeds 2–4σ along the refusal axis, subtracting only the excess above the harmless mean cv:
why do this at runtime instead of editing weights
Classic abliteration projects r̂ out of the model's weight matrices directly. On Inkling-2-Mini that fails for three reasons:
- Looped layers: Inkling-2-Mini has 24 physical layers and runs the middle 12 layers three times (48 logical visits). Refusal concentrates in Pass 2 while the same physical weights handle syntax and reasoning on Pass 1 and verification on Pass 3. Modifying shared weights affects all three passes.
- 4-bit quantization noise: Re-quantizing small weight edits back to 4 bits rounds them away.
- Always-on drift: An ungated weight projection shifts harmless prompts as well. Leaving the 19 GB weights untouched and applying the 1.8 MB sidecar at runtime restricts the gated translation to the Pass 2 visits where refusal forms.
0..5 pass 1
6..17 pass 2 (refusal)
18..29 pass 3
30..41 coda
42..47
editing physical layers L6..L17 hits all three passes at once. the 1.8 MB runtime sidecar leaves the weights untouched and applies a triangular schedule only across the Pass 2 visits where refusal forms.
how tools/ablate.py builds that 1.8 mb file
Computing r̂, estimating the harmless covariance Σ, and tuning the per-visit schedule and threshold run offline in an isolated uv environment (the inference binary stays Python-free):
copy-paste recipe to build your own 1.8 MB sidecar (with uv)
# 1. One-time setup (isolated uv env — core squid5090 still uses ZERO Python!)
uv sync --project tools
zig build -Dwebp=true # defaults to ReleaseFast (-Doptimize=fast)
# 2. Generate your own 1.8 MB abliterated safetensors
export SQUID_MODEL_DIR=/opt/models/inkling-2-mini
WORK=work/my-ablation && mkdir -p "$WORK"
uv run --project tools tools/ablate.py directions --out "$WORK/directions.pt"
uv run --project tools tools/ablate.py directions --out "$WORK/directions_think.pt" --think
uv run --project tools tools/ablate.py stats --work "$WORK"
uv run --project tools tools/ablate.py baseline --out "$WORK/baseline_val.pt" --split val
uv run --project tools tools/ablate.py baseline --out "$WORK/baseline.pt" --split report
uv run --project tools tools/ablate.py search --work "$WORK" --batches 12 --n 8
uv run --project tools tools/ablate.py show --work "$WORK" --top 20
uv run --project tools tools/ablate.py export --work "$WORK" --trial <N> --out "$WORK/my-abliterated.safetensors"
# 3. Serve with the 1.8 MB sidecar (fp8/q4 default: 0.0093 KLD, 512K + Vision in 22.9 GiB)
./zig-out/bin/squid5090 serve /opt/models/inkling-2-mini \
--mode fp8 --kv q4 --ctx 524288 --mtp 7 --temp 1.0 --top-p 0.95 \
--ablation "$WORK/my-abliterated.safetensors"
uv run tools/refusal_eval.py --base-url http://127.0.0.1:8000/v1 --label mine how it compares, and what it doesn't do
We benchmarked squid5090 live back-to-back against the two open engines people actually use for this model — ingine (CUDA 13.4) and basalt v0.5.7 — on the exact same RTX 5090, same unmodified weights, native Vision ON, and same HTTP SSE prompts. squid5090 now beats basalt v0.5.7 on all 8 of 8 decode benchmarks in every single quantized mode (fp8/fp8, fp8/q4, and nvfp4/q4), leads cold 18.9K HTTP prefill (17,741 tok/s — 1.61× faster than ingine), leads greedy chat (398.2 tok/s) and T=1.0 prose (324.9 / 313.2 tok/s), hits 29/30 (96.7%) on 30-task reasoning in default fp8/fp8, and fits zero-spill 512K + Vision in 22.9 GiB or 1M in 23.5 GiB.
Honest limits: single-user (c=1) slot architecture by design for the lowest single-stream latency and zero-spill 1M context in two static VRAM arenas, no constrained JSON-schema grammar yet (standard OpenAI tools / tool_calls streaming and OpenAI/Anthropic image payloads are supported), and a static 32 MiB HTTP request buffer.
links
- repository: github.com/tensorfish/squid5090
- the plain-English guide: LITE.md
- the technical reference (every kernel, formula & roofline audit): LEARNINGS.md
- the model: thinkingmachines/Inkling-2-Mini