Re review report · NVIDIA/hyperflare-inference #628

Raw Markdown for agents: https://autobot.eidonix.com/p/77efbb08-5c9e-4d61-80da-efdc630b4ad6.md

Recommendation: Changes Requested

Head 76e1813 cleanly resolves all Round 1 blockers on the in-process threaded TP path—scoping CopyEngineGate exclusively to models with peer-copy graphs (zero overhead on single-GPU and non-peer-copy models), adding bounded fairness in CopyEngineGate wired into RankExecutor::can_submit, bounding peer-graph waits at 120 s, and updating docs/prefix-cache-offload.md. However, 76e1813 also extends gating to multi-process peer ranks (serve_rank / join_peer_with_gate) without wiring should_drain_for_offload() into serve_rank, leaving unbounded offload starvation on RankPeers::Processes, and subtracts max_gate_wait from Reply.elapsed, which distorts Selene's end-to-end inbound_rate / worth_fetching admission pricing; the new gated CUDA tests and A/B latency measurement also remain pending on 76e1813.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

  1. Unbounded offload starvation on multi-process peer ranks (helios/src/execution/parallel.rs:627-666, helios/src/execution/ranks.rs:181-184, helios/src/offload/copy_gate.rs:55-68, 120-125, 173-199):
    • Verified behavior & impact: 76e1813 wires owner.copy_gate() into multi-process peer offload workers (flare-cli/src/cluster.rs:254-261 -> helios/src/offload/shard.rs:47-61) and acquires PeerGraphLeases in serve_rank (parallel.rs:563-566, 652-665). However, should_drain_for_offload() is only checked by RankExecutor::can_submit (ranks.rs:181-184) on rank 0 against rank 0's process-local CopyEngineGate; serve_rank never checks leases.should_drain_for_offload(). Under 2-frame pipelined decode (protocol::can_submit_pending in helios/src/execution/threaded/protocol.rs:28), whenever rank 0's local gate has offload_batches_waiting == 0 while a peer process still has a waiting offload batch (e.g., rank 0 finished its batches first, a peer batch arrived slightly later over TCP, or a peer is serving a codec/pool transfer), rank 0 keeps pipelining PREPARE -> READY -> COMMIT back-to-back. On the peer, serve_rank enters frame N+1 while frame N is still active (peer_graphs_active oscillates 1 -> 2 -> 1 -> 2 and never hits 0), maybe_arm_offload_wave() never fires (copy_gate.rs:56 requires peer_graphs_active == 0), and the peer offload worker blocks indefinitely in enter_offload_batch's unbounded Condvar::wait (copy_gate.rs:183-185)—stalling multi-rank restores (which wait for every shard) and keeping GPU checkpoints pinned until decode goes idle.
    • Concrete fix: In serve_rank (helios/src/execution/parallel.rs:627-640), do not defer after COMMIT (at that point rank 0 has already launched its local CUDA graph in commit_and_launch at parallel.rs:359-372). Instead, when PREPARE/PREPARE_MORE arrives and leases.should_drain_for_offload() is true, hold back sending READY (without arming prepared_at) while continuing to poll executor.poll() so active frames finish, leases.release_through drops peer_graphs_active to 0 and arms the peer's offload wave, and send READY once !leases.should_drain_for_offload(). Add a CPU unit test driving serve_rank (or its frame-coordination loop) alongside a waiting offload thread to verify forward progress under 2-frame pipelining.

