Repository navigation
feat(moe): report expert offload hit/miss counters in model status - #3910
Closed
beatakouchnir wants to merge 1 commit into
Closed
beatakouchnir wants to merge 1 commit into
beatakouchnir wants to merge 1 commit into
Conversation
moe_offload_stats() existed but nothing outside the tests called it, so a user could not tell whether a residency was too low for their workload. - /v1/models/status: each model carries moe_expert_offload_stats (layers, hits, misses, hit_rate since load, prefill included), or null when the model is not loaded, offload is off, or no layer was wrapped. A failure reads as null so monitoring never breaks on it. - BaseEngine.moe_offload_stats() behind a _moe_offload_model() hook, which BatchedEngine and VLMEngine implement; the walk runs only for models with offload enabled. - DeepSeek V4.1 kept its counters on OffloadedExpert.slots, which the walk never reached; _ExpertSlots is now marked moe_offload_counters, and moe_offload_stats walks with moe_offload_caches(counters=True). The default walk still skips the slots, so materialize_offload_state and the prefill slot release never see them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
beatakouchnir
force-pushed
the
feat/moe-offload-stats
branch
from
October 7, 2026 06:36
7f1c271 to
74d3190
Compare
Contributor
Author
|
Rebased onto 57fda05. #4240 moved the cache walk into |
Contributor
|
Closing this PR because it has merge conflicts and no new commits for over 30 days. This isn't a judgment on the change. If you'd like to continue, rebase on current |
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 #2595 (expert offload primitive).
Problem
Expert offload keeps per-layer hit and miss counters, and
moe_offload_stats()aggregates them. Since #4240 the scheduler logs them per request, but nothing exposes them through the API, so a monitoring client cannot see whether a residency is too low for its workload. The DeepSeek V4.1 adapter's counters are also out of reach: they live onOffloadedExpert.slots, whichmoe_offload_caches()never collects.Change
GET /v1/models/status: each model carriesmoe_expert_offload_stats,{"layers", "hits", "misses", "hit_rate", "fetched_bytes"}since load (prefill included), ornullwhen the model is not loaded, offload is off for it, or no layer was wrapped.EnginePool.get_statusreads it through_moe_offload_stats, which turns any error intonullso the status endpoint never fails on it.BaseEngine.moe_offload_stats()walks the model returned by a_moe_offload_model()hook (Noneby default);BatchedEnginereturns_model,VLMEnginereturns_vlm_model. The walk runs only whenmoe_expert_offload_enabledis set for the model.deepseek_v41/moe_offload.py:_ExpertSlotsis markedmoe_offload_counters = True.moe_offload_caches(model, counters=True)also collects slots carrying that marker, andmoe_offload_statsuses it when it walks a model itself. The default walk is unchanged, somaterialize_offload_stateand perf(moe): faster prefill and decode when offloaded experts stream from SSD #4240's prefill slot release never see V4.1's slots, and the counters the engines hand the scheduler are as on main.Example (Qwen3.8-Flash-Next-4bit, 50% residency, after one request):
Verified
Measured before the rebase onto #4240, which added
fetched_bytesto the counters and moved the cache walk intomoe_offload_caches(). Throughomlx serveon an M5 Max (128 GB), isolated base path, one cold request per model at temperature 0:mlx-community/OLMoE-1B-7B-0125-Instruct-4bitmlx-community/Qwen3.8-Flash-Next-4bitLayer counts match the adapter's load log (
wrapped 16 layers at 25.0% residency,wrapped 48 layers at 50.0% residency)./v1/models/statusanswered in 1.2 to 2.0 ms with the Flash-Next walk included.Tests
test_moe_expert_offload.py: the engine method returns the same counters asmoe_offload_stats,Nonewith offload off, andNonefor a model with no wrapped layer.test_deepseek_v41_moe_offload.py: after a load through the V4.1 loader,moe_offload_statsreports everyOffloadedExpertlayer with hits and misses equal to the sum over their slots (fails withoutcounters=True), and the defaultmoe_offload_caches()returns none of the slots.test_engine_pool.py:get_statusreports a loaded engine's counters,nullwhen the engine raises, andnullonce unloaded.1,199 passed across the offload (common, V4, V4.1, GLM), engine-pool, scheduler, server, batched and VLM engine, engine-core, compat and admin-template suites on the current base.
ruffadds no findings beyond twoOptional[Dict]annotations that match the surrounding style ofengine/base.py.Not in this PR
Showing the counters in the admin dashboard, and a misses-per-decode-token figure (it needs the decode token count separated from prefill accesses).
🤖 Generated with Claude Code