WIP: PD-DFlash — native offloaded-expert stat accessors (unblock §8 B0–B2) - #164
Merged
Conversation
added 4 commits
August 15, 2026 19:00
Add native, behavior-inert getters so the PD-DFlash §8 runner can read real offloaded-expert metrics instead of 0.0 fallbacks: - ExpertDispatcher (gpt-oss/FP4 path): GetCacheOccupancyBytes() sums stored byte_size over the resident cached_experts_ set; GetCacheHitRate() divides two passive hit/access counters incremented at the existing exec-arg emit sites and reset by ClearExpertCacheCounts(). No routing/dispatch change. - ArcherPrefetchHandle (topology path): GetExpertOccupancyBytes() and GetWastedPrefetchBytes() from a read-only GetResidentAndWastedBytes(). - pybind: get_cache_occupancy_bytes, get_cache_hit_rate, get_expert_occupancy_bytes, get_wasted_prefetch_bytes.
ExpertPrefetcher gains read-only helpers the §8 runner probes: get_hit_rate() (dispatcher counter, else topology visit-count aggregate), expert_occupancy_bytes() (dispatcher + handle), wasted_prefetch_bytes(), and a num_offloaded_experts property that counts expert_tensor_map ids the store reports offloaded -- this is populated for gpt-oss packed experts, so require_offloaded() no longer wrongly refuses B0/B1/B2. OffloadEngine wires the dispatcher into the prefetcher and exposes num_offloaded_experts / expert_cache_hit_rate / expert_occupancy_bytes / kv_occupancy_bytes (kv from a kv-cache manager when present, else None).
…ix Qwen 404 _serving_measure now falls back to the native prefetcher wasted_prefetch_bytes when RouteAheadStats has no per-expert byte payload (gpt-oss), and adds an opt-in --probe-h2d device host->device bandwidth probe so the §7 hide inequality uses a measured BW instead of the 'not supplied' warning. Also replaces the 404 Qwen/Qwen3-Coder-30B-A3B target (never existed) with the real ungated Qwen/Qwen3-Coder-30B-A3B-Instruct repo in the frozen §8 contract.
Add CPU tests for the ExpertPrefetcher/runner accessor wiring (num_offloaded_experts, hit-rate dispatcher/topology fallback, occupancy sum, native wasted fallback, h2d probe) with fakes for the native _store engine, and point the contract/GPU tests at Qwen/Qwen3-Coder-30B-A3B-Instruct.
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.
WIP / DRAFT — do not merge
Wires the native offloaded-expert statistics accessors so the PD-DFlash Phase A §8 matrix's B0–B2 (offloaded) rows emit REAL metrics instead of 0.0 fallbacks — the last blocker to computing the hardware go/no-go. All accessors are read-only, additive, opt-in; no default/hot-path behavior changes.
Root cause of the prior blocker (measured on
origin/dev)The gpt-oss offloaded baselines were unmeasurable because
_count_offloaded_experts(engine)returned 0 (gpt-oss's packed experts leaveexpert_prefetcher.expert_nbytes_mapempty), sorequire_offloaded(B0|B1|B2, 0)raised. gpt-oss experts flow through the nativeExpertDispatcher(FP4), whose hit/occupancy accounting was never surfaced to Python — henceexpert_cache_hit_rate/expert_occupancy_bytes/wasted_prefetch_bytesall fell back to 0.0.Counters exposed (C++ → pybind → Python)
expert_cache_hit_rateExpertDispatcherpassive hit/access counters (gpt-oss);NodeBodyhit/visit aggregate (others)expert_dispatcher.get_cache_hit_rate/prefetch_handle.get_hit_rateExpertPrefetcher.get_hit_rate(),engine.expert_cache_hit_rateexpert_occupancy_bytesbyte_sizeovercached_experts_(dispatcher) + on-CUDA nodebyte_size(handle)get_cache_occupancy_bytes/get_expert_occupancy_bytesExpertPrefetcher.expert_occupancy_bytes(),engine.expert_occupancy_byteswasted_prefetch_bytesbyte_size × unused_count(topology)get_wasted_prefetch_bytesExpertPrefetcher.wasted_prefetch_bytes(); runner native fallbacknum_offloaded_expertsis_tensor_offloadedoverexpert_tensor_map(populated for gpt-oss)is_tensor_offloaded)ExpertPrefetcher.num_offloaded_experts,engine.num_offloaded_expertsmeasured_h2d_bytes_per_second--probe-h2dflag (flag--measured-h2d-gbpsalready accepted)kv_occupancy_bytesengine.kv_occupancy_bytes(see note)The dispatcher hit/access counters are two
std::atomicincrements at the existing exec-arg emit sites (same instrumentation class asgpu_hit_cnt++/incache_visit_count++), reset byClearExpertCacheCounts(); they change no routing/dispatch behavior.Qwen 404 fix
Qwen/Qwen3-Coder-30B-A3B(harness default) returns HTTP 404 / never existed (verified via HF API). Replaced with the real, ungatedQwen/Qwen3-Coder-30B-A3B-Instruct(qwen3_moe, per-expert tensors) in the frozen §8 contract + tests + docstring. Draftz-lab/Qwen3-Coder-30B-A3B-DFlashunchanged (verified present).RE-RUN §8 slice (SM120, gpt-oss-20b,
--device-memory-ratio 0.30,--probe-h2d)report.py --allow-blocked B2→ exit 0. B0/B1 now RUN (norequire_offloadedRuntimeError); B2 remains the runner's pre-existingBLOCKED_UNTIL_2D_SCHEDULER.Before: B0–B2 could not run at all; B3 alone reported
hit_rate/occupancy/kv = 0.0fallbacks. 4 of the 5 named gaps now emit real values.Note on
kv_occupancy_bytes: still 0.0 in this run — honestly, not fabricated. TheMoE.generate()path uses HF's own KV cache (no MoE-Infinity KV manager), so the engine has nothing resident to report. The accessor is wired to report real KV occupancy when a KV-cache manager is present (continuous-batching/serving path).Verification
tests/python/dflash/test_native_stat_accessors.py(14) — accessor surface with_storefakes.tests/test_gpt_oss_offload_topology.py(+policy): 10 passed.ruff+ LSP clean on all changed files._storerebuilt forsm_120, new symbols import cleanly.Guardrails
Read-only accessors only; no GLM /
feat/dflash-spec-decode/ #119 touched; not on dev/main; DRAFT — do not merge.