Repository navigation
MoE route tap: optional TF_ROUTE_TAP trace of global top-k - #1886
Cosmic-Construct wants to merge 18 commits into
Conversation
|
Thanks @Cosmic-Construct, this is a careful design, and it follows #1758's conditions closely. We read it through. With
It also conflicts with main now (the CHANGELOG and a few one-line hook-ups). A rebase onto current main is fine whenever you push the fixes. You can leave the CHANGELOG to us; we add the line at landing. Once it's in, we'll run it on a GB10. |
2c58d3e to
9e0995c
Compare
|
Thanks for the review. I've rebased the branch onto current main (9bb51cd) and it's five commits now. The fourth (
I've left CHANGELOG to you. Hardware checks (Apple M4 Max, 64 GB;
|
|
Thanks @Cosmic-Construct. That's all six, in order, plus a leak you found yourself. We're now running what your Mac couldn't, on a GB10 (CUDA, Nemotron 3.5 Lightning 30B-A3B): main against this head with |
|
@Cosmic-Construct, our runs on hardware you don't have are in. Two things need fixing before this lands. 1. With
(These are from the second job. In the first, the PR's runs sat at 219-220 at one stream and three of main's four runs at 239-241.) The tap-off path should cost nothing. Our guess is the barrier before the blit you added for LFM2 (and GLM, GLM-DSA, Step5 and MiniMax) runs whether or not the tap is live. Could you make it conditional on a live tap? 2. With the tap set, CUDA Nemotron doesn't load. This was Nemotron 3.5 Lightning 30B-A3B MLX 4-bit on a GB10,
Our tap-unset CUDA A/B is still queued. We'll post it when it's in. |
9e0995c to
86726bb
Compare
|
Thanks for both reports. The fixes are on this head ( 1. Tap-off Metal regression. The blit barrier was already behind
M4 Max tap-unset A/B of main
v5 also matched main on this M4 Max, so the M5 Ultra 5–10% regression does not reproduce here. Could you rerun main vs this head on the M5 Ultra? 2. CUDA Nemotron GraphNotPermitted, and the leak on the way out. The real fix, not a named refusal. Every failed native open after Tap-on on this M4 Max: LFM2 13,604 records, 0 all-zero; Nemotron 3,095 records, 0 all-zero; tokens equal; no leaks. Decode counts from the TFR1 Host checks here (logs not attached): I've left CHANGELOG to you. |
|
@Cosmic-Construct, the CUDA tap-off run is in: Nemotron 3.5 Lightning 30B-A3B MLX 4-bit on a GB10, main against this head with |
|
Thanks @Cosmic-Construct. An independent review on current main (d38bba3): Verdict: CHANGES (four). Unset, the tap is main: every hot-path site is one global load and a skipped
Applying it
What holdsUnset is main.
Where it writes.
Posted evidence (Metal only). An M4 Max running
CUDA and HIP haven't run on GPU. Changes1. Rebase on current main and prove one
2. GLM on Metal: plain decode rounds never publish.
3. Layer numbers shift after a drop.
4. Records can't be split into rows, and long ones are cut silently.
Small points (not blocking)
Runs needed
|
|
Hi @Cosmic-Construct, checking in on the route tap. With the tap unset it matches main, which is the part we cared about most, and thanks again for chasing down the close-path leak yourself. Our 3 Nov review lists what's left:
|
… ring storage Keep the session and its tests in route_tap.zig; move unchanged wire encoding and ring storage into a bounded module. Preserve main’s existing Nemotron prompt-flight extraction, which already keeps backend.zig below the inclusive600-line cap.
…pped ordinal asks Capture each Metal command buffer reservation bound and publish at its own wait, including GLM plain rounds, launched slots, ring windows and the extracted Nemotron prompt-flight owner. Tap GLM chunked routing too, and let the existing GLM device runner open a session for its record-count gate. Keep original row dimensions and whole routed rows, flag truncation, and omit shared slots consistently in strided CUDA/HIP captures. Advance ordinals on refused reservations. Add real engine/CUDA session identity and pending-buffer host regressions, decoder cases and updated wire-format documentation. Fit host-only XPU bindings to the same core; retain the separate file-split commit.
Read the path through the shared platform environment and register its path rule. Validate before opening the writer so malformed control characters report an open error; unset capture stays inactive.
Use single-line module docstrings and point at the route-tap device gates. Tool behavior and every Zig source stay unchanged.
Add a valid trace path to the existing all-rules table. The first environment run correctly refused the missing fixture entry; keep that receipt and rerun the named target with the coverage row supplied.
Unset, the tap is inert. Set to a path, rank 0 of a tapped family writes TFR1 records (step, layer, ids, weights) from a host ring after the existing step wait. CUDA and HIP copy before localisation; Metal blits each layer in the same command buffer. DeepSeek V4.1 and every other untapped family refuse the switch by name.
Record fields stay step, layer, ids and weights. The sample is a format fixture. The bench receipt names only host RAM class and GPU model.
nemotron_h on HIP rewrites picks in tf_nemo_localize, not tf_moe_localize. Tap after select on both whole-layer and sharded paths so rank 0 records global ids. Untapped families, including deepseek_v41, still refuse by name.
While the tap is live, tapped CUDA/HIP families run without graphs and copy into a cuMemHostAlloc/hipHostMalloc ring. A failed copy clears its slot and counts as a drop (logged at stop). Publish is per step, after an event behind that step's copies. admit refuses XPU nemotron_h, Metal Flash Next and Metal Qwen3.5 MoE by name. Metal GLM, GLM-DSA, Step5, MiniMax and LFM2 barrier before the blit. XPU tokenizer is one shared module.
admit starts the GPA ring before family hosts open. LFM2, GLM-DSA and MiniMax each have their own Host.close and never called stop(), so the session and both 2 MiB slabs leaked at shutdown. Nemotron, GLM and Step5 already stopped. stop() also runs the Metal detach callback. A testing-allocator test covers start/stop.
… open The blit barrier, afterWait/afterLand, reservedCount and CUDA/HIP land run only while the tap is live, so tap-off records the same work as main. CUDA Nemotron skips MTP and window capture when the tap is live; glue kernels run eagerly instead of GraphNotPermitted. Failed native opens call stop so the ring is freed. A testing-allocator test covers that path. held() takes api.Opened at the Metal Nemotron and DeepSeek sites so the return type is !?api.Opened. Decode counts TFR1 records from the records list.
… ring storage Keep the session and its tests in route_tap.zig; move unchanged wire encoding and ring storage into a bounded module. Preserve main’s existing Nemotron prompt-flight extraction, which already keeps backend.zig below the inclusive600-line cap.
…pped ordinal asks Capture each Metal command buffer reservation bound and publish at its own wait, including GLM plain rounds, launched slots, ring windows and the extracted Nemotron prompt-flight owner. Tap GLM chunked routing too, and let the existing GLM device runner open a session for its record-count gate. Keep original row dimensions and whole routed rows, flag truncation, and omit shared slots consistently in strided CUDA/HIP captures. Advance ordinals on refused reservations. Add real engine/CUDA session identity and pending-buffer host regressions, decoder cases and updated wire-format documentation. Fit host-only XPU bindings to the same core; retain the separate file-split commit.
Read the path through the shared platform environment and register its path rule. Validate before opening the writer so malformed control characters report an open error; unset capture stays inactive.
Use single-line module docstrings and point at the route-tap device gates. Tool behavior and every Zig source stay unchanged.
Add a valid trace path to the existing all-rules table. The first environment run correctly refused the missing fixture entry; keep that receipt and rerun the named target with the coverage row supplied.
Follow main 5ee83f2 (GLM DFlash2 prompt integration) and 4b997f8 (current Metal native layout). Remove only two and four blank lines from the merged GLM prompt and native Metal modules. Retain all main branches, readers, assertions, scheduling and incoming optional route-tap lifetime hooks; source tokens are unchanged.
|
Thanks @Cosmic-Construct. The latest tree still has four route-tap correctness issues:
|
Closes the request in #1758, following the conditions in the maintainer comment there.
MoE route tap (
TF_ROUTE_TAP)Off-by-default switch for inspecting or monitoring MoE routing. Unset, the engine is unchanged (same tokens, same speed). Set to a file path, rank 0 of a tapped family writes a versioned TFR1 trace of each layer's global top-k (step, layer, ids, weights).
Families
Tapped (named, and only these):
glm5_next,glm_moe_dsa,qwen3_5_moe,qwen4_exp,nemotron_h,nemotron_h_omni,minimax_m3_vl,step5_vl,lfm2_moe.Every other
model_typeis refused by name whileTF_ROUTE_TAPis set, includingdeepseek_v41(not tapped).Copies
tf_moe_localizeortf_nemo_localize.The host ring is independent of the file writer. A full ring drops the newest record. The header
top_kfield is reserved and stays 0; per-recordnis rows × k.Evidence
Host tests: ring wraparound, header/record round-trip, tapped names, unset no-op (
zig/src/core/route_tap.zig).tools/route_tap_bench.py decodefails on any all-zero record.GPU run, Metal only: Apple M4 Max (64 GB class),
nemotron_h(Nemotron 3.5 Lightning 30B-A3B, MLX 4-bit),zig build native -Dcpu=apple_m1, 256 tokens, temp 0, 3 reps, medians.Not run: CUDA and HIP paths have not been run on GPU hardware yet;
GPU_RUNBOOKindocs/has the checklist. Happy to add those receipts when available.Docs
docs/route-tap.md.TF_ROUTE_TAPis listed incapabilities --json.