Repository navigation
feat(deepseek_v41): opt-in per-forward expert-offload statistics - #4991
cropduster wants to merge 1 commit into
Conversation
With MoE expert offload, a DeepSeek-V4.1 forward spends its time in a few serial phases per layer: the routing sync, the expert reads, the install, the experts themselves. The per-request hit/miss counters the scheduler logs since jundot#4240 show how often experts are missing, not where a forward's time goes or how prefill and decode differ. With OMLX_DSV41_OFFLOAD_STATS=1 in the server's environment (read at model load, off by default), the V4.1 adapter logs one line per prefill forward and one per decode window: DSV41-OFFLOAD prefill req fwd wall_s chunks routes distinct hits misses read_gb read_bytes wait_s sync_s ensure_s lo_/hi_ misses, distinct DSV41-OFFLOAD decode req win steps reason rows_per_step misses_per_step miss_per_kroute hits misses read_mb wall/wait/sync/ensure/tolist ms_per_step lo_misses hi_misses Decode windows cover forwards 1-16, 17-64 and then 256 each after a request starts; a pause longer than 2 s starts a new request, and a small daemon thread flushes the window of a request that went idle. lo/hi split the layers that run on the whole prefill chunk from those that run on the CED decoder tail. Off, the adapter keeps no collector (stats is None) and the hot path is unchanged. On, each layer adds a few counter updates per call; expert selection and arithmetic are untouched, and a test checks outputs and the slot hit/miss counters are identical with statistics on and off. These lines produced the measurements behind jundot#4951 and jundot#4959, e.g. on an M4 Max (oQ2.5e, 131/384 resident): a full 8K prefill forward 36.9 s wall, of which 15.5 s blocking read wait for 108 GB; steady decode 167 ms per MTP cycle, of which 79 ms read wait and 53 ms routing sync. Tests: tests/test_deepseek_v41_offload_stats.py (17): off by default and the environment switch, exact counters and window boundaries on a fake clock, idle flush, lo/hi split, and unchanged outputs with statistics on. Co-Authored-By: Claude <noreply@anthropic.com>
|
The per-phase split is a useful way to see where an offloaded forward spends its time, and I can see it produced the numbers behind #4951 and #4959. I'm going to close this one, and I want to explain why. I don't keep OMLX_* environment switches in the server code anymore. A toggle either becomes a setting users can see or it stays out of the tree, and a profiling logger isn't something I'd expose as a user setting. The PR also adds a watchdog thread and timing hooks around the expert reads, about 500 lines in total, for output that only a profiling session reads. One thing I noticed while checking it. With CED prefill, a chunk that skips the decoder tail never runs the last MoE layer, so layer_done never closes that forward and several chunks end up in one prefill line with a combined wall_s. I think this fits best as a local patch for your profiling runs, and the measurements you post on the offload PRs are still what I rely on when reviewing them. |
Problem
With MoE expert offload, a DeepSeek-V4.1 forward is a serial chain per layer: routing sync, expert reads, install, experts. The per-request hit/miss counters the scheduler logs since #4240 say how often experts are missing, but not where a forward's time goes, and not how prefill forwards differ from decode. #3910 exposes the cumulative counters through
/v1/models/status; this PR is complementary and does not touch that path.Change (
omlx/patches/deepseek_v41/moe_offload.py, opt-in)OMLX_DSV41_OFFLOAD_STATS=1in the server's environment (read at model load; off by default) makes the V4.1 adapter log one line per prefill forward and one per decode window:Both lines are from a real run: the prefill line is a full forward, the decode line the first window after a cold load.
wait= blocking wait on expert reads,sync= GPU drain before in-place writes,ensure= whole residency update,tolist= routing sync.lo/hiseparate the layers that run on the whole prefill chunk from those that run on the CED decoder tail.Off, no collector exists (
stats is None) and the hot path is unchanged. On, each layer adds a few counter updates per call; expert selection and arithmetic are untouched.Why it is useful
These lines produced the measurements behind #4951 and #4959. On an M4 Max 128 GB (
DeepSeek-V4.1-Flash-1017-oQ2.5e-mtp, 131/384 resident, MTP on), e.g.:They also showed that the OS page cache does not help (disk reads ≈
read_bytes) and that each prefill forward has ~18 s of fixed read cost regardless of length.Tests
tests/test_deepseek_v41_offload_stats.py(17): off by default and the environment switch; exact counters and window boundaries on a fake clock; idle flush; lo/hi split; outputs and slot hit/miss counters identical with statistics on and off.tests/test_deepseek_v41_moe_offload.py,test_deepseek_v41_offload.py,test_moe_expert_offload.py: 136 passed; the 13 failures on this machine fail identically on baremain(the installed app bundle lacksmlx_vlm.models.d1_lfm3_vl). Independent of #4959; the two merge without conflict in either order.Developed with Claude Code; I reviewed and measured it on my machine.