Repository navigation
helios: gate offload Copy Engine batches during peer-copy graphs - #628
Conversation
On discrete PCIe GPUs (observed on SM120 RTX PRO 6000 under CUDA driver 595.99.02), tensor-parallel CUDA graphs whose collectives drive peer-to-peer transfers through in-graph Copy Engine nodes (`Node::Copy` with a `Memory::Peer` endpoint, such as `b12x` `PCIeDmaAllReduce`) deadlock when prefix-cache offload workers issue concurrent host-device Copy Engine batches on the same devices. Even a single concurrent device-to-host copy from an unrelated allocation on the offload stream stalls both ranks inside the graph's peer-copy collectives. Coordinating host offload batches against peer-copy graph execution directly in Helios eliminates the deadlock for already-exported model packages without changing the package format, scheduling policy, or per-model behavior. Detect peer-copy graphs structurally during CUDA graph reconstruction in `NativeResources`: record `peer_copy_graphs[i] = true` whenever any `Node::Copy` node in graph `i` has a `Memory::Peer` source or destination, carry that vector on `ExecutionManifest`, and union it across local `RankPeers::Threads` manifests in `RankExecutor`. Share one `offload::CopyEngineGate` per `NativeModel` across `RankExecutor`, local `offload::Binding` / `offload::open_with_gate`, and `NativeModel::attach_offload` (for Selene pool workers). When submitting a graph flagged with peer copies, `RankExecutor` acquires a `PeerGraphGuard` (blocking until in-flight offload batches drain and giving waiting peer-copy graphs priority over new batches) and releases it on `poll` completion or after `close` drains. Offload workers acquire an `OffloadBatchGuard` per `BATCH_BYTES` batch in uncompressed `RankWorker::run`, CPU-codec `copy_spans_batch`, and all five GPU-codec capture/restore entry points (preserving strict `gpu.codec` before `CopyEngineGate` lock order and draining the CUDA stream before releasing the guard on error). Graphs without peer-copy nodes incur no gate locking. Eliminates the TP2 prefill deadlock under concurrent prefix-cache offload while preserving multi-rank offload concurrency outside peer-copy graphs and maintaining warm/restore correctness and burst latency. Validation: - `RUSTFLAGS="-D warnings" cargo check --locked --all-targets` passed for `helios --features runtime-core,server`, `flare`, `flare-cli`, and `heliopause --lib` (0 warnings). - Unit tests passed: `helios` `offload::copy_gate` and `execution::ranks` (5/5), `helios` `server::runtime` and `execution::threaded` (162/162), `flare` (245/245), and `flare-cli` (200/201 under root and 200/201 under non-root, with all 201 distinct tests passing across the two permission contexts). - SM120 4-GPU CUDA `helios` `offload::` tests passed: 19/19 default tests plus 6/6 ignored `offload::transfer::` GPU/CPU codec and multi-GPU split pool tests (`FLARE_RUN_CUDA_TESTS=1`). - Live SM120 TP2 (`--gpus 0,1`, `--prefix-cache-memory 4G`, 16 GiB disk tier) on `Qwen3.8-Flash-Next` (`--lossless-kv-compression off`): cold, warm (0/6 pos0 mismatches, 5.08x speedup), restart + disk restore (0/6 pos0 mismatches, 2.45x speedup), 8-way burst with 2 aborts (8/8, 4.15s), and 5x 8-way uncached 6578-token bursts (40/40 HTTP 200, 4.68-4.83s/burst; unpatched `main` deadlocked during the first burst). - Live SM120 TP2 on `GLM-5.3-Flash` (`--lossless-kv-compression gpu`): cold, warm (0/96 token mismatches, 3.50x speedup), restart + restore (0/96 token mismatches, 1.55x speedup), and 8-way burst with 2 aborts (8/8, 5.88s). Limitations: - Tested on single-host threaded TP2 on SM120 (RTX PRO 6000) with local DRAM and disk tiers (uncompressed and GPU KV codec). Multi-host TP, live Selene pool serving, CPU KV codec live serving, and non-SM120 GPUs were not exercised live (though pool and CPU codec paths share the same `CopyEngineGate` wiring and unit/CUDA codec tests). Fixes NVIDIA#627 Signed-off-by: yatesdr <6937857+yatesdr@users.noreply.github.com> Design-Signed-Off-By: yatesdr; design-review=2e5b
|
A case file has been opened for 628. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedClean engineering of structural peer-copy detection, RAII gate primitives, strict
Walkthrough
Merge Risk: High · up to
|
…ls, and preserve metrics Address starvation, non-peer-copy overhead, timeout, metrics, multi-host coverage, and cleanup gaps in `CopyEngineGate`: - Add bounded fairness to `CopyEngineGate` (`MAX_PEER_STREAK_WHILE_OFFLOAD_WAITING = 4`): when offload batches are waiting under sustained 2-frame pipelined peer-copy decode, `PeerGraphLeases::should_drain_for_offload()` signals `RankExecutor::can_submit()` to pause pipelining for one frame so active peer-copy leases drain to zero, then grants one concurrent wave to all waiting offload ranks before resuming peer-copy graphs. Only arm an offload wave when `peer_graphs_active == 0` so a single-threaded pipelined worker cannot self-deadlock. - Scope `CopyEngineGate` creation in `NativeModel` to models where at least one rank reconstructed a graph with `Node::Copy` referencing `Memory::Peer` (`NativeResources::has_any_peer_copy_graphs()`). Single-GPU and non-peer-copy TP models receive `copy_gate = None` and stay on the ungated single-sync-per-window offload fast path. - Bound `CopyEngineGate::enter_peer_graph` with `PEER_GRAPH_GATE_TIMEOUT` (120 s, aligned with `ThreadedExecutor::TIMEOUT`), returning `ExecutionError::Drain` instead of parking the model worker thread indefinitely if an offload Copy Engine batch fails to drain, and update the invariants in `docs/prefix-cache-offload.md` and `helios/src/offload/transfer.rs`. - Exclude gate-wait pauses from throughput metrics: start the transform timer after acquiring the gate in all five GPU-codec call sites in `codec.rs`, accumulate per-rank `gate_wait` and subtract `max_gate_wait` from `Reply.elapsed` in `Transfers::absorb`, and record `prefill_started` in `Worker::submit` after `executor.submit()` succeeds. - Share `PeerGraphLeases` between `RankExecutor` and multi-host `serve_rank` (`execution/parallel.rs`), and wire `owner.copy_gate()` through `offload::shard::join_peer_with_gate` (`flare-cli/src/cluster.rs`). - Deduplicate gated/ungated `stream.copy_batch` and stream-drain helpers into `transfer::copy_batch_gated` and `transfer::drain_stream`; remove dead `ExecutionManifest::has_peer_copies` and unused `OffloadBatchGuard` re-export; move pure delegation matches onto `RankExecutorInner`; validate `peer_copy_graphs.len() == graphs.len()` (when non-empty) in `ExecutionManifest::validate()`; and add unit and gated CUDA transfer tests. Validation: - `RUSTFLAGS="-D warnings" cargo check --locked --all-targets` passed with 0 warnings on `helios --features runtime-core,server`, `heliopause --lib`, `flare`, and `flare-cli`. - `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server`: 1,740/1,740 lib tests passed (1,739 with `io_uring` + 1 non-root chmod test) and all integration tests passed (excluding the 9 HF-template fixture tests requiring `FLARE_TEST_TEMPLATE_DIR`). - `cargo test --locked --release --manifest-path flare/Cargo.toml`: 245/245 passed. - `cargo test --locked --release --manifest-path flare-cli/Cargo.toml`: all 201 unit tests (across root and non-root permission contexts) and all 4 integration test suites passed. Limitations: - New gated CUDA transfer tests (`split_pools_cost_each_device_its_part_and_round_trip_units` and `gated_cpu_and_gpu_codec_capture_and_restore_defer_while_peer_graph_holds_gate`) and an A/B peer-copy offload latency comparison have not yet been executed on this commit because the SM120 host GPUs are currently occupied by another job; the earlier SM120 CUDA `offload::` tests and live `Qwen3.8-Flash-Next` TP2 / `GLM-5.3-Flash` TP2 runs passed on `1870a27`. Signed-off-by: yatesdr <6937857+yatesdr@users.noreply.github.com> Design-Signed-Off-By: yatesdr; design-review=2e5b
|
Addressed the Autobot review findings in
Validation on
Discord: D-Rock |
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedHead
Walkthrough
Merge Risk: Medium · up to
|
…Gate wiring Address review findings on CopyEngineGate and offload transfer plumbing: - Defer READY in execution::parallel::serve_rank when a rank's CopyEngineGate reports a waiting offload batch, parking on in-flight frames until active peer-copy graphs drain so multi-process TP ranks cannot starve offload transfers under continuous traffic. Add unit test peer_deferred_ready_drains_active_frames_for_waiting_offload. - Measure Selene offload Reply.elapsed as real wall-clock completion time (including gate wait) so MemoryStore inbound_rate and admission pricing reflect actual offload duration, while keeping GPU-codec timing scoped after gate acquisition and prefill_started after executor.submit(). Remove the gate_wait plumbing from RankReply, Pending, RankWorker, RankCodec, and copy helpers. - Collapse open_with_gate into offload::open and join_peer_with_gate into offload::shard::join_peer, deduplicate batch sync/drain into GatedCopies in offload::transfer, make enter_peer_graph_timeout private, and tighten the drain bound wording in docs/prefix-cache-offload.md. - Add gated SM120 CUDA test gated_cpu_and_gpu_codec_capture_and_restore_defer_while_peer_graph_holds_gate. Signed-off-by: yatesdr <6937857+yatesdr@users.noreply.github.com> Design-Signed-Off-By: yatesdr; design-review=2e5b
|
Updated in
Verification (4× RTX PRO 6000 SM120 PCIe)
@flare-autobot please re-review. Discord: D-Rock |
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Ready To MergeHead
Walkthrough
Merge Risk: Medium · up to
|
…cing with cohort horizon and time-potential
Why
Under concurrent mixed prefill-and-decode workloads where active decode
requests have staggered or tight remaining output budgets, the prefill
coalescing continuation term in helios/src/scheduler/policy.rs and
scripts/scheduling_sim/utility.py exhibits two defects:
1. Scalar minimum peer_budget collapse: clamping the coalescing horizon and
speculative expected output for all active decoders by
peer_budget = min_i(rem_i) drops coalescing credit toward zero whenever any
single active decoder nears completion, stalling decode-batch growth
(K -> K + m) even while the rest of the cohort retains ample remaining
output budget.
2. Uniform per-token amortization against non-linear prefill latency: dividing
the unlocked decode-batch surplus V_unlock uniformly across initial_prefill
tokens rewards suboptimal bucket-boundary splits (such as 512 + 38 tokens on
a 550-token prompt) and leaves under 1% of V_unlock on short residual tails
that actually enter decode, stalling near-complete requests behind active
decoders while holding concurrency slots and KV pages.
Averaging the bounded horizon across active decoders eliminates single-stream
collapse while preserving coalescing_horizon_tokens (default 64.0). Replacing
uniform per-token amortization with a telescoping potential over the loaded
core's monotone minimal measured GPU prefill time T_min(tokens) at each
request's fixed reference context (admission_reused_tokens) bounds total
coalescing credit to at most 1x V_unlock across any multi-chunk path (including
subset TerminalPrefill catalogs), penalizes tail-creating splits in proportion
to added GPU time, retains 100% of the unlock rate
V_unlock / T_min(initial_prefill) on residual tails, bounds DP work to
O(|catalog| x 512) without coarse-grid quantization cliffs, caches
non-context-scaled DP tables once per PlanningScope for O(1) scoring, and falls
back to uniform per-token amortization on unmeasured cold-start catalogs.
What
- Helios scheduler (helios/src/scheduler.rs, helios/src/scheduler/checkpoints.rs,
helios/src/scheduler/policy.rs, helios/src/scheduler/utility.rs; +863/-64,
799 net lines including 32 added lines of #[cfg(test)] helpers -> 767 net
non-test Rust production LOC):
- Replaced scalar peer_budget = min_i(rem_i) in
RequestScheduler::coalescing_prefill_terms with a stack-allocated
[usize; REQUEST_LANES] cohort average, capping speculative expected output
per decoder before averaging (matching scripts/scheduling_sim/utility.py)
and resolving Decode graph durations once per call.
- Added ResolvedPrefillCatalog, RefCell<Box<CoalescingScopeCache>> (allocated
once in RequestScheduler::new(); +16 B to size_of::<RequestScheduler>(),
zero per-select_plan heap allocations, invalidated on PlanningScope
enter/drop, descending capacity walk retaining the largest capacities when
> 32 shapes exist), and PrefillTimeModel dynamically over the loaded core's
Prefill, TerminalPrefill, and constant Mixed catalogs.
- Evaluated T_min(tokens) via O(1) closed-form affine summation for full
chunks (PrefillPredictor::full_chunk_affine()) plus a stack-allocated
strictly monotone 1D DP (MAX_DP_STEPS = 512, conservative downward
quantization with exact single-launch remainder pricing on coarse grids),
caching DP tables per scope whenever
has_context_scaling(requires_terminal) is false.
- Gated PrefillTimeModel::min_time_ms under #[cfg(test)] so non-test
--release builds emit zero new compiler warnings.
- Python scheduling simulator (scripts/scheduling_sim/utility.py; +129/-15,
114 net production LOC): mirrored cohort-averaged horizon and time-potential
telescoping in UtilityPolicy.
- Docs and tests (docs/scheduling-runtime-design.md +18/-8;
helios/src/scheduler/policy_tests.rs +1,573/-0;
tests/test_scheduling_utility.py +304/-3): documented the cohort horizon and
time-potential formulas and added Rust and Python coverage for cohort
averaging, telescoping, subset TerminalPrefill catalogs, downward coarse-DP
quantization, scope-cache invalidation, zero-intercept context-scaled
predictors, cold-start fallback, and O(|catalog|) lookup scaling.
- Compatibility: zero Protobuf, core-format, ABI, CLI, config, or graph-op
changes; existing exported cores load and serve unchanged; zero unsafe code
or new locks.
Result
Live zero-re-export flare run A/B benchmarks on two 4-GPU TP4 clusters
(DeepSeek-V4.1-Flash, identical CLI flags and prompts across arms, zero server
errors or non-finite logprobs; measured on the equivalent scheduler logic atop
571a447 prior to the rebase onto 5d53040 incorporating NVIDIA#656 and NVIDIA#628):
4x RTX PRO 6000 (SM120 TP4, exported core gb202-tp4-202612010626, balanced 4
trials/arm and throughput 2 trials/arm; PolicyConfig::throughput() inherits
coalescing_horizon_tokens = 64.0 from PolicyConfig::default()):
| Policy ∥ Workload | Makespan | Agg Decode | TTFT (p50 ∥ Max) | Max Decode Gap | Mean TPOT |
| --- | --- | --- | --- | --- | --- |
| balanced ∥ Mixed long-prefill + decode | 3.88 -> 3.82 s (-1.5%) | +1.7% | 2K p50: 1,599 -> 1,479 ms (-7.5%) | 408.1 -> 322.4 ms (-21.0%) | 7.20 -> 8.50 ms (+18.2%) |
| balanced ∥ Burst-8 + BG decode | 2.35 -> 2.24 s (-4.6%) | +5.0% | 1,224 -> 992 ms (-19.0%) ∥ 1,782 -> 1,509 ms (-15.3%) | 337.6 -> 201.3 ms (-40.4%) | 6.03 -> 6.80 ms (+12.9%) |
| throughput ∥ Mixed long-prefill + decode | 3.86 -> 3.79 s (-1.8%) | +1.9% | 2K p50: 1,823 -> 1,674 ms (-8.1%) | 584.8 -> 320.7 ms (-45.2%) | 7.55 -> 10.20 ms (+34.9%) |
| throughput ∥ Burst-8 + BG decode | 2.39 -> 2.09 s (-12.8%) | 610.3 -> 698.2 tok/s (+14.4%) | 1,179 -> 983 ms (-16.7%) ∥ 1,729 -> 1,492 ms (-13.7%) | 485.0 -> 452.7 ms (-6.6%) | 6.38 -> 8.23 ms (+29.2%) |
4x DGX Spark GB10 (SM121 TP4, exported core gb10-tp4-202612010243, balanced, 3
trials/arm):
| Workload | Wall / Makespan | Decode Throughput | TTFT | Decode Tail Latency | Mean TPOT |
| --- | --- | --- | --- | --- | --- |
| 12 decoders + 3 ~24.8K prefills | 20.67 -> 18.73 s (-9.4%) | 94.33 -> 103.28 tok/s (+9.5%) | Heavy max: 16,603 -> 14,537 ms (-12.4%) | Max gap: 1,720.5 -> 1,689.2 ms (-1.8%) | 74.77 -> 67.43 ms (-9.8%) |
| 6 decoders + Burst-8 prefills | 12.87 -> 12.41 s (-3.5%) | 104.44 -> 108.28 tok/s (+3.7%) | Burst max: 6,996 -> 6,840 ms (-2.2%) | BG p99 ITL: 266.34 -> 237.94 ms (-10.7%), 0 stalls >500 ms | 40.70 -> 42.10 ms (+3.4%) |
Trade-off: on SM120 under mixed bursts, coalescing prefills earlier into the
decode cohort raises active-decode mean TPOT (+12.9%..+18.2% balanced,
+29.2%..+34.9% throughput) while reducing worst-case decode stalls (-21%..-45%),
TTFT (-7.5%..-19.0%), and makespan (-1.5%..-12.8%).
Deterministic simulator matrix (scripts/scheduling_sim/workloads.py, 21
workloads, seed=0, Value(64), rate_history="service"): mixed=False throughput
and mixed=True balanced are 21/21 bit-identical; mixed=True throughput has
21/21 identical summary metrics; mixed=False balanced is 18/21 identical with
burst_eight makespan 2060 -> 1998 ms (-62 ms, max TTFT -90 ms),
burst_eight_low 7940 -> 7938 ms (-2 ms), and burst_eight_8k 2648 -> 2676 ms
(+28 ms, +1.0%, max TTFT +44 ms). Hot-path release scaling at 16 x 256K warmed
adds +23 ENTRY_LOOKUPS (429 -> 452) and +2.5 us median select_plan latency
(29.9 -> 32.4 us).
Evidence
Verified on a clean git archive extract of this commit atop 5d53040:
- git merge-tree --write-tree 5d53040 HEAD -> 0 conflicts
- cargo check --locked --release on helios (--features runtime-core,server --lib), flare (--lib), flare-cli (--bins), and heliopause -> 0 new non-test warnings
- cargo test --locked --release on helios (--features server --lib and --features runtime-core,server --lib), flare (--lib), and flare-cli
- python3 -m pytest tests/preparation/test_core_boundary.py tests/test_scheduling*.py -q
- ruff==0.12.8 check on scripts/scheduling_sim/utility.py and tests/test_scheduling_utility.py
- Standalone TLA+ model checks (all 10 TLC configs) and Rust trace conformance against all 8 modeled protocols
- Dual-hardware live flare run A/B benchmarks above on 4x RTX PRO 6000 (SM120) and 4x DGX Spark GB10 (SM121) on the equivalent scheduler logic atop 571a447
Material limitations:
- Live GPU serving benchmarks ran on the equivalent scheduler logic atop 571a447 prior to the rebase onto 5d53040 (NVIDIA#656, NVIDIA#628).
- The 62-scenario x 64-seed scripts/scheduling_sim/learning.py --preset validate sweep and cargo-kani were not run (timing estimation, funded refresh, completion-vector validation, and StateView extent arithmetic are unchanged).
Discord: Dooner
Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>
Upstream NVIDIA#628 records whether a graph moves data through peer memory so offload Copy Engine batches can be gated around it. That flag was declared inside the single build loop upstream; our capture split keeps every graph alive for hooks, so the flag now travels in Captured. Also passes the empty hooks set in the metadata-only load test, which predates the hooks argument.
Fixes #627
Problem and approach
On discrete PCIe SM120 GPUs (RTX PRO 6000, CUDA driver
595.99.02), tensor-parallel CUDA graphs whose collectives execute in-graph peer-to-peer Copy Engine nodes (Node::Copywith aMemory::Peerendpoint, such asb12xPCIeDmaAllReducepaired withFlagLaunchSM spin-waits) deadlock when Helios prefix-cache offload workers issue concurrent host-device Copy Engine batches on the same devices. Node-level frontier probes and controlled copy-path ablations isolated the stall specifically to concurrent Copy Engine DMA submission during peer-copy graph execution.Coordinating host offload batches against peer-copy graph execution directly in Helios resolves the deadlock for already-exported model packages without changing the package format, Protobuf contract, scheduling policy, or per-model behavior.
Summary of changes
helios/src/runtime_core/mod.rs,helios/src/runtime_core/serving.rs,helios/src/execution/manifest.rs): During CUDA graph reconstruction inNativeResources, recordpeer_copy_graphs[i] = truewhenever anyNode::Copynode in graphihas aMemory::Peersource or destination. Exposepeer_copy_graphsandhas_peer_copiesonExecutionManifest(defaulting absent entries tofalsefor non-core manifests).helios/src/offload/copy_gate.rs,helios/src/offload/mod.rs,helios/src/runtime_core/model.rs,helios/src/server/runtime.rs): AddCopyEngineGatewith RAIIPeerGraphGuardandOffloadBatchGuardleases. Multiple offload workers holdOffloadBatchGuardconcurrently across ranks while no peer-copy graph is waiting or active; waiting peer-copy graphs take priority over new offload batches and wait only for in-flight batches to drain. Share oneArc<CopyEngineGate>perNativeModelacrossRankExecutor, localoffload::Binding/offload::open_with_gate, andNativeModel::attach_offload(Selene pool workers).helios/src/execution/ranks.rs): Unionpeer_copy_graphsacross localRankPeers::Threadsmanifests so asymmetric peer copies are covered. Acquire aPeerGraphGuardinRankExecutor::submitonly when the submitted graph contains peer copies, release completed leases inRankExecutor::poll, and release remaining leases inRankExecutor::closeafterinner.close()drains. Graphs without peer-copy nodes do not touch the gate.helios/src/offload/transfer.rs,helios/src/offload/transfer/codec.rs): AcquireOffloadBatchGuardperBATCH_BYTESbatch in uncompressedRankWorker::run, CPU-codeccopy_spans_batch, and all five GPU-codec capture/restore entry points. Preserve strict lock ordering (gpu.codecbeforeCopyEngineGate) to prevent lock inversion againsttry_lock, and drain the offload stream before releasing the guard on error.Resulting behavior
Validation
RUSTFLAGS="-D warnings"):cargo check --locked --all-targetspassed with 0 warnings onhelios --features runtime-core,server,flare,flare-cli, andheliopause --lib.heliosoffload::copy_gate+execution::ranks: 5/5 passed (multi-rank concurrency, peer-graph wait/drain, priority under continuous offload, panic-unwind release, asymmetric rank union).heliosserver::runtime+execution::threaded: 162/162 passed.flare: 245/245 passed.flare-cli: 200/201 passed under root and 200/201 passed under non-root (all 201 distinct tests passed across the two permission contexts).FLARE_RUN_CUDA_TESTS=1):heliosoffload::passed 19/19 default tests plus 6/6 ignoredoffload::transfer::CPU/GPU KV codec and multi-GPU split-pool tests.--gpus 0,1,--prefix-cache-memory 4G, 16 GiB disk tier):Qwen3.8-Flash-NextTP2 (--lossless-kv-compression off): cold, warm (0/6pos0 mismatches,5.08xspeedup), restart + disk restore (0/6pos0 mismatches,2.45xspeedup), 8-way burst with 2 aborts (8/8,4.15 s), and 5x 8-way uncached 6,578-token bursts (40/40HTTP 200,4.68–4.83 s/burst; unpatchedmaindeadlocked during the first burst).GLM-5.3-FlashTP2 (--lossless-kv-compression gpu): cold, warm (0/96token mismatches,3.50xspeedup), restart + restore (0/96token mismatches,1.55xspeedup), and 8-way burst with 2 aborts (8/8,5.88 s).Limitations
CopyEngineGatewiring and passed unit and CUDA codec tests).Discord: D-Rock