Repository navigation
[Engine] Inkling-2-Mini from the official NVFP4/MXFP8 checkpoint, expert offload and CPU experts for 8-16 GB cards - #6520
baptisterajaut wants to merge 89 commits into
Conversation
…-vram-reserve-mib)
…perts, key-split attention)
…ify and draft, adaptive fallback, --spec in --serve
…ack after 3 iterations
…ls, effort words, stop token, Strata kv names)
…xpert memory, background promotion into VRAM
…ns, per-node doorbells so pools touch local memory only
…ed first, admission margin) instead of LRU
…GLU, warm AVX-512, pinned engine thread
…sured CPU and PCIe times
…f page cache no longer spills it across UPI
…ate_up (resident decode +4%, bit-identical)
… arguments, README, drop the pre-server shim
# Conflicts: # terminal/serve/frontend.py
…t attention's smem attribute only without --tc --kv k8v4: K as in --kv i8 (int8, fp16 scale per 64), V through the Walsh-Hadamard rotation of --kv i8r and stored as 4-bit codes with an fp16 scale per 32 values; the attention output is rotated back. 1632 bytes per cell per slot (i8: 2112, f16: 4096), so the expert pools get the rest. Turing (sm_75) has 64 KiB of shared memory per block: the fp32 prompt attention (kb_attn, 83 KiB) cannot run there and its attribute call failed at startup even with --tc 1, which does not use it. The attribute is set only without --tc, with a message when the card cannot.
…p (k_attn_partial 23.8 -> 13.6 us, decode back to 92 tok/s)
K as in --kv i8, V through the Walsh-Hadamard rotation of --kv i8r and stored int8 (fp16 scale per 64); q is not rotated, the attention output is rotated back. Same bytes as i8. With routing forced to an f32-K/V run (Inkling-2-Mini safetensors, 1338 positions): mean KL 1.24e-3, p99 6.8e-3, top-1 99.48% (i8: 1.36e-3, 1.9e-2, 98.43%; i8r: 2.19e-3, 1.7e-2, 99.25%).
…ols get the rest The fixed 384 MiB beside --vram-reserve-mib covered cuBLAS' lazy workspace and the decode graph; cuBLAS now runs its shapes at load (before the pools are sized), so 128 MiB is enough. RTX 2060 SUPER, IQ3_S GGUF, --kv i8, chunk 4096, reserve 64: 1426 -> 1497 expert slots, decode 30.1 -> 31.1 tok/s (23-token prompt), 24.4 -> 25.3 tok/s (5269-token prompt).
…red at 8 GiB (17-31 MiB used after the pools)
…IQ3_S / IQ4_NL / Q8_0 experts --model FILE.gguf reads llama.cpp's merged layout (#32694, b12600+): - dense matrices in Q8_0, repacked losslessly into int8 codes + fp16 scales, with their own GEMV (decode) and fp32 / fp16 conversions (prompt); - the router (F32, exact) and the loop gates as BF16; - the Q8_0 embedding table in host RAM; - experts gate_up / down in IQ3_S, IQ4_NL or Q8_0: one slot per expert [gate_up rows | down rows] in pool_nv (every layer one format, no MXFP8 pool), read through the part A / part B tables like the checkpoint formats, so the offload (device LRU, prompt streaming) works unchanged. Their decode GEMV and prompt grouped products (SIMT and tensor-core) decode the ggml blocks on the fly. The converter's transforms are undone at load: static conv taps (flip(0).T), rel_logits_proj (transposed), gate_up rows (gate then up, read through a row permutation into the interleaved gu layout). The F32 tensors match the safetensors bit for bit after that.
…there), short chunks skip the NVFP4/MXFP8 small-T paths
--kv-grow 1: the full-attention slots' K/V and (with offload) the expert pools live in CUDA virtual address ranges. The K/V is mapped in --kv-grow-step cells (8192) as the context grows; when VRAM is short the pools give up slots (k_pool_evict drops their experts from the tables, the decode graph is rebuilt for the new slot count). A shorter new request hands the cells back and the pools refill. The addresses never move.
…ns and the spec verify graphs (slot counts baked in)
I rewrote the Marlin kernels from SGLang for this and they're significantly faster. According to my Codex benchmark report, I'm getting 52 tok/s without DSpark, compared to 26 tok/s with your kernels, also without DSpark. So roughly a 2× speedup. |
… NUMA offload, and Dual-GPU EP Unify official Hugging Face safetensors (thinkingmachines/Inkling-2-Mini + mtp.safetensors + vision) and community/Unsloth GGUF checkpoints (UD-Q4_K_XL, IQ3_S, IQ4_NL, IQ4_XS, Q4_K, Q5_K, Q6_K, Q8_0, MXFP4, NVFP4, split multi-shard, and external dspark GGUF/safetensors) directly inside strata-inkling while keeping native .strata v1.1 (SQ-20/15/10 + Vision) as the flagship recommended default. - Zero-requantization official HF safetensors adapter (ink_safetensors_loader.h): maps NVFP4 L0..19 straight to SF4 (code_id=15), MXFP8 L20..23 straight to MX8 (code_id=16), BF16 dense trunk, 3x loop-weighted vram_load_order, mtp.safetensors DSpark drafter, and model.visual.* vision weights (ink_vision.h). - Community / Unsloth GGUF adapter (ink_gguf_loader.h): supports both llama.cpp master (GGUF_shard_rewrite) and PR #32187 layouts, split multi-shard GGUFs, bit-exact NVFP4 -> SF4 nibble-desplit repack, lossless SkCode::GGUF_RAW (id=20) native block dispatch across CPU and CUDA, full-array 200K o200k tokenizer + chat_template export, and Unsloth dspark-*.gguf (dflash arch) 54-tensor mapping. - Ported PR #6520 CUDA-Graph mapped-memory doorbell + NUMA-aware AVX-512/AVX2 CPU expert worker pools + decayed-use background promotion (hybrid_doorbell.{h,cu}) and --kv k8v8|k8v4 KV compression (ink_batch.h, hybrid_doorbell.cu). - Ported PR #6506 Dual-GPU Expert Parallelism (--gpus 2 / --ep-split / IK2_EP_SPLIT) with P2P / pinned fallback and native SF4/MX8/S_K/GGUF_RAW GPU kernels (ep_dual_gpu.{h,cu}) in modular non-conflicting files. - Wired multi-format detection, community HF sources, local import args, and HF o200k tokenizer loading into terminal/setup.py, terminal/strata_cli/launch/catalog.py, terminal/tools/strata_tokenizer.py, and terminal/serve/test_inkling_formats.py. - Preserved original MIT copyright headers (Project Maya, Baptiste Rajaut, merbanan, cobra91) and documented contributor credits for 0.2.19 release notes.
[Engine] inkling2: AMD ROCm/HIP support for strata-ink2, strata-ink2ref, and setup
…ild; docs name AMD RDNA
…her for 20-23 (ggml-org IQ4_NL + Q8_0), other mixes refused naming layers and types
…'s small config files
…el id strata launch leaves thinking
|
@Norhiro fixed in 3cbc56b, now on |
|
@AtahAlam Which card and which engine arguments give the 26 tok/s? Here, on an RTX 3090 with every expert on the card, plain decode without DSpark runs at 91 tok/s on a 257-token prompt, and at 60-66 tok/s with the card limited to 8 GB and the missing experts on the CPU; 26 is close to what offload over PCIe without |
…missing experts on the CPU pools
…he card holds 70% of the experts
|
@baptisterajaut thanks, confirmed on the same RTX 5060 Ti 16 GB. I built The same benchmark as my first comment, run right after on the same build with the official checkpoint and the arguments from that comment (
So on this card the GGUF comes out about 13 % faster at decode, not slower. My guess is the smaller IQ4_NL experts: 5 % more of them fit on the card, and the rest cross PCIe without needing the CPU pools. I have not measured KL here; your 5.9e-3 against the reference covers that. One cosmetic thing: the offload line still says The official checkpoint is unchanged against my first comment (51.5-51.8 tok/s then, 51.7-51.8 now). |
An RTX 3090 has roughly 2.6 times the memory bandwidth of a standard RTX 3060, which is about 160% higher. Your code also pins approximately 17 GB of expert weights in system RAM. My computer has only 16 GB of RAM, with roughly 15.4 GB usable. As a result, the original implementation crashes due to an out-of-memory (OOM) error. To work around this, I modified the code to avoid pinning the entire 17 GB in RAM. I'm also running single-channel DDR4 memory, which has significantly lower bandwidth than a dual-channel configuration. Could removing the memory pinning be responsible for the slower decoding performance I'm seeing? I'm trying to determine whether the bottleneck comes from my modifications, limited RAM bandwidth, or PCIe offloading overhead. |
…ts own MODELS.md section beside strata-inkling's
…ec verify on tensor cores
…nkling 2's template does
…ric reasoning effort
|
Heads-up on overlap: #7073 is a focused fix for #7051 that names tool results after their calls on every route (chat completions, |
Problem and result
Since 0.2.19, Strata runs Inkling-2-Mini (thinkingmachines/Inkling-2-Mini: 128-expert top-8 MoE, layers 6-17 looped three times, so 48 layer applications per token, plus a ViT for pictures) through
strata-inklingand its SQ packs. Its setup also lists the official safetensors as a source, butstrata-inklingreads them only through its EP backend, where attention runs on the host: on an RTX 3090, 2.6 tok/s resident and 2.3 tok/s at 8 GB, and a segfault with the default--chunk 512(48 works). This PR makes that source runstrata-ink2, an engine that loads the official checkpoint as shipped (NVFP4 experts for layers 0-19, MXFP8 for 20-23, BF16 dense weights and vision tower), installed from./setup.sh --family inkling-2-mini --model official(or--family inkling2), and served by the Strata server with its chat template, thinking and tool-call markers, reasoning-effort words, pictures and a conversation cache.This duplicates work from #6506 (cobra91), but I went the other path on purpose: the official checkpoint is already quantized enough to work on as is, so there is no requantization, and the quality is the reference's. Against the transformers implementation (huggingface/transformers#51050) in fp32, the token path with fp32 K/V is at mean KL 1.4e-12 on a 1,600-token text, top-1 identical on every position. With the default f16 K/V it is 1.3e-3 (router near-ties), against 5.4e-3 for ggml-org's IQ4_NL GGUF through llama.cpp on the same text and reference.
The PR is big because the goal was not a minimal engine strapped on in a hurry, but an integration that is already good where Strata matters, on 8-16 GB cards. On an RTX 3090 limited to 8 GB, with the experts that do not fit computed on the CPU, it decodes at 60-66 tok/s with a 32K context.
Related discussion
#6442, opened 2026-11-20 before any code. A public WIP branch was posted there at 11:05 UTC on 2026-11-21, more than three hours before #6506 was opened. Benchmarks of #6506 and maya against this branch are in my comments on #6506.
Approach
strata-ink2is a standalone CUDA engine (engine/src/inkling2/). Decode is one captured graph per token. Prefill uses cuBLAS for the dense products and a tiled grouped GEMM for the experts, with weights decoded on the fly.strata-ink2refis the plain reference path used to check it, andterminal/tools/inkling2/has the oracle and KL tools.--vram-reserve-mib Nleaves N MiB of VRAM free, and the experts that do not fit live in pinned RAM. Placement uses decayed use counts with an admission margin, and promotions run in the background.--cpu-threads Ncomputes the non-resident experts on the CPU: AVX-512 or AVX2 kernels, one thread pool per NUMA node, each expert's memory bound to its node. Doorbells in mapped memory, written from inside the decode graph, tell the pools what to compute, so there is no host sync per layer. With--spec 1, a verify block's missing experts go to the same pools (up to 8 tokens and 64 token-expert jobs per layer visit).--kv-grow 1(merbanan's) lets the K/V grow into the expert pools as a conversation grows. Each pool keeps 64 slots: a prompt shrinks its chunk near that floor, and one that cannot fit ends with a "context is full" error while the engine keeps serving.--conversation-cache-mib Nkeeps conversations in pinned RAM. A checkpoint at each prompt end lets the next turn continue even when the client sends the history back without the model's reasoning (most agent clients do, and the server re-renders the history, so plain prefix reuse never fired after turn 1). Conversations set aside, an agent and its subagents taking turns, are taken up again, and a long shared beginning is read once.image=keys). The conversation cache keys picture tokens on the picture's content.--spec 1uses the model's own DSpark drafter (mtp.safetensors). A draft token is kept only when it is the target's own choice (greedy) or passes the usual acceptance test (sampled), and it falls back to plain decode when that is faster. The verify step reads the drafts through other kernels than plain decode, with another summation order, so a near-tie can flip: on a 512-token chat answer, greedy output matches plain decode for 273 tokens, then parts where the top two logits are 0.2 apart. Plain decode is no different: reading the same prompt token by token instead of as one chunk changes that answer from token 55 on, at a 0.005 gap.--spec: GGUF loading (IQ3_S / IQ4_NL / Q8_0),--kv k8v4/k8v8,--kv-grow, elastic prompt buffers, routed short prompts, a decode-once GGUF prompt GEMM, a chunk size that shrinks to fit, a smaller offload margin, and a Turing startup fix.inkling-2-minifamily, the SQ packs staying onstrata-inkling: the checkpoint at a pinned revision with every file's size and SHA-256, the tokenizer pack, thestrata-ink2build, and engine arguments sized from the card, the RAM and what a desktop already holds. Per card size, and what each config measures, is indocs/INKLING2.md.Everything engine-side is opt-in or specific to
strata-ink2/strata-ink2ref. Outside them: the server's Inkling family switch and image gate, a fix for thinking-off requests on Inkling (enable_thinking: falseused to leave effort 0.9 in the prompt), and setup's CMake minimum raised to 3.25.2, because 3.24 and Debian 12's 3.25.1 cannot configure the engine's CUDA20 targets with nvcc 13; that last one is a separate commit and can be split out.Validation (RTX 3090 24 GB, 2x Xeon Gold 6252, CUDA 13.2, Linux; engine and server at 2daf740, and after merging 0.2.19 (f30718f) the engine is bit-identical,
--specgives the same 128 tokens, and the server passes thinking, effort, tool-call, streaming and picture checks on 24 GB; the later commits add the docs page and the AMD port, whose CUDA build has the same SASS and PTX and gives bit-identical outputs; the picture and conversation-cache identity checks ran on their branches before integration)--specgives the same 128 tokens as plain decode, resident and at 8 GB (longer answers can part at a near-tie, see above).--spec 1 --cpu-threads 22at 8 GB (PCIe share off) gives the same 512 tokens as--spec 1resident, its verify logits at KL 3.4e-13 from the resident ones on the exact path; the other paths stay bit-identical to f30718f.--spec), prompt 2,380 tok/s.--spec,--kv-grow, 8 GB with offload on the GPU only). With two agents taking turns and their reasoning dropped from the history (6 requests, prompts from 6K to 17K tokens), the four returning turns wait 8.6 s in all for their first token instead of 22.3 s resident, and 36-37 s instead of 100 s at 8 GB with a desktop../setup.sh, the server passes its smoke checks on the 24 GB card and a simulated 8 GB one (thinking on/off, effort words, a tool call round trip, streaming, a 30K-token prompt, a picture).python3 -m pytest serveandtests/terminalinterminal/: no new failures (see below).test_stop_closed_pipe.py, and intests/terminalthe TUI modules that do not collect (notextualin the system Python).--specmatching plain decode, the server end to end. The targets are built on Linux HIP only and stay out of the default HIP build, so the other engines' HIP builds compile nothing new. SYCL: nothing new compiled.Limits
--cpu-threadson Linux only, at most two NUMA nodes.--cpu-threads, greedy output is not repeatable run to run: which misses go over PCIe depends on timings, and two runs can differ at mean KL about 1e-4.INK2_PCIE=0makes it repeatable.usage.prompt_tokens; the engine expands it (432 tokens for a 960x686 picture).--specwith--cpu-threadspays only when the card holds most experts: the drafter takes about 2 GiB of expert pool, and a verify computes 8 rows to keep about 3. Decode with and without it (chat prompt / short prompt, tok/s): 8 GB 66.9 → 51.8 / 64.6 → 59.9; 12 GB 80.6 → 72.3 / 81.5 → 87.9; 24 GB at 256K with i8r K/V and CPU experts 82.9 → 84.7 / 83.3 → 100.0. Setup adds it in offload only where the pools hold about 70% of the experts (in practice 24 GB cards at long context).--cpu-threadsand--spec, and setup does not install them. ggml-org's IQ4_NL file (Q8_0 in layers 20-23) loads, at mean KL 5.9e-3.strata launchor the desktop app;strata-inkling's own server path is unchanged, and its tool-call parser stays for it (strata-ink2 keeps its own, which keeps the reasoning).Next, not in this PR
mma.syncexpert GEMM that decodes NVFP4 in registers, and an opt-in W4A8 path with its KL. A 4096-token chunk already reads prompts 23-24% faster than 1024 at a 32K context, but its buffers do not fit at 64K beside the drafter, so setup keeps 1024.--spec(about 1 GiB of pool back at 8-12 GB), and a CPU expert kernel that reads the weights once for a whole verify block.--cpu-threads.