Repository navigation
feat(moe): serve inkling 2 mini under --moe-strategy hybrid and cpu - #963
Merged
Merged
Conversation
Collaborator
|
LGTM. Reproduced at 54304b7 on an RTX PRO 6000 + Xeon 8559C with Inkling-2-Mini, bs=1 greedy decode:
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 hybridandcpufor Inkling-2-Mini. The CPU MoE executor has no softcapped SwiGLU, andcpurefuses experts of several formats (Mini's layers 0-19 are NVFP4, 20-23 MXFP8). Part of the CPU experts work in #671.ACT_SOFTCAP_SWIGLU(id 5) ingated_rows, the gate/up epilogue the bf16, nvfp4, fp8_block, mxfp8 and gguf formats share. It computesalpha * tanh(gate / alpha) * sigmoid(gate) * limit * tanh(up / limit), the TritonSOFTCAP_SWIGLUmath, with the layer's gate and up caps passed asswiglu_alpha/swiglu_limit(4 and 25 on Mini).max_generic_act_idmoves to 5, so a stale prebuilt_cpu_moeis refused with the rebuild message instead of computing gelu_tanh, and the automatic hybrid pick falls back to offload.cputakes 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 fixed2 * num_expertsslots 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_floorgets abuffersargument, andcpuwith several pools takesmax(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 keep2 * num_experts.cputoo.--moe-cpu-layerswith experts of several formats,cpuwith--moe-cache-scope per-layer, andcpuwith several formats on a host whose pin budget is below the expert banks (WSL, orFREETOKEN_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 withFREETOKEN_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_formatnow also runssoftcap_swigluover bf16, NVFP4 and MXFP8 layers, with inputs large enough to reach the caps. It fails with the sigmoid taken of the capped gate, withupleft uncapped, and with the id 5 branch removed. The newbuffers=2case oftest_the_planned_floor_is_the_fewest_slots_that_stage_a_layerfails whenstage_floorignoresbuffers.The engine lines that pass
buffers=2have 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 ofgated_rows, next toclamped; 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),avx512bf16in its startup line). Each strategy runs in its own process:fuseduses the whole card (r=0.9). The others get a 16 GB card's budget:rgives the engine 0.9 x 15.5 GiB = 13.95 GiB,moe_cache_auto=Truefor offload and hybrid, and after the loadtorch.cuda.set_per_process_memory_fractionstops 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.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 sentenceinstead ofThe 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. WithFREETOKEN_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 main8a5b38a, 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 servewith the chat template andreasoning_effort: low, scored by the last number in the reply:A run of this change on main
8a5b38agave 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
8a5b38athe same hybrid and cpu runs stop at startup:With this change minus the
stage_floorsizing (a control commit on main8a5b38a, in another container), cpu starts with 256 slots (43 + 213), logsDisabling 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 bwprofile 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_GIB11.5 and 7.5), in a container reporting 16 CPUs, every offload and hybrid reply fused's 197 tokens:cpu under the 8 GB budget gave 51.1 tok/s. On
54304b7the 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.ggufhas 37 expert layers with Q5_K down rows and 3 with Q6_K, so two pools. On main--moe-strategy cpurefuses it withseveral 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. WithFREETOKEN_PIN_BUDGET_GB=8it 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
54304b7and again with main's threecpu_moesources, 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: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.