Skip to content

feat(moe): serve inkling 2 mini under --moe-strategy hybrid and cpu - #963

Merged
jason-fxz merged 2 commits into
FlashML-org:mainfrom
ischencheng:feat/inkling2-cpu-moe
Nov 29, 2026
Merged

jason-fxz merged 2 commits into
FlashML-org:mainfrom
ischencheng:feat/inkling2-cpu-moe

Conversation

@ischencheng

@ischencheng ischencheng commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #957, the first item in its follow-ups and the first part @jason-fxz asked for in #942: main refuses --moe-strategy hybrid and cpu for Inkling-2-Mini. The CPU MoE executor has no softcapped SwiGLU, and cpu refuses experts of several formats (Mini's layers 0-19 are NVFP4, 20-23 MXFP8). Part of the CPU experts work in #671.

  • The CPU executor gets ACT_SOFTCAP_SWIGLU (id 5) in gated_rows, the gate/up epilogue the bf16, nvfp4, fp8_block, mxfp8 and gguf formats share. It computes alpha * tanh(gate / alpha) * sigmoid(gate) * limit * tanh(up / limit), the Triton SOFTCAP_SWIGLU math, with the layer's gate and up caps passed as swiglu_alpha / swiglu_limit (4 and 25 on Mini). max_generic_act_id moves to 5, so a stale prebuilt _cpu_moe is refused with the rebuild message instead of computing gelu_tanh, and the automatic hybrid pick falls back to offload.
  • cpu takes several slot pools under the default --moe-cache-scope unified. Its slots only back the prefill double buffer, which needs two layers of each bank's widest rows. With the fixed 2 * num_experts slots split over the pools, the gate_up bank cannot hold two MXFP8 layers: most slots go to the NVFP4 pool, whose rows are half as wide. stage_floor gets a buffers argument, and cpu with several pools takes max(2 * num_experts, stage_floor(..., buffers=2)) slots. On Mini that is 439 slots (74 MXFP8 + 365 NVFP4) instead of 256. Models with one pool keep 2 * num_experts.
  • GGUF files whose expert layers mix ggml types also get several pools, so they start under cpu too.
  • Still refused: --moe-cpu-layers with experts of several formats, cpu with --moe-cache-scope per-layer, and cpu with several formats on a host whose pin budget is below the expert banks (WSL, or FREETOKEN_PIN_BUDGET_GB), since those banks cannot be OS-locked. The last one now fails at startup with --moe-strategy cpu: the expert banks (14.64 GiB) exceed this host's pin budget, and experts of several formats cannot be OS-locked instead (Mini with FREETOKEN_PIN_BUDGET_GB=8).

Tests

pytest tests/moe/test_mixed_expert_formats.py tests/moe/test_cpu_moe.py tests/moe/test_cpu_moe_fp8_block.py tests/moe/test_hybrid_fetch.py tests/kernels/test_swiglu_clamp.py tests/engine/test_moe_cpu_layers.py tests/engine/test_cache_budget.py tests/models/inkling2 -m "not slow" on an L4 (driver 620.70.06, 4 vCPU with AVX-512 VNNI): 180 passed, 20 skipped (ROCm / HIP only).

test_cpu_executor_computes_each_layer_in_its_format now also runs softcap_swiglu over bf16, NVFP4 and MXFP8 layers, with inputs large enough to reach the caps. It fails with the sigmoid taken of the capped gate, with up left uncapped, and with the id 5 branch removed. The new buffers=2 case of test_the_planned_floor_is_the_fewest_slots_that_stage_a_layer fails when stage_floor ignores buffers.

The engine lines that pass buffers=2 have no unit test of their own: a test there would restate the branch. The real-checkpoint run below without them shows what they guard.

Results

Measured at 7ab2048. The second commit, 54304b7, only moves the softcap check out of the row loop of gated_rows, next to clamped; the unit tests and mutants above, the 8 GB rows and the executor comparison below were rerun on it.

RTX PRO 6000 Blackwell Server Edition (sm_120), driver 620.70.06, thinkingmachines/Inkling-2-Mini at c9d028302c. The test container reports 4 CPUs (nproc) and no CPU model; the CPU executor ran 15 threads with AVX-512 BF16 and VNNI (isa=avx512bf16+avx512vnni(nvfp4-w4a8),avx512bf16 in its startup line). Each strategy runs in its own process:

LLM(ckpt, moe_strategy=s, max_running_req=2, max_seq_len_override=8192, cuda_graph_max_bs=2, memory_ratio=r)

fused uses the whole card (r=0.9). The others get a 16 GB card's budget: r gives the engine 0.9 x 15.5 GiB = 13.95 GiB, moe_cache_auto=True for offload and hybrid, and after the load torch.cuda.set_per_process_memory_fraction stops any allocation past 15.5 GiB. Decode is greedy at batch 1, (129 tokens - 1 token) / 128 (64 for cpu), best of two. They ran in the order offload, hybrid, cpu, hybrid, offload.

fused offload hybrid cpu
greedy reply to a 26-token prompt 197 tokens, the transformers reference text (#51050) up to its end token same as fused same as fused 183 tokens, see below
decode tok/s 119.4 105.1, 105.0 98.5, 100.5 47.5
expert slots resident 1987 (332 + 1655), 98.3% hit 1987, 98.6% hit 439 (74 + 365), prefill staging only
KV 1412835 tokens 8196 tokens 8196 tokens 163964 tokens
GSM8K, first 200, greedy, 16 concurrent 197 / 200 195 / 200 194 / 200

On this CPU the executor runs Mini's NVFP4 layers as W4A8 (activations quantized to int8 for VNNI). The cpu reply takes another word at the 5th token (The user asks for one sentence instead of The user asks: "Explain) and ends with almost the same one-sentence answer. It is the same reply run to run and with 4 executor threads. With FREETOKEN_CPU_MOE_NO_VNNI=1 (bf16 activations) the cpu reply is fused's 197 tokens, and so is the W4A8 reply with this change on the previous main 8a5b38a, before #962's attention kernels. The cpu decode rate follows the container: six other W4A8 cpu runs with 15 threads, in containers reporting 16 CPUs, gave 47.5 to 54.9 tok/s, except one at 15.8.

GSM8K goes through ft serve with the chat template and reasoning_effort: low, scored by the last number in the reply:

ft serve --model <ckpt> --max-running-requests 16 --cuda-graph-max-bs 16 --moe-strategy {fused,hybrid,cpu} --max-seq-len-override 8192 --max-extend-length 2048 [--memory-ratio 0.1474 for hybrid and cpu]

A run of this change on main 8a5b38a gave 197 / 200 for all three. Between that run and this one the fused replies are the same on 96 of the 200 questions, with the same 3 wrong.

On main 8a5b38a the same hybrid and cpu runs stop at startup:

ValueError: --moe-strategy 'cpu': the CPU MoE executor does not support this model's expert activation 'softcap_swiglu'; drop the flag and let every layer decode on the GPU offload path instead.

With this change minus the stage_floor sizing (a control commit on main 8a5b38a, in another container), cpu starts with 256 slots (43 + 213), logs Disabling MoE prefill overlap: the slot cache cannot hold two whole layers of experts, and the 26-token prompt's time to first token is 0.71 s instead of 0.53 s.

No ft bench bw profile was recorded, so hybrid fetched at most one miss per layer call and computed the rest on the CPU. Under the 16 GB budget the cache already holds 98% of the expert uses, and hybrid was 4-6% slower than offload on this host. With less memory it pulls ahead. Same script and order (offload, hybrid, hybrid, offload) under the budgets of a 12 GB and an 8 GB card (CARD_FREE_GIB 11.5 and 7.5), in a container reporting 16 CPUs, every offload and hybrid reply fused's 197 tokens:

card budget slots, offload hit offload tok/s hybrid tok/s
16 GB (above) 1987, 98.3% 105.1, 105.0 98.5, 100.5
12 GB 1233, 95.3% 85.6, 86.5 88.4, 88.6
8 GB 479, 77.7% 55.1, 55.1 73.5, 73.6

cpu under the 8 GB budget gave 51.1 tok/s. On 54304b7 the 8 GB rows read offload 49.9, 51.2 and hybrid 71.9, 72.8 tok/s (cpu 55.9), with the same replies: offload and hybrid fused's 197 tokens, cpu the 183-token reply above.

unsloth/Qwen3.6-35B-A3B-GGUF Qwen3.6-35B-A3B-UD-Q4_K_M.gguf has 37 expert layers with Q5_K down rows and 3 with Q6_K, so two pools. On main --moe-strategy cpu refuses it with several MoE slot pools (--moe-cache-scope per-layer, or experts in several quant formats) need every MoE layer to decode from the GPU slot cache; .... On this branch it starts with 603 slots (46 + 557), and its greedy replies to two prompts (48 tokens each) keep offload's tokens for 11 and 48 tokens. With FREETOKEN_PIN_BUDGET_GB=8 it OS-locks its 18.12 GiB of banks, turns prefill overlap off, and gives the same token ids as without the cap.

The CPU executor on its own, main against this branch: in one container (16 CPUs), the executor is built from 54304b7 and again with main's three cpu_moe sources, and timed in alternating runs (b m m b b m m b b m, 400 iterations each, 15 threads) on synthetic banks at the real expert shapes, bs 1, 2 and 4 with and without shared experts. Every task's output is bit-identical between the two builds (42 and 28 tasks). Task time, branch / main, geomean over a workload's tasks of the median over each build's 5 runs:

workload (silu unless noted) run 1 run 2, Qwen3.6 NVFP4 moved last
Qwen3.6 NVFP4 (H 2048, I 512) 1.062 0.966
Qwen3.6 GGUF Q4_K 0.987 0.971
Qwen3.6 bf16 1.048 1.028
GLM-5.3-Flash NVFP4, swiglu_clamp 1.015
Inkling MXFP8 shape (H 2304, I 1152) 0.973
Inkling NVFP4 shape 1.005 0.988

Within one build a task's median moves 2 to 14% from run to run (coefficient of variation), so these ratios are inside the noise either way. Qwen3.6 NVFP4 ran first in every process of run 1.

A real 8 or 12 GB card, a desktop CPU and its memory bandwidth were not tested; the smaller cards above are budgets on the same RTX PRO 6000, and the container's host bandwidth and PCIe link are not a desktop's.

@jason-fxz

Copy link
Copy Markdown
Collaborator

LGTM. Reproduced at 54304b7 on an RTX PRO 6000 + Xeon 8559C with Inkling-2-Mini, bs=1 greedy decode:

strategy budget slots decode tok/s reply vs fused
fused full card resident 122.5
offload 8 GB 477 53 identical
hybrid + ft bench bw profile 8 GB 477 86 first 63 tokens identical
offload 12 GB 1227 85 identical
hybrid + ft bench bw profile 12 GB 1227 98 identical
cpu 8 GB 439 53 identical
  • cpu keeps prefill overlap with 439 slots (74 + 365). Without the stage_floor(buffers=2) sizing it gets 256 slots and turns overlap off, and TTFT goes from 0.54 s to 0.61 s.
  • On the real weights, the CPU executor's output stays within 0.6% of the GPU kernel's on both the NVFP4 layers (0-19) and the MXFP8 layers (20-23) with bf16 activations, and within 1.2% on NVFP4 with the default W4A8 path.
  • GSM8K first 100: fused 96, hybrid 98, cpu 98.

@jason-fxz
jason-fxz merged commit 81c162b into FlashML-org:main Nov 29, 2026
1 check passed
xinze-zheng added a commit to xinze-zheng/FreeToken that referenced this pull request Nov 29, 2026
Resolve engine.py against FlashML-org#963 (inkling 2 mini under hybrid and cpu): keep the pin
budget sized by the banks this process pins (_pinned_bank_bytes) and pass main's
layer_methods through it; size the cpu-strategy prefill double buffer from the slot
rows, as the auto floor does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants