Skip to content

perf(offload): event-driven tier-load wait ahead of schedule() (no fixed timeout, on by default) - #3772

Open
ZhangLirong-amd wants to merge 8 commits into
mainfrom
lirzhang/offload-prestart-load-overlap
Open

ZhangLirong-amd wants to merge 8 commits into
mainfrom
lirzhang/offload-prestart-load-overlap

Conversation

@ZhangLirong-amd

@ZhangLirong-amd ZhangLirong-amd commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This PR overlaps offload-tier loads (Mooncake Store and other supports_early_load connectors) with scheduling. The engine finds out that a load finished through a doorbell event, so it no longer waits a fixed time.

It replaces the earlier revision of this PR, which used a 20 ms bounded poll and role-based defaults. That revision had no doorbell, used a hard-coded wait and special-cased roles and the delayer. All of that is gone.

  • One env var: ATOM_OFFLOAD_LOAD_EVENT_WAIT (bool). Default 1 (on). 0 brings back main's step exactly.
  • No tuning constant. A step waits at most tick * gain / (max(1, cost) * dp_size), and never more than one tick. tick is the measured wall time of this engine's last forward.
  • A wake-up, not a sleep. A worker rings a doorbell as soon as a load job ends. The engine blocks on that event and continues as soon as every load it started has landed.
  • Without an early-loading offload tier, nothing changes. No load starts, so no step waits. A decode instance and a plain P/D transfer connector are unaffected.

On 1P1D AgentX c256, TTFT mean drops 20.2% and P90 drops 24.9%. ITL is flat (−1.0%) and throughput is +0.6%. Full results are below.

Problem

The early tier load inside schedule() (_early_load_tier_prefixes) parks a waiting request that has a tier hit. Its load leaves with step N's batch and lands within milliseconds. But the engine reads load completions only after forward N returns (_poll_kv_transfer_progress, the pipelined async_proc_aggregation query). That read returns a snapshot taken before forward N, so the request prefills in forward N+1 at the earliest and often in N+2. On a busy P, one forward is a few hundred milliseconds of TTFT.

Design

1. Pre-phase ahead of schedule() (EngineCore._prestart_tier_loads_and_wait)

  • Scheduler.prestart_tier_loads() runs this tick's early tier load ahead of time. It uses the same lookup prefetch (_prefetch_waiting_lookups), the same _early_load_tier_prefixes and the same KV-pressure bounds. The step's _schedule() then skips its own pass (_early_load_prestarted), so the per-tick caps and the retry/prune cadence still apply once per engine step. State loads it queued are published right away (_publish_state_loads).
  • Not while a decode is running (_has_running_decode). The pre-phase allocates, and a running decode's page reservation (reserved_decode_blocks) is installed only inside _schedule(). This is an allocation-order correctness constraint, not a tuning choice. On such a step, _schedule() runs its own early load behind the reservation, exactly as on main.
  • The loads that were started ship at once (_ship_connector_meta).

2. Event source: the KV progress doorbell (atom/kv_transfer/progress_doorbell.py, new)

  • Who rings it: the offload load pool is now a LoadExecutor (_offload_common.py). Each job's future rings when the job ends, after _done_load / _failed_load is recorded. Dense, kv_store and dsv4 loads all go through this pool.
  • How it reaches the engine: the worker (AsyncIOProc) puts a string marker on its existing KV output channel. The engine's process_kv_output_sockets sees the marker and only sets kv_doorbell_event. The marker never enters the aggregation queue, so the protocol (one outstanding query, drain-once answers, TP quorum in KVOutputAggregator) is unchanged.
  • Coalescing: after one ring, the next ring waits until the worker answers a completion query. rearm() runs before get_finished() in async_proc_aggregation, so a burst of completions costs one message and none is lost.
  • In the engine process: a finished Store lease renewal (ATOM_STORE_ASYNC_RENEW, AsyncStoreLookup.renew_async) rings the same event. The wait loop then ships the GET that the renewal released.

3. Wait bound (LoadWaitState.budget_s over Scheduler.load_wait_tradeoff)

  • gain: the started loads still in flight that this step could still admit, meaning a free slot and enough token budget after the prefill ahead of them.
  • cost: the requests this step carries anyway. That is all of running, plus the admittable waiters ahead of the last admittable target.
  • Holding pays while wait < tick * gain / (cost * dp_size). DP peers reach the forward collective later by up to the same amount, hence the dp_size factor. The bound is capped at one tick: past that, the held request is no earlier than without the hold.
  • A cold engine (no forward yet) has tick = 0 and never holds. A step with running decodes has cost ≥ the decode batch, so the bound goes to ~0. No special case is needed for role or delayer.

4. Wait loop (EngineCore._wait_for_loads)

The loop blocks on the doorbell. After a ring, it fetches a completion answer that was requested after the ring, then ships any released loads. It returns once every started load has landed or the bound has passed. A load that misses the bound rides the forward as before. A failed load reports through the same answer and falls back to prefill. No collective runs here and the step count is unchanged, so DP lockstep holds.

Counters

Each rank logs one [LOAD-WAIT] line per minute: steps loads skipped waits landed timed_out wakes avg_wait max_wait avg_bound tick.

Scope

The pre-phase runs in EngineCore and DPEngineCoreProc, not in PPEngineCoreProc or the RapidServe cores.

Results

DeepSeek-V4.1-Flash on MI355X. 1P1D on one node: P DEP4 (GPU 0-3, Mooncake Store on P) and D DEP4 (GPU 4-7). AgentX scenario, c256, 900 s window, warmup 10, seed 42. Every arm was a cold start of P, D and Store. Both arms used the same image and the same ATOM tree, and only ATOM_OFFLOAD_LOAD_EVENT_WAIT differed (A = 0, B = 1).

metric A (=0) B (=1) Δ
TTFT mean (ms) 584.5 466.2 −20.2%
TTFT P50 (ms) 450.6 348.9 −22.6%
TTFT P90 (ms) 967.7 727.1 −24.9%
TTFT P99 (ms) 3393 3008 −11.3%
ITL mean (ms) 5.742 5.683 −1.03%
ITL P90 (ms) 7.405 7.365 −0.5%
total tok/s 1,400,966 1,408,652 +0.55%
errors 0 0

B's [LOAD-WAIT] counters on P over the window: 3360 waits, 308 timed out (9.2%), average wait 8.56 ms against an average bound of 39.1 ms, 3955 doorbell wakes. The average wait is a fraction of the bound, which shows the event wake ends the hold rather than the bound.

Limitations:

  • One run per arm, with no repeated A arm as a noise control. In the A window, D compiled 7 times (B: 0). Per minute, B's TTFT is lower than A's throughout the window.
  • Measured on 1P1D c256 only. 4P8D c512, an aggregated Store server and the prefill delayer kept on have not been measured with this revision. The design covers those cases by the same rule (see "Wait bound"), but there is no GPU number for them yet.

Risks

  • Fork-checkpoint pin window (existing on main). StateSlotPool.pin / release_pins keep a pin for one pass. A parked reader's fork source can be overwritten before its forward reads it, both on main and here. When a load misses the hold, the pre-phase widens that window by one pass. PAGE checkpoints are unaffected. The real fix is to keep a parked reader's fork pin until its forward is issued, which belongs in a separate issue against the early-load path.
  • dp_size approximation. Peer cost is approximated as cost * dp_size, which is conservative when peers carry fewer requests. In the A/B, 9.2% of holds hit the bound.

Tests

CPU only (rocm/atom-dev:nightly_202611250801-perf without GPU devices, PYTHONPATH set to this branch).

  • tests/test_offload_load_event_wait.py (new, 26 cases) covers these cases:
    • a load that already landed, a load that lands during the hold (doorbell, not the bound), a load that misses the bound, and a failed load;
    • running decodes (the bound goes to ~0, and test_no_pre_phase_load_while_a_decode_is_running), and a prefill-only step;
    • several loads, including one that misses the bound and does not hold back one that landed;
    • a cold start, abort during the hold, and the off step unchanged;
    • one prefetch and one early-load pass per step (on and off), and a state load shipping with the first build;
    • the bound formula, including DP scaling and the one-tick cap;
    • doorbell coalescing, rearm, and a failed send that does not silence the doorbell;
    • the marker over real zmq, without entering aggregation;
    • an ATOM_STORE_ASYNC_RENEW renewal finishing mid-hold, with a real MooncakeStoreOffloadScheduler.
  • tests/test_envs.py: the default is on, and 0 / off / empty turn it off. The offload doc check now covers ATOM_OFFLOAD_* and ATOM_STORE_*.
  • Regression set (scheduler, engine, envs, mooncake_store, dp, kv, offload, pd, otel_scheduler, prefill, lmcache, load, async, early, collective_rpc, throughput, pause and rollout tests, 99 files): 4133 passed / 23 failed / 34 skipped on this branch, and 4103 / 23 / 34 on main 6180dbcff with the same container and file set. The 23 failures are the same on both sides. They are all in test_scheduler_metrics.py and come from the Prometheus multiprocess environment in a shared run: that file passes 43/43 when run alone. The +30 passes are the new cases.
  • Black and Ruff are clean on the changed files.

Copilot AI balanced review requested due to automatic review settings November 24, 2026 06:36
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every eligible PR before approval:

  • ✅ Pre Checkin: Black, Ruff, catalog schema validation, non-GPU unit tests

Heavy model tests:

  • ✅ Gate checks are published on every PR so required checks do not stay missing
  • ✅ Expensive jobs run only after the PR is approved, or when a matching ci:* label is present
  • ✅ Pre Checkin must pass before approved heavy jobs continue
  • ✅ Without a matching label, expensive jobs also require a relevant path
  • ✅ A matching ci:* label is an explicit request and can open the gate even when paths would otherwise skip it

Path scope:

  • Native ATOM, vLLM, and SGLang use ignore lists: docs/markdown and unrelated plugin or Mesh paths are skipped
  • ATOMesh uses an include list: Mesh code, the ATOMesh accuracy workflow and its 1P1D launcher, plus the shared models_accuracy.json and accuracy_to_dashboard.py. ATOMesh benchmarks run after merge or on dispatch, not on PRs
  • Relevant path alone does not start expensive jobs; approval still opens the automatic path-scoped gate
Label Tests
ci:full Run all heavy PR model tests: native ATOM, vLLM, SGLang, and ATOMesh
ci:atom Run native ATOM model accuracy tests
ci:vllm Run ATOM vLLM OOT model accuracy tests
ci:sglang Run ATOM SGLang model accuracy tests
ci:mesh Run the ATOMesh accuracy tests, standalone and 1P1D, for Mesh-related changes

Without a matching ci:* label, heavy jobs are skipped when the path is not relevant or the PR is not approved.
Add labels via the sidebar or gh pr edit 3772 --add-label <label>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The wait loop only polls workers, so loads blocked on lease renewal remain undispatched even when renewal finishes within the window, delaying execution and missing same-step prefill.

1 open issue
What changed in this PR

Adds opt-in early dispatch and bounded waiting for offload-tier loads, allowing restored requests to prefill in the same engine step rather than waiting for the next forward pass.

Changes:

  • Starts eligible tier loads before scheduling and waits only when request slots and token budget permit.
  • Adds ATOM_OFFLOAD_PRESTART_LOAD_WAIT_MS, defaulting to 0 to preserve existing behavior, plus per-rank overlap counters.
  • Adds CPU tests for same-step admission, timeouts, failures, abort cleanup, ordering, and disabled behavior.
File Description
tests/​test_load_forward_overlap.py Adds engine and scheduler tests for early-load overlap and fallback behavior.
atom/​utils/​envs.py Registers the non-negative wait-window setting, disabled by default.
atom/​model_engine/​scheduler.py Adds early-load preparation and a budget-aware wait gate.
atom/​model_engine/​engine_core.py Dispatches loads before scheduling, polls within the wait window, and logs overlap statistics.

Review effort: Balanced

Comment thread atom/model_engine/engine_core.py Resolved

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few small things..

4P4D AgentX A/B: exact serving command line and ROCm version?

ci green.

Comment thread atom/utils/envs.py Resolved
Comment thread atom/model_engine/scheduler.py Resolved
Comment thread atom/model_engine/engine_core.py Resolved
Copilot AI balanced review requested due to automatic review settings November 24, 2026 09:08
@ZhangLirong-amd

Copy link
Copy Markdown
Collaborator Author

@valar-cop thanks. Serving setup for the 4P4D AgentX A/B. Both hosts used the same setup, and only ATOM_OFFLOAD_PRESTART_LOAD_WAIT_MS differed between arms (P only).

ROCm / image: rocm/atom-dev nightly 2026-11-22 (base rocm/pytorch:rocm7.2.4_ubuntu24.04_py3.12_pytorch_release_2.10.0, i.e. ROCm 7.2.4, PyTorch 2.10.0+rocm7.2.4), MI355X. ATOM on P was an earlier main commit (cccc96a) + #3187 + this patch. D ran the same tree without this patch.

P (GPUs 0-3). Env: ATOM_OFFLOAD_PRESTART_LOAD_WAIT_MS={0|20|40} ATOM_ENABLE_PREFILL_DELAYER=0 OFFLOAD_LOAD_WORKERS=1 OFFLOAD_PROFILE=1 ATOM_MONO_ENABLE=1 ATOM_FRONTEND_PREFIX_HASH=1 ATOM_DP_SESSION_AFFINITY=0 ATOM_DSV41_MOE_FP8_ACTIVATIONS=0 ATOM_DSPARK_DISABLE_COMPILE=1 ATOM_USE_CUSTOM_ALL_GATHER=0 ATOM_MOONCAKE_MATCHED_RAILS=auto

python3 -m atom.entrypoints.openai_server --model DeepSeek-V4.1-Flash --trust-remote-code \
  -tp 4 --enable-dp-attention --enable-expert-parallel --moe-backend mega --all2all-backend high-throughput \
  --dp-load-balance share_cache --kv_cache_dtype fp8 --index-cache-dtype fp4 --gpu-memory-utilization 0.9 \
  --max-num-seqs 128 --max-num-batched-tokens 16384 --attn-prefill-chunk-size 16384 --long-prefill-token-threshold 8192 \
  --enable_prefix_caching --block-size 16 --state-checkpoint-interval-tokens 8192 \
  --level 3 --cudagraph-mode FULL --cudagraph-capture-sizes [1,2,4,8,16,24,32,48,64,96,128] \
  --method dspark --num-speculative-tokens 5 --dspark-config '{"confidence_schedule":false}' --spec-decode-acceptance-length 3.51 \
  --tool-call-parser dsml_v41 --disable-uvicorn-access-log \
  --kv-transfer-config '{"kv_connector":"multi","connectors":[
     {"kv_connector":"mooncake","kv_role":"kv_producer","protocol":"rdma", ...},
     {"kv_connector":"mooncake_store","kv_role":"offload","kv_connector_extra_config":{
        "mooncake_store.protocol":"rdma","mooncake_store.rdma_devices":"rdma0,rdma1,rdma2,rdma3",
        "mooncake_store.owner_rdma_devices":"rdma7","mooncake_store.load_pool_mib":1024,"mooncake_store.save_pool_mib":1024, ...}}]}'

D (GPUs 4-7): the same model, spec-decode and cache flags, with --moe-backend standard --dp-load-balance least_requests --max-num-batched-tokens 1024 --attn-prefill-chunk-size 32768 and {"kv_connector":"mooncake","kv_role":"kv_consumer","protocol":"rdma"}.

Router: atomesh launch --pd-disaggregation --prefill-policy cache_aware --decode-policy cache_aware --cache-threshold 1.0 --balance-abs-threshold 0 --balance-rel-threshold 1.0 --backend atom.

Client: AgentX trace replay at concurrency 256, 900 s measurement window, warm JIT cache (0 compiles in the window).

Addresses, ports and Mooncake master/metadata endpoints are omitted (...).

The review threads are addressed in 791e92b (renewal-parked loads shipped during the wait, one early-load pass per step, docs row + doc test).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

tests/test_load_forward_overlap.py omits the ATOM Project Contributors copyright notice required for every new source file.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Low severity Add required copyright notice to new test file

tests/​test_load_forward_overlap.py:2

The new test file omits the ATOM Project Contributors copyright notice required for every new source file by CLAUDE.md:194–199. Add the third header line so this file meets the repository's explicit header requirement.

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 24, 2026 09:33
@ZhangLirong-amd

Copy link
Copy Markdown
Collaborator Author

Copilot's note on the missing ATOM Project Contributors line: added the full three-line header to tests/test_load_forward_overlap.py in 95b89e3.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block approval of the opt-in early offload loading change.

No open issues 🎉

Review effort: Balanced

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some changes needed..

ci Run non-GPU unit tests failed — looks like the pr itself (medium): The captured log is empty, so the failure line itself is unread. Code reading shows the only new CPU-path code this job runs is the renewal test, which constructs MooncakeStoreOffloadScheduler and thus imports aiter; that module's autouse aiter_arch stub is not applied to a test in another file, and the runner has no aiter.

atom/kv_transfer/offload/kv_store/keys.py:99: from aiter import dtypes
tests/test_mooncake_store_offload.py: @pytest.fixture(autouse=True) def aiter_arch(...) # module-local, not applied here
pyproject.toml dependencies: aiter not listed; run_unit_tests.sh: 'no aiter/MoRIIO native libs'
next: Fix the new test to request the aiter_arch stub (or skip without aiter), then re-run Pre Checkin; the empty log should be re-fetched to confirm. https://github.com/ROCm/ATOM/actions/runs/45366388345/job/138349085526

Comment thread tests/test_load_forward_overlap.py Resolved
@ZhangLirong-amd

Copy link
Copy Markdown
Collaborator Author

CI: Run non-GPU unit tests failed on 95b89e3 in the new test_wait_ships_a_load_whose_renewal_finishes_in_the_window: the real MooncakeStoreOffloadScheduler resolves its namespace through AITER's dtype/arch query, and the CPU runner has no aiter. Reproduced locally with aiter made unimportable; fixed in c1722e6 by requesting test_mooncake_store_offload's aiter_arch fixture (fake AITER arch, as that module's own tests do). test_load_forward_overlap.py + test_mooncake_store_offload.py: 544 passed with and without aiter.

Copilot AI balanced review requested due to automatic review settings November 24, 2026 10:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The opt-in wait affects core distributed scheduling latency, while single-run benchmarks leave burst and P99 impacts unresolved, requiring maintainer review of the operational tradeoff before enabling the recommended P-side setting.

No open issues 🎉

Review effort: Balanced

@ZhangLirong-amd

Copy link
Copy Markdown
Collaborator Author

CI on c1722e6 is green, including Run non-GPU unit tests. Description updated: the GPU A/B numbers are marked as measured with the first revision (the review fixes in 791e92b were validated on CPU only and not yet re-measured on GPU), plus a Related section linking #3773, #3777, #3781 and the draft recipe #3759.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (5)

  1. Drop the getattr defaults that only test fakes need. atom/model_engine/engine_core.py:704 (getattr(self, "_prestart_load_wait_s", 0.0)), engine_core.py:798 (getattr(scheduler, "prestart_tier_loads", None) + its dead return), scheduler.py:2292 (getattr(self, "_early_load_prestarted", False)), scheduler.py:4550 (getattr(self.kv_connector, "supports_early_load", False)). Every production object sets these (EngineCore.__init__, Scheduler.__init__, connector base supports_early_load; the sibling at scheduler.py:4447 already reads it bare); a direct read only breaks SimpleNamespace/__new__ fakes (e.g. test_off_step_is_unchanged, test_pd_chunked_transfer, test_engine_core_kv_wait). Read the attributes directly and add _prestart_load_wait_s=0.0 to those fakes.
  2. Remove the copied guard and prefetch in prestart_tier_loads (scheduler.py:4546-4555). The connector/is_offload/supports_early_load guard repeats _early_load_tier_prefixes (scheduler.py:4444-4448), and the prefetch_lookups block copies _schedule (scheduler.py:2276-2282). Keep the not self.waiting early-out, and move the prefetch into one helper that both call. With the knob on, the prefetch then runs twice per step; you can skip the second call when _early_load_prestarted is set.
  3. Add tests for two wiring points that no test covers.
    • Removing self._publish_state_loads() (scheduler.py:4568) still passes all 18 tests. Add a test that a state load queued by the pre-phase goes out with the first build_connector_meta.
    • Setting _early_load_prestarted only when the pre-phase parked something also passes. Add a case to test_prestart_and_the_tick_share_one_early_load_pass where the pre-phase parks nothing and tick still advances exactly once.
  4. Say where the knob is ignored. The docs/environment_variables.md:487 row and the envs.py comment say "Each engine step first ...". In fact only the base/DP EngineCore step runs the pre-phase. PPEngineCoreProc (pp_engine_core.py:177), PrefillEngineCore and DecodeEngineCore never reach it.
  5. Re-measure on this head. All GPU numbers are from revision 1. 791e92b changed what a step does (a ship per poll pass, one early-load pass per step). Post a wait-0 vs wait-20 A/B on the current head, with a second wait-0 run as the noise control.

Question, not blocking: prestart_wait_worthwhile does not look at the prefill delayer. With the delayer or coalescing on, a step can wait up to N ms and then HOLD in schedule(), and under DP its peers wait too. Is that intended? If so, please document it in the row.

Checked, no change needed: flag-off behaviour is identical to main (two attribute reads per step), the pre-phase runs no collective, build_connector_meta is not double-consumed, an abort during the wait releases blocks, and all four earlier valar-cop/Copilot asks are fixed at head.


Reviewed at c1722e6 (Deep; 2 independent passes + cross-PR interaction pass, mutation runs). Already fixed: doc row + filter, single early-load pass, ship per poll, aiter_arch stub.

@valar-cop

valar-cop commented Nov 24, 2026 •

Copy link
Copy Markdown

@zufayu
zufayu requested a review from yitingw1 November 25, 2026 01:02
Copilot AI balanced review requested due to automatic review settings November 25, 2026 01:43
@ZhangLirong-amd

Copy link
Copy Markdown
Collaborator Author

@valarLip thanks. Pushed 22c75b7.

  1. getattr defaults: dropped. _prestart_load_wait_s, prestart_tier_loads and _early_load_prestarted are read directly (the dead return went with the probe). The fakes in test_off_step_is_unchanged, test_engine_core_kv_wait, test_pd_chunked_transfer and test_otel_scheduler now set _prestart_load_wait_s=0.0; the "engine built before the knob existed" case is removed.
  2. Copied guard and prefetch: prestart_tier_loads keeps only the not self.waiting early-out. The prefetch is now _prefetch_waiting_lookups(), called by _schedule and by the pre-phase; _schedule skips it together with its early-load pass when the pre-phase already ran them, so the prefetch runs once per step.
  3. Two new tests. test_a_state_load_queued_by_the_pre_phase_ships_with_its_first_build fails when self._publish_state_loads() is removed from the pre-phase. test_a_pre_phase_that_parks_nothing_is_still_the_steps_one_pass fails when _early_load_prestarted is set only after something parks (tick goes to 2). Both mutants were checked.
  4. Scope: the envs.py comment and the doc row now say the knob applies to the single-engine and DP loops (EngineCore, DPEngineCoreProc) and is ignored by PPEngineCoreProc and the RapidServe PrefillEngineCore/DecodeEngineCore.
  5. Re-measure: not done yet. This needs a 4P4D GPU run (wait-0 vs wait-20, plus a second wait-0 as the noise control). The description keeps the GPU numbers marked as revision 1.

Delayer question: yes, that is how it works, and it is now documented in the row. The wait does not consult the delayer, whose HOLD/FIRE is a DP collective inside schedule(). With the delayer on, a step can wait and then HOLD, and DP peers reach that collective up to the wait later. The landed load is then admitted by the next FIRE. The measured setup ran with ATOM_ENABLE_PREFILL_DELAYER=0.

CPU checks (v3 container): test_load_forward_overlap.py 20 passed. Regression over scheduler/engine/dp/env/mooncake/pd/load/offload/early/prefill/kv/pause/otel/sequence/entrypoints: 6,338 passed / 4 failed on the new head vs 6,336 / 4 on c1722e6, with the same 4 failures on both (entrypoints structured-output/chat-encoder, environment). Black and ruff are clean on the changed files.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

GPU validation covers only revision 1, so current-head dispatch and scheduling changes still need human confirmation of joint state/KV loading, DP lockstep, and latency impact.

No open issues 🎉

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The unconditional hook makes deployments without early-load support wait for fresh completion responses, potentially delaying scheduling by the previous forward’s duration even when load-wait holding is disabled.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread atom/kv_transfer/offload/load_wait.py Resolved
Copilot AI balanced review requested due to automatic review settings November 27, 2026 09:42
@ZhangLirong-amd

Copy link
Copy Markdown
Collaborator Author

@valarLip A follow-up on item 1 of round 5. The new head is 8196edf12, and the only change is the default of the hold. ATOM_OFFLOAD_LOAD_WAIT_HOLD is back on by default. The refactor from 80edded7f (the load_wait.py policy object and the generic step_hooks) is unchanged.

  • Why it stays on: the hold produced the measured gain. On 1P1D c256 (P DEP4 with Mooncake Store, D DEP4, AgentX), TTFT mean was −20.2% and throughput +0.55% (A/B in perf(offload): event-driven tier-load wait ahead of schedule() (no fixed timeout, on by default) #3772 (comment)). The doorbell-only path was never measured on its own.
  • DP peers: the bound already charges them. It is tick * gain / (cost * dp_size), capped at one tick, and ~0 while decodes run because the decode batch counts as cost.
  • Off switch: ATOM_OFFLOAD_LOAD_WAIT_HOLD=0 turns off only the hold; the doorbell and the fresh answer stay on. docs/environment_variables.md says to turn it off if a deployment shows an ITL or throughput loss. 4P8D and a DP aggregated Store server are still unmeasured.
  • Group-wide bound (carried on the per-step DP sync): still a possible follow-up.

Tests: test_offload_load_event_wait.py passes 34/34 in each of 3 runs. test_envs.py passes 134, covering default-on and the 0/off/empty opt-outs. Both the hold-on tests and the hold-off tests (test_hold_off_*) are kept. The related engine, scheduler and Store files pass 736, with 6 skipped. black and ruff are clean.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The wait hook runs for offload connectors without early-load support, potentially blocking scheduling for an entire previous-forward tick and adding latency to deployments intended to remain unaffected.

1 open issue

Review effort: Balanced

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (2)

Thanks, the refactor is what we asked for. load_wait.py holds the whole wait. EngineCore gains only the generic step_hooks tuple and the _collect_kv_transfer_progress split, Scheduler keeps one take_tick_pass() branch over EarlyLoadState, AsyncIOProc has no env branch, ModelRunner is back to main, and only a generic step_hooks=() remains in one fake. rearm in get_finished and the on_forward_done tick are both covered (each fails a test when removed). The renewal alarm fixes the Copilot thread. Two items remain:

  1. The hold is back on by default, and its bound still ignores the DP peers (round 5 #1). Your 1P1D A/B (TTFT -20%) ran on a P instance, where no rank has a decode, so it does not exercise the hazard. The hazard is a DP aggregated Store server, which the default now reaches:

    • budget_s (load_wait.py:62-76) uses this rank's cost. A rank with no decode of its own and a fresh Store hit gets cost = 0 and holds for min(tick, tick / dp_size). Its peers' running decodes wait at the forward collective for that long, and the wait adds to their ITL.
    • tick_s is updated only after a real forward (engine_core.py:717). _execute_dummy_batch (engine_core.py:1392) calls no hook, so an idle rank keeps the tick of its last real forward, often a long prefill. With dp=8, a 500 ms prefill tick gives a 62.5 ms hold, while a fresh 30 ms tick gives 3.8 ms.

    Please do (a): call on_forward_done after the dummy forward as well (its time is the group's real step), and carry "any rank has a running decode" on the existing _sync_dp_state reduction (no new collective), so the hold is ~0 while any peer decodes. That keeps your measured gain on P. Otherwise do (b): leave the hold off by default until (a) lands or an aggregated DP Store run shows no ITL loss.

  2. The wait also runs on offload tiers without early load (open Copilot thread load_wait.py:374). LoadExecutor is the load pool of every OffloadWorkerMixin (dense and DSV4 offload too), and load_wait_hook installs the hook whenever KV transfer is on. On a tier with supports_early_load = False, every ring makes before_schedule wait for a fresh answer (at least one query round trip, bounded by one tick) and ship connector meta outside a batch. The env row says the feature is "inert without an offload tier that loads early", which is not true at head. Please return None from load_wait_hook unless engine.scheduler.kv_connector.supports_early_load (the scheduler exists before the hooks are built), and add a test for a dense connector.

Root cause vs patch

Root problem: a load completion reaches schedule() only through the pipelined query answered after forward N. The doorbell plus a fresh answer before schedule() fixes that with no knob. Holding the step to turn N+1 into N is a policy trade-off that every DP peer pays, so its bound has to see the group (item 1). Verdict: right direction with patch-like parts.

Prior asks: round 5 #2 (shared classes) and #3 (Copilot renewal thread) are fixed. Round 5 #1 is open; see item 1. Rounds 3-4 still hold.


Reviewed at 8196edf (round 6, passes A+B; true delta = old head replayed on b4ca7b9 vs head, mutants for rearm, on_forward_done and the before_schedule loop, DP dummy-path read, budget probe, dense-connector probe, 180 CPU tests). Already fixed: shared-class state, patched fakes, renewal-timeout wake, fork-pin thread, squash text.

ZhangLirong-amd added a commit that referenced this pull request Nov 27, 2026
… for early-load tiers

Review round 6 (#3772), items 1 and 2. The hold stays on by default.

Item 1 (option a): the hold's bound now sees the DP group.
- DPEngineCoreProc._execute_dummy_batch calls the step hooks'
  on_forward_done with the dummy forward's wall time, so an idle rank's tick
  is the group's step, not its own last (often long prefill) forward.
- _sync_dp_state sends a fifth flag on its existing MAX all_reduce, this
  rank's Scheduler.has_running_decode(), and keeps the reduced value as
  dp_group_decoding (no new collective; kept between syncs).
- LoadWaitState.budget_s(..., group_decoding=True) returns 0: while any rank
  decodes, a hold would add to that decode's ITL at the next collective.
  With no decode anywhere (a P/D prefill instance, the measured case) the
  bound is unchanged.

Item 2: load_wait_hook returns None unless the engine's KV connector has an
offload tier that loads early (supports_early_load: Mooncake Store), so a
dense or DSV4 offload tier, whose LoadExecutor also rings the doorbell, gets
no hook. Env and docs rows say so instead of "inert".

Tests: dummy forward updates the tick; a peer decode makes the budget 0 and
keeps a step from holding; a prefill-only group keeps the hold and its bound;
_sync_dp_state carries any rank's decode; no hook for a dense / missing
connector. The two _sync_dp_state tests follow the five-flag payload.
Copilot AI balanced review requested due to automatic review settings November 27, 2026 12:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because the load-wait estimate can omit completed parked work, allowing a full-tick hold that delays ready requests and data-parallel peers without advancing the new load.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@ZhangLirong-amd

Copy link
Copy Markdown
Collaborator Author

@valarLip thanks. Both items are in 6a45755. The hold stays on by default.

1. Option (a): the bound sees the DP group.

  • Change:
    • DPEngineCoreProc._execute_dummy_batch now calls the step hooks' on_forward_done with the dummy forward's wall time, so an idle rank's tick_s is the group's step, not its last prefill.
    • _sync_dp_state sends a fifth flag on its existing MAX all_reduce: this rank's Scheduler.has_running_decode(). It keeps the reduced value as dp_group_decoding. There is no new collective. Under ATOM_DP_SYNC_INTERVAL>1 the last synced value holds between syncs.
    • LoadWaitState.budget_s(..., group_decoding=True) returns 0, so no rank holds while any rank of the group decodes. With no decode anywhere (a P instance, the measured case) the bound is unchanged.
  • Tests:
    • test_dp_dummy_forward_updates_the_tick
    • test_a_peer_decode_makes_the_hold_budget_zero
    • test_a_peer_decode_keeps_the_step_from_holding
    • test_prefill_only_group_keeps_the_hold_and_its_bound (it holds, bound tick / dp as before)
    • test_sync_dp_state_carries_any_rank_decoding
    • The two existing _sync_dp_state tests now expect the five-flag payload.

2. No hook without an early-load tier.

  • Change: load_wait_hook returns None unless engine.scheduler.kv_connector.supports_early_load (also None with no connector). The env comment and docs row now say the hook is installed only for such a tier, instead of "inert".
  • Tests:
    • test_no_hook_without_an_offload_tier_that_loads_early[dense|none]: kv_transfer_step_hooks returns () and the doorbell is not installed.
    • test_dense_offload_connector_gets_no_hook: real scheduler, supports_early_load False then True.

CPU results, against 8196edf:

  • tests/test_offload_load_event_wait.py: 42 passed, three runs (was 34).
  • Related suites (engine, dp, scheduler, offload, lmcache, mooncake store, pd chunked, envs): 2820 passed against 2812. The same single failure is on both heads.
  • black and ruff are clean.

A/B on 1P1D c256 (900 s, P DEP4 + D DEP4, Mooncake Store on P): TTFT mean -20.2%, P90 -24.9%, ITL mean -1.0%, throughput +0.6%, 0 errors. The bound needs no tuning (tick * gain / (cost * dp_size), at most one forward): a running decode drives it to ~0 and a cold engine never holds, and without an offload tier that loads early nothing is started, so nothing waits. ATOM_OFFLOAD_LOAD_EVENT_WAIT=0 restores main's step.
With ATOM_STORE_ASYNC_RENEW, a lease renewal that stalls rings no doorbell,
yet from RENEW_TIMEOUT_S on its load may be dispatched ("timeout"). An engine
holding its step for that load (EngineCore._wait_for_loads) then slept to the
hold's bound. AsyncStoreLookup now arms one shared alarm thread per renewal
that rings the KV progress doorbell at the renewal's timeout if it is still
unfinished; the hold wakes, ships the released GET and ends on its landing.

Test: test_renewal_stalled_past_its_timeout_wakes_the_hold_and_ships_the_load
(fails without the fix: the hold runs to its 2 s bound).
… off by default

Review round 5 (#3772), items 1 and 2.

Item 1: the hold's bound is rank-local while its cost lands on every DP
peer. The doorbell and the fresh completion answer before schedule() stay
on by default (ATOM_OFFLOAD_LOAD_EVENT_WAIT); the hold itself moves behind
ATOM_OFFLOAD_LOAD_WAIT_HOLD, off by default, to be enabled only once it is
group-aware or measured with the prefill delayer on and in 4P8D. Without
the hold, a doorbell makes the next step fetch one answer requested after
the ring before schedule() (a query round trip, bounded by one tick).

Item 2: no load-wait state on the shared classes.
- atom/kv_transfer/offload/load_wait.py owns everything: LoadWaitState,
  prestart_tier_loads, load_wait_tradeoff and OffloadLoadWait, the step hook.
- EngineCore keeps a generic step_hooks tuple (before_schedule /
  on_forward_done) built by atom/kv_transfer/engine_step_hooks.py.
- Scheduler loses _early_load_prestarted, prestart_tier_loads and
  load_wait_tradeoff; the once-per-tick flag lives in EarlyLoadState.
- AsyncIOProcManager loses kv_doorbell_event and kv_aggregation_started_at:
  a worker's marker rings the engine's doorbell, which sets the existing
  kv_progress_event; the hook tells a ring from other wakes by its count.
- AsyncIOProc installs the doorbell sender without an env branch; the
  offload worker picks LoadExecutor by env and rearms in get_finished;
  ModelRunner is back to main.

Tests: tests/test_offload_load_event_wait.py adapted (hold tests run with
the hold on), plus default-mode, hook-env, worker-rearm and shared-class
tests; the test fakes outside it are back to main except one generic
step_hooks=().
ATOM_OFFLOAD_LOAD_WAIT_HOLD now defaults to 1; `0` turns it off and keeps
the doorbell and the fresh answer before schedule().

The hold is the part measured at 1P1D c256 (P DEP4 with Mooncake Store,
D DEP4, AgentX): TTFT mean -20.2%, throughput +0.55%. Its bound already
charges the DP peers it delays: tick * gain / (cost * dp_size), never more
than one tick and ~0 while decodes run.

The load_wait.py policy object and the generic engine step hooks are
unchanged. Docs, the recipe note, test_envs and the hook-env test follow
the new default; the hold-off tests are renamed test_hold_off_*.
… for early-load tiers

Review round 6 (#3772), items 1 and 2. The hold stays on by default.

Item 1 (option a): the hold's bound now sees the DP group.
- DPEngineCoreProc._execute_dummy_batch calls the step hooks'
  on_forward_done with the dummy forward's wall time, so an idle rank's tick
  is the group's step, not its own last (often long prefill) forward.
- _sync_dp_state sends a fifth flag on its existing MAX all_reduce, this
  rank's Scheduler.has_running_decode(), and keeps the reduced value as
  dp_group_decoding (no new collective; kept between syncs).
- LoadWaitState.budget_s(..., group_decoding=True) returns 0: while any rank
  decodes, a hold would add to that decode's ITL at the next collective.
  With no decode anywhere (a P/D prefill instance, the measured case) the
  bound is unchanged.

Item 2: load_wait_hook returns None unless the engine's KV connector has an
offload tier that loads early (supports_early_load: Mooncake Store), so a
dense or DSV4 offload tier, whose LoadExecutor also rings the doorbell, gets
no hook. Env and docs rows say so instead of "inert".

Tests: dummy forward updates the tick; a peer decode makes the budget 0 and
keeps a step from holding; a prefill-only group keeps the hold and its bound;
_sync_dp_state carries any rank's decode; no hook for a dense / missing
connector. The two _sync_dp_state tests follow the five-flag payload.
@ZhangLirong-amd
ZhangLirong-amd force-pushed the lirzhang/offload-prestart-load-overlap branch from 6a45755 to cacc8b4 Compare November 27, 2026 13:45
Copilot AI balanced review requested due to automatic review settings November 27, 2026 13:45
@ZhangLirong-amd

Copy link
Copy Markdown
Collaborator Author

Rebased onto main a69d2bb (new head cacc8b4; old head kept as lirzhang/offload-prestart-load-overlap-old-20261127b).

Conflicts: atom/model_engine/engine_core.py, tests/test_pd_chunked_transfer.py, tests/test_offload_load_event_wait.py, all from #3672 renaming EngineCore._kv_progress_event to _wake_event (now also set by every input put and waited on by the idle loop's _wait_for_input). Resolved by keeping main's code and moving the PR onto _wake_event (load_wait.py doorbell install and waits, tests). No logic change: hold stays on by default, the doorbell and the DP-group dp_group_decoding flag are unchanged. The idle loop clearing _wake_event cannot drop a ring, since the hook reads the doorbell's ring count, not the event.

CPU tests (rocm/atom-dev container, same node, main vs this head): test_offload_load_event_wait.py 42 passed; envs/engine_core/dp/pd_chunked 339 passed (main 331); broad engine/scheduler/offload/mooncake/pd/kv/dp/lmcache suites 4158 passed vs 4108 on main, identical 8 failed + 1 collection error on both (test_scheduler_metrics, test_qwen4_exp_offload), no new failures. black/ruff clean.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An older query response can complete all loads yet still trigger unnecessary waiting, delaying the forward pass and data-parallel peers; recheck _still_loading before waiting and add regression coverage.

1 open issue

Review effort: Balanced

Comment thread atom/kv_transfer/offload/load_wait.py Resolved

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (1 Nit)

Thanks, both round-6 items are done the way we asked.

  1. The DP-group-aware hold is fixed, option (a).
    • _execute_dummy_batch now times the dummy forward and calls on_forward_done, so an idle rank measures the group's step.

    • _sync_dp_state carries has_running_decode() as a fifth flag on the same MAX all_reduce. Every rank sends five, so there is still one collective.

    • budget_s(..., group_decoding=True) returns 0, so no rank holds while any peer decodes.

    • The flag is reduced in the same round, before before_schedule reads it. Under ATOM_DP_SYNC_INTERVAL>1 it can be up to N-1 rounds stale, but each held step stays capped at one tick, and the docs say so.

    • Every scheduler a DPEngineCoreProc can own has has_running_decode. PrefillScheduler only serves PrefillEngineCore, which never syncs.

    • Each wire is guarded by a test that fails when it is removed:

      Removed Test that fails
      dummy-forward tick test_dp_dummy_forward_updates_the_tick
      group_decoding test_a_peer_decode_keeps_the_step_from_holding
      fifth all_reduce flag test_sync_dp_state_carries_any_rank_decoding, test_sync_reduces_hidden_work_with_the_vote
  2. The early-load gate is fixed. load_wait_hook returns None without a connector or with supports_early_load False. Removing the gate fails test_no_hook_without_an_offload_tier_that_loads_early[dense|none] and test_dense_offload_connector_gets_no_hook.

The rebase onto _wake_event (#3672) is safe:

  • A ring is read from the doorbell's ring count, so a clear by _wait_for_input cannot lose one.
  • _wait_for_input checks both queues after its clear, so a clear inside the hook cannot strand an input.

The two has_running_decode=lambda: False stand-ins follow from the generic DP sync, so they are not the red-flag pattern.

Nit: atom/kv_transfer/engine_step_hooks.py:7-8 still says on_forward_done is "called after every real forward". The comments at engine_core.py:140 and load_wait.py:233 were updated to "real or DP dummy", but this one was missed.

Also reply to and resolve the open Copilot thread at load_wait.py:377. It is right in part. An answer requested before the ring can already finish every started load, and _wait_for_loads then waits for the next answer without re-checking pending. That costs one completion-query round trip, not the full bound, because applying that answer sends the next query. Re-checking pending after any applied answer removes the extra round trip. Either fix it or explain this in the thread.

Root cause vs patch

Root problem: a load completion reaches schedule() only through the pipelined query answered after forward N. The doorbell plus a fresh answer before schedule() fixes that with no knob. The hold is a bounded policy on top. Its cost to DP peers is now charged against the group (dummy-forward tick, group decode flag on the existing sync), not guessed per rank. Verdict: root fix, with the hold as a bounded, group-aware policy.

Prior asks: round 6 #1 and #2 are fixed. Rounds 3-5 still hold.


Reviewed at cacc8b4 (round 7, passes A+B; true delta = d89f8c9 (8196edf rebased on a69d2bb, range-diff = _wake_event rename only) vs head; mutants for the dummy tick, group_decoding, the supports_early_load gate and the all_reduce flag; CPU tests: load_wait/dp_idle/dp_sync_interval/envs/engine_core_kv_wait 262 passed). Already fixed: shared-class state, patched fakes, renewal-timeout wake, fork-pin thread, squash text, DP-aware hold, early-load gate.

An answer requested before the doorbell can already hold every started
load's completion. `_wait_for_loads` then waited for the next answer (one
completion-query round trip) before re-checking `pending`. Re-check after
any applied answer; the ring stays unread until a fresh answer, so a load
still in flight is waited for exactly as before.

Also: the step-hook docstring says `on_forward_done` runs after every real
or DP dummy forward.
Copilot AI balanced review requested due to automatic review settings November 27, 2026 14:22
@ZhangLirong-amd

Copy link
Copy Markdown
Collaborator Author

@valarLip thanks. Both are fixed in 06d1ef2:

  • Nit: engine_step_hooks.py now says on_forward_done is called "after every real or DP dummy forward".
  • Copilot thread load_wait.py:377: fixed, then replied to and resolved. After any applied answer, _wait_for_loads re-checks pending, including an answer requested before the ring. Once every started load has landed it returns, so the extra completion-query round trip is gone. A load still in flight waits as before, because the ring stays unread until a fresh answer. The new test test_an_older_answer_that_lands_every_load_ends_the_hold_at_once fails with the old load_wait.py.

CPU (rocm/atom-dev, head vs cacc8b4):

  • test_offload_load_event_wait.py: 43 passed (42 before).
  • envs, engine_core_kv_wait/idle_wait, dp_idle/dp_sync_interval and pd_chunked: 339 passed.
  • Broad offload/pd/kv/mooncake/scheduler/engine/dp/lmcache set: 4159 passed. The 8 failures and 1 error are the same at both heads, so none are new.

black and ruff are clean.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because an unread doorbell during data-parallel decoding can cause a completion wait of up to a full forward tick despite a zero hold budget, delaying every peer.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants