Skip to content

feat(inkling2): serve inkling 2 mini - #957

Merged
jason-fxz merged 52 commits into
mainfrom
feat/inkling-2-mini
Nov 27, 2026
Merged

jason-fxz merged 52 commits into
mainfrom
feat/inkling-2-mini

Conversation

@jason-fxz

@jason-fxz jason-fxz commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Serve thinkingmachines/Inkling-2-Mini (Inkling2LoopForConditionalGeneration, inkling2_loop): text, image input, reasoning and tool calls, with prefix reuse and the fused and offload MoE strategies. Closes #941.

The model

  • 24 decoder layers; layers 6-17 run three times per token (48 layer visits, each with its own KV and convolution state). Every pass after the first mixes four message rows from the previous pass into its q / k / v and MLP inputs through low-rank gates.
  • Block attention residuals: every 6 layers close a block, and each sublayer's input is a softmax mix over the blocks (attn_res).
  • Sliding-window (1024) and global attention with a relative-position bias, sinks, a sigmoid output gate, q/k L2 clips and log scaling; short convolutions (window 3) on k, v, the attention output and the MoE output.
  • 128 experts, top 8, sigmoid router with a selection bias, softcapped SwiGLU. Layers 0-19 are NVFP4 (W4A16), layers 20-23 MXFP8 (W8A16, on the MXFP8 MoE kernel from feat(moe): add mxfp8 expert kernels for gpu and cpu #954). The activation quantization the checkpoint records is not served, as in the reference implementation.
  • Fused Triton kernels in kernel/triton/inkling2.py: q_prep, short_conv, attn_res, the message gates, extend attention and split-K decode attention.
  • Vision tower and processor (40x40-pixel cells, no resize; transparent pixels blended onto the reference's checkerboard).
  • Reasoning and tool-call parsers, with tool-call arguments streamed as they decode.

Shared mechanisms this adds

  • Window states (ModelConfig.window_states, WindowStateSpec): a model declares per-token rows a resume needs for the last few tokens. Inkling declares its convolution inputs (624 KiB per token, window 3).
  • Tiered SWA radix (kvcache/swa_radix_cache.py): each node carries a swa_level: the window KV tier, then each state tier as a shorter window. Resume points, eviction and tombstones work per tier. HybridSWAKVCache keeps a row pool per state tier, reached from a token's full KV slot through a row map.
  • Resume points (scheduler/cache.py, Req.state_live): a prefill chunk allocates state rows only for its last tokens; at commit the rows are kept only at resume points (the last 16 tokens of a prompt, the insert point, the tool-call anchor).
  • ModelConfig.swa_full_tokens_ratio (Inkling: 0.1) and ModelConfig.moe_layer_order (the offload prefill stages experts in the model's call order, so a looped model keeps its prefill overlap).
  • Resident experts in several formats; the offload cache floor stages a whole layer in every bank (moe/pool_policy.py).
  • A hf_quant_config.json that names its own quant_method replaces config.json's quantization_config (utils/hf.py): Inkling 2 ships only a ModelOpt stub there and describes every tensor's precision in that file (quant_method: inkling2, read by Inkling2QuantConfig). An old ModelOpt sidecar still only fills a missing config.

Memory

  • 17.9 GiB resident under --moe-strategy fused. Prefill activations peak at about 100 KiB per token: 796.8 MiB for an 8192-token chunk, down from 1516.8 MiB before perf(moe): reuse the gate_up buffer for the nvfp4 prefill down output #956 and the activation work in this PR (logits bitwise equal at the time of that change).
  • 96 GiB GPU, 4 requests: 1.40M tokens of full-attention KV (42.6 GiB), 140K window tokens (21.3 GiB, about 125 resume points), 2.7K convolution rows (1.6 GiB).

Performance (RTX PRO 6000 Blackwell, sm_120, ft serve, median of 5)

Every expert on the GPU in both columns; auto resolves to offload with all 3072 experts cached.

--moe-strategy fused default (offload)
prefill, 2048-token prompt 17136 tok/s 3715 tok/s
prefill, 8192-token prompt 18692 tok/s 14286 tok/s
decode bs=1, 1024 in / 512 out 120.8 tok/s 116.2 tok/s
decode bs=8, 1024 in / 512 out 65.5 tok/s per request, 512 total 63.9 per request, 506 total

Under offload a prefill chunk stages every layer visit's experts from host memory whatever its length, so a 2K prompt costs about as much as an 8K one.

Correctness

  • GSM8K, first 100 test questions, greedy, default reasoning effort, 16 concurrent requests, at most 4096 tokens: 97 / 100 (none truncated, 515 output tokens on average).
  • Prefix reuse against a cold prefill on the real checkpoint (tests/models/inkling2/test_prefix_cache.py): bitwise where the cached prefix was prefilled; first logits within the decode-vs-prefill noise where it holds decoded tokens.

Not served

DSpark speculative decoding, --tp > 1, GGUF checkpoints and quantized KV caches are refused at startup.

Follow-ups

  • The CPU and hybrid MoE strategies: refused at startup in this PR.
  • Dspark speculative decoding from the checkpoint's mtp.safetensors: refused at startup in this PR. It needs multi-row decode in the short convolution and the attention, window-KV frees held until a verify step commits, and an MTP loader and proposer.

Tests

RTX PRO 6000 (sm_120):

  • FREETOKEN_INKLING2_MODEL=<checkpoint> pytest tests/models/inkling2: 17 passed, the real-checkpoint prefix-cache tests included.
  • pytest tests/kvcache tests/scheduler tests/moe tests/engine/test_attention_backend_arch.py: all passed (the two flashinfer b12x tests with a CUDA toolkit that has cublasLt.h; the scheduler tests include a two-request decode that keeps every request's window KV).
  • pytest tests -m "not slow", run before the last fixes: 2712 passed. The other failures fail the same way on main: the ggml kernels need a CUDA toolkit with cublas_v2.h (all 102 pass with CUDA 13.2), fa has no sm_120 kernels, and some test_quant_config cases depend on the local checkpoints.

andy-yang-1 and others added 30 commits November 26, 2026 23:59
…ow of the swa radix

- swa_radix nodes carry a level, one per window tier (the window KV, then each model window
  state); single-window trees behave as before
- Inkling 2 declares its convolution inputs as a 3-token WindowStateSpec: a prefill chunk gives
  rows only to its tail, and a resume point keeps 19 rows beside its 1040 window tokens
- drops swa_snapshot_radix, its state slots and snapshot planning
A model may declare its own swa_full_tokens_ratio; EngineConfig's default is now None,
resolved to the model's ratio or 0.2. Inkling 2 keeps window KV only in front of resume
points, so 0.1 still holds about 120 of them on a 96 GiB GPU and leaves the full-attention
KV 1.32M tokens instead of 946K.
A looped model runs some MoE layers more than once per forward, so the overlap prefill staged the
wrong layer after a loop's last visit and the engine turned the overlap off. A model now declares
its MoE call order (moe_layer_order) and the double buffer alternates by call, staging the next
call's layer. Inkling 2 Mini offload prefill: 1.3x at 2K tokens, 1.7x at 32K, identical logits.
- fused_experts_nvfp4 allocates one M*top_k*max(2I, H) buffer: the gate_up output is a view of it, and the down output takes the same storage once the activation has run
- the routed sum is written into hidden_states and returned, as the bf16 fused_experts_impl does; the MoE layer contract already lets the expert kernel overwrite its input
- the prefill tests pass a copy of the input where they read it again after the call
- loop-pass prefill chunks of 2048+ tokens mix each message row when its gate reads it and run each attention gate end to end on its own rows; decode and shorter chunks keep the batched path
- drop the gated q/k/v inputs once attention has run, and the prelude output and the previous pass's sources before the coda
- build the relative-bias table 2048 rows at a time and free each before the next
…h fp32 output

- the checkpoint stores the gates' forget / gain weights in bf16; keep them bf16 instead of upcasting at load
- torch.bmm with out_dtype=float32 replaces the z.float() cast and the fp32 SIMT bmm; measured against fp64 on a real 8192-token prefill, the error is the same as the fp32 bmm's
- layers 20-23 load as e4m3 rows with their ue8m0 codes instead of bf16 dequantized at load, and run on the W8A16 mxfp8 MoE method
- the AOT table lists the mxfp8 expert bank rows for this model
- transparent and half-transparent pixels show the 8-pixel 204 / 153 checkerboard behind them, as the reference processor does, instead of their dropped-alpha color
- the non-streaming parse no longer strips the reasoning and content, so it returns what the stream sends
- ModelConfig.bf16_kv_only marks a model whose own attention kernels read bf16 KV; --kv-cache-dtype fp8 / int8 now fails at startup instead of at the first forward
…sor scan

- the scan builds the QuantConfig as the loader does, from the file a family's spec names when config.json holds only a stub, and reads stacked w13_ / w2_ expert tensors; Inkling 2 Mini's 164 modules now agree
- method_rows and min_cache_bytes replace the engine's _min_expert_cache_bytes for the small-GPU fit; layer_bank_bytes reads the same per-bank rows off the loaded banks for the auto plan's floor and for layer_slot_bytes
- the checkpoint stores the router weight in bf16; keep it bf16 and compute the logits with torch.mm(out_dtype=float32), as SGLang does for this hidden size, instead of x.float() and an fp32 SIMT GEMM
- against fp64 on a real 8192-token prefill the logit error grows from 1.7e-6 to 2.0e-5 at most; no row's top-8 expert set changes
…s greedy tokens

- a hit that resumes past decoded KV is bounded by the largest difference of its first logits; the 24 greedy tokens are no longer compared, since a near tie anywhere in them flips the check without a cache fault
- the MXFP8 layers run as W8A16 and the model takes about 18 GiB resident; note the prefill activation peak per token and that a quantized --kv-cache-dtype is refused at startup
- the 96 GiB example now holds 1.40M full-attention tokens, 140K window tokens and 2.7K rows
…onfig loads

- a hf_quant_config.json that names its own quant_method replaces config.json's quantization_config, which Inkling 2 ships only as a ModelOpt stub; an old ModelOpt sidecar still only fills a missing one
- ModelSpec.quantization_config, QuantConfig.from_hf's quantization_config argument and Inkling 2's own reader of the file go away; the stored-tensor scan folds the sidecar the loader's way
- a model with window states no longer lowers --max-running-requests on its own when the plan does not fit; like every other model it fails at the first allocation that does not fit
- method_rows and min_cache_bytes go with it; the offload cache's stage floor stays
- drop the cache internals, pool sizing, the 96 GiB example and the speculative-decoding plan from the note; keep resume points, memory, the MoE strategy advice, reasoning effort and what is refused
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New architecture request: Inkling-2-Mini (thinkingmachines/Inkling-2-Mini, 26.4B-A3.4B looped MoE)

2 participants