Should Fix

  1. Subtracting max_gate_wait from Reply.elapsed distorts Selene's inbound_rate and worth_fetching admission pricing (helios/src/offload/transfer.rs:780, 795-799, selene/src/memory.rs:1174, 1450-1457, selene/src/levels.rs:57-68, selene/src/store.rs:424-442, helios/src/server/runtime.rs:223-235, 2834, 2858):
    • Verified behavior & impact: Transfers::absorb reports pending.started.elapsed().saturating_sub(pending.max_gate_wait) as Reply.elapsed. MemoryStore::absorb feeds reply.elapsed into inbound_rate.observe(reply.bytes, reply.elapsed), which computes estimated_seconds for worth_fetching/worth_transfer (estimated_seconds < 0.5 * gained_tokens / prefill_rate) and RestoreWait::defer. Selene's own contract requires inbound_rate to measure end-to-end effective wall-clock restore latency (cf. selene/src/disk_store/coalesce/tests.rs:1444 (not opened), 1982, 2153); stripping gate wait makes gate-contended restores look artificially fast so the scheduler keeps admitting restores that actually lose to prefill (and clamping elapsed to zero causes Rate::observe to silently drop the sample at selene/src/levels.rs:58-60).
    • Concrete fix: Delete the gate_wait/max_gate_wait subtraction from Reply.elapsed (keep pending.started.elapsed(), and remove the ~60 lines of gate_wait plumbing across transfer.rs and codec.rs—see Subtract #1—updating transfer.rs:2047-2051 accordingly). Keep the two valid metric isolations already in 76e1813: GPU-codec transform_ns timers starting after gate acquisition and prefill_started recorded after executor.submit() succeeds.
  2. Complete pending SM120 GPU verification and A/B offload latency measurement (helios/src/offload/transfer.rs:2013-2053, helios/src/offload/transfer/codec.rs:1286-1292):
    • Concrete fix: Once the SM120 GPUs are free, run the newly added gated CUDA transfer and CPU/GPU codec tests on the final commit, post a peer-copy A/B offload throughput/latency comparison per Charter #210, and confirm Helios lifecycle (python3 verification/helios-lifecycle/check.py (not opened)) passes on the final head.

Subtract / Simplify

  1. Delete gate_wait / max_gate_wait plumbing (~60 lines, subsumes Should Fix #1): Remove RankReply.gate_wait (helios/src/offload/transfer.rs:78), Pending.max_gate_wait (:85), the saturating_sub (:780, 795-799), the Duration return from enter_offload_batch/copy_batch_gated/copy_spans_batch/RankWorker::run/RankCodec::run/capture_window/restore_window/decode_pages_cpu_batch, and revert the five (stored_len, elapsed, waited) tuple blocks in helios/src/offload/transfer/codec.rs:288-305, 318-340, 354-376, 673-700, 760-782 to simpler let start = Instant::now(); ... stats.transform_ns += ... blocks (still placed after gate acquisition).
  2. Collapse unused/test-only pass-through wrappers into single entry points:
    • helios/src/offload/mod.rs:114-130: open has zero callers repo-wide (server/runtime.rs:731 already calls open_with_gate). Delete open and rename open_with_gate to open.
    • helios/src/offload/shard.rs:37-61: join_peer is only called in two tests (helios/src/offload/shard/tests.rs:20, helios/src/offload/pool/tests.rs:146); production (flare-cli/src/cluster.rs:254) already calls join_peer_with_gate. Delete the wrapper, pass None at those two test sites, and keep one join_peer.
  3. Deduplicate gated/ungated batch-sync logic (helios/src/offload/transfer.rs:308-339, 459-474, helios/src/offload/transfer/codec.rs:978-1034): Both RankWorker::run and copy_spans_batch repeat the if copy_gate.is_none() { record; synchronize; } pattern and duplicate DrainOnDrop/Fence drop guards plus std::mem::forget. A small GatedCopies<'a> helper with batch(...) and finish() (draining inline on error via drain_stream) replaces all three sites cleanly.
  4. Narrow CopyEngineGate::enter_peer_graph_timeout visibility (helios/src/offload/copy_gate.rs:110): Its only callers are enter_peer_graph (:106) and two unit tests (:509, :518); make it private (fn) instead of widening the public crate API for a test knob.

Nits

  1. Accurate drain bound in docs (docs/prefix-cache-offload.md:919-922, 1025-1028): Line 1026 states that the model worker thread waits only for "a bounded in-flight 16 MiB batch drain", whereas at the five GPU-codec sites (helios/src/offload/transfer/codec.rs:288-303, 318-338, 354-374, 674-695, 761-779) OffloadBatchGuard spans an entire GPU encode/decode call—including up to MAX_PIPELINE_BATCHES = 4 pipelined batches + host emission (gpu_codec.rs:1601-1665) and CPU CRC/staging (gpu_codec.rs:1723-1747). Reword to "a bounded in-flight 16 MiB copy batch or GPU-codec batch/wave drain".

Dropped on verification