feat: overlap-aware expert prefetch - #180
Open
drunkcoding wants to merge 10 commits into
Open
Conversation
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Contributor
Author
|
Momus plan review: [OKAY] on the first review round. |
Pure-Python deterministic overlap-budget controller: EWMA calibration, whole-expert greedy byte admission, cold-start cap, and exact-route correction accounting (coverage/waste/late/uncovered/cancel). No Torch/CUDA imports; fully CPU-testable. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Add default-off off|observe|enforce policy plus validated EWMA/safety/cold-start/window/inflight knobs and the shared gpu_only_expert_routing field. Reject gpu_only_expert_routing=True together with an active overlap policy in the first release. Document the formula, cold-start, fail-closed behavior, rollout, and cross-plan compatibility table. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Add IOProfiler.record() public instant-event API (dur_ns=0) that merges caller fields and rejects keys overwriting reserved event columns. Register overlap byte stages (prefetch_budget/admit/complete/cancel/late/waste) in ExpertTracer for consistent byte aggregation. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Add header-only PrefetchQueueAccounting value helper (GPU-free, unit-tested) with RemovalReason/RunningOutcome enums and a RunPrefetchTaskNoThrow noexcept worker boundary that retires bytes exactly once. Add Task generation/layer/bytes metadata, PrefetchAdmission/PrefetchSample structs, and thread-safe AdmitPrefetchTasks/CancelQueuedPrefetch/DrainPrefetchSamples/GetInflightPrefetchBytes pool APIs backed by the accounting helper. Bridge through ArcherPrefetchHandle with tensor-to-node dedupe and bind schedule_prefetch_tensors/cancel_prefetch_generation/drain_prefetch_samples/get_inflight_prefetch_bytes plus read-only value structs. Legacy prefetch_tensors behavior unchanged. Add opt-in MOE_BUILD_TESTS root build and a GPU-free GoogleTest for the accounting invariants. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Add testable ExpertTimingLifecycle (free/pending/quarantined state machine over a CudaTimingAdapter, GPU-free unit-tested) and wire dispatcher-owned, timing-enabled epoch/start/stop events around ForwardHelper only. MoEMLP::forward records kernel start/stop immediately around ForwardHelper (excluding input copy and syncs). GPUExecFunc lazily creates per-worker timing objects after cudaSetDevice only when the atomic enable flag is set, brackets forward, captures separate host forward-return/output-complete steady-clock delays, polls pending stops between work items, and quarantines exception pairs behind a same-stream fence until a query or stream sync proves completion. Every ExpertComputeSample carries a nonzero invocation id threaded through CallArgs/ExecArgs via set_inputs_with_invocation. Bind set_inputs_with_invocation/set_overlap_compute_timing_enabled/drain_compute_samples and the read-only expert_compute_sample struct; legacy set_inputs unchanged. Add the GPU-free lifecycle GoogleTest and an opt-in native compute-sample smoke test. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Give ExpertPrefetcher an overlap controller, a NativeOverlapCapabilities adapter, exact byte costing, and native admission/cancellation/telemetry bridges (plan_candidates, correct_to_native_route, abort_prefetch_generations, drain_native_prefetch_samples, observe_compute_samples, record_stale_compute_samples, overlap_prefetch_stats). configure_overlap_policy leaves off byte-for-byte, enables dispatcher timing only when the full capability set is present, records a capability miss under observe on an older extension while keeping legacy issuance, and fails closed under enforce. Add ExpertPredictor.ranked_candidates. Configure the policy in model_offload right after the exact byte map is registered. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Apply exact-route correction before every expert enqueue and budget exact-route warming through plan_candidates on the supported eager path, pinning and reporting only admitted experts while the full native union is still dispatched. Thread a per-dispatch invocation id via set_inputs_with_invocation when the dispatcher timing capability is complete, else legacy set_inputs. Extend _pending_prefetch to carry owned generations and the invocation id; _maybe_route_ahead_prefetch returns (fired, generations). Restructure wait_dispatch_local so pending state is detached before waiting and all policy cleanup runs in finalize_policy: cancel owned generations on wait error, accept only the exact (invocation_id, layer_id) compute samples (counting the rest as stale), correct/re-trigger on success, and always drain native samples in finally without masking the original wait error. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Add bench_overlap_prefetch.py: a pure build_report that derives coverage/waste/late ratios and p50/p95 latency, enforces the byte invariants (completed<=admitted, covered<=route, late<=route, wasted<=completed), and labels the result MEASURED with no speedup key; plus a paired off|observe|enforce CUDA driver that runs each policy in a separate process, resets the cache between arms, and compares output ids exactly against the off oracle. Extend run_decision_profile.py with --overlap-prefetch-policy and knob flags and append overlap_prefetch_stats; add run_all.py --scenario overlap that shells out without altering other scenarios. Document commands, interpretation, and the no-speedup promise; add the CPU-only report-gate test. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Document the staged off->observe->enforce rollout per model/hardware pair, config-only rollback (set overlap_prefetch_policy=off and restart; deploy the prior package if the extension is suspect), rollback triggers, and the full risk/detection/mitigation table in docs/configuration.md. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Contributor
Author
|
Independent implementation verification:
PR remains draft for native/CUDA maintainer review. |
drunkcoding
marked this pull request as ready for review
September 2, 2026 21:53
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.
Description
Implements the Momus-approved overlap-aware expert prefetch plan
(
docs/superpowers/plans/2026-08-21-overlap-aware-expert-prefetch.md). Admitsspeculative expert transfers only when their exact stored bytes fit a
conservatively calibrated transfer window derived from measured bandwidth and
the current layer's measured compute time. The native router, expert weights,
and dispatched expert set remain authoritative — budgeting applies only to early
cache warming.
What landed (9 atomic commits, strict TDD)
moe_infinity/memory/overlap_budget.py): pureEWMA calibration, whole-expert greedy byte admission, cold-start cap, and
exact-route correction accounting (coverage/waste/late/uncovered/cancel).
overlap_prefetch_policy=off|observe|enforce+ knobs andthe shared
gpu_only_expert_routingfield) with fail-closed validation.PrefetchQueueAccountingvalue helper(GPU-free, unit-tested),
RemovalReason/RunningOutcomeenums, aRunPrefetchTaskNoThrowworker boundary, and thread-safeadmit/cancel/drain/inflight pool + handle + pybind APIs. Legacy
prefetch_tensorsunchanged.ExpertTimingLifecycle(free/pending/quarantined over a CUDA adapter) plus dispatcher-owned
timing-enabled epoch/start/stop events bracketing
ForwardHelperonly,nonzero invocation ids, and
set_inputs_with_invocation/set_overlap_compute_timing_enabled/drain_compute_samplesbindings.exact byte costing, exact-route correction before every enqueue, one-layer
admitted-only pinning, and
(invocation_id, layer_id)-exact calibration witherror/finally cleanup that never masks a
wait_experterror.IOProfiler.record()instant events and overlap bytestages in
ExpertTracer.off|observe|enforcebench_overlap_prefetch.pywith a purebuild_report,run_all --scenario overlap, andrun_decision_profile --overlap-prefetch-policy.staged rollout/rollback, and the risk/mitigation table.
Verification
speculative-prefetch, route-ahead wire/metrics, report, output-equivalence,
qwen3.5 rollback).
PrefetchQueueAccounting(5) andExpertTimingLifecycle(5) via the opt-inMOE_BUILD_TESTSroot build.prefetch_op,--whole-archiveoverarcher_core) buildsand links cleanly with all new bindings.
MOE_DFLASH_SERVING_GPU.Dependencies / limitations
Independently implementable on eager routing. First-release co-enablement with
GPU-only routing is rejected until route-ready ordering is reconciled;
ArcherConfigraises whengpu_only_expert_routing=Trueis combined with anactive overlap policy.
Type of Change
Performance / support evidence
with no speedup claim.
Checklist