Explore scratchpad · NVIDIA/hyperflare-inference #628

Raw Markdown for agents: https://autobot.eidonix.com/p/769d0b0c-8333-4bd2-9dff-7ae4f9272054.md

#1 [high] Change: what PR #628 does, size, and summary-of-changes

PR #628 "helios: gate offload Copy Engine batches during peer-copy graphs" (draft, open 2026-11-30, head 1870a27, base main, 14 files +572/−72). Fixes #627.

What it does in plain terms: adds a process-wide mutex/condvar "gate" (CopyEngineGate, helios/src/offload/copy_gate.rs) with two lease types:

Gate is shared per NativeModel (helios/src/runtime_core/model.rs:27 field copy_gate, created at :662 Arc::new(CopyEngineGate::new())) and threaded through offload::Binding::new(inner, cubins, copy_gate) (helios/src/offload/mod.rs:39-56), NativeModel::attach_offload (model.rs:986 Copiers::with_gate), NativeModel manifest build (model.rs:1032-1039), and server offload attach (helios/src/server/runtime.rs:715-733 open_with_gate).

Graph classification is structural, computed at CUDA graph reconstruction: NativeResources.peer_copy_graphs: Vec<bool> set true when any Node::Copy has a Memory::Peer source or destination (helios/src/runtime_core/mod.rs:117, 919, 1149-1155, 1238), exposed per graph name in ExecutionManifest.peer_copy_graphs + has_peer_copies (helios/src/execution/manifest.rs:436-444, 449-452; populated in helios/src/runtime_core/serving.rs:49, 59, 202).

Execution boundary: RankExecutor restructured into RankExecutorInner + gate state (helios/src/execution/ranks.rs); merge_peer_copy_graphs unions peer flags across local RankPeers::Threads manifests (ranks.rs:29-42); guard taken in submit only if peer_copy_graphs[graph] (ranks.rs:90-105), released in poll for fences <= completed frame fence (ranks.rs:114-121), and all remaining guards cleared in close after inner close (ranks.rs:172-181).

Offload copy sites gated: uncompressed RankWorker::run per BATCH_BYTES batch (helios/src/offload/transfer.rs:398-428), CPU-codec copy_spans_batch flush (helios/src/offload/transfer/codec.rs:958-1025), and five GPU-codec sites (codec.rs:287-292, 315-320, 349-354 encode; 664-670 try_lock decode; 749-755 decode_to_device).

Wire/compat surface: no Protobuf change, no package-format change. heliopause Python manifest builder passes peer_copy_graphs: Vec::new() (heliopause/src/python.rs:331), i.e. the Python path never marks peer-copy graphs. Test-only additions: manifest literals in helios/src/execution/tests.rs:206, model/testing.rs:396, model/contract.rs:983.

#2 [high] Why: issue #627 reproduces an SM120 TP2 prefill deadlock and isolates it to concurrent Copy Engine DMA

#3 [high] Change: what the diff does that the description does not say (ungated paths, per-batch sync)

Findings from reading the diff/code (not stated in the PR description):

  1. Multi-host disk-store peer path is not gated. helios/src/offload/shard.rs:37-49 join_peer still builds super::transfer::Copiers::new(gpu_cubins) — the gate-less constructor. That path is what flare-cli uses for a peer rank with a disk prefix store (flare-cli/src/cluster.rs:254, owner.offload(), owner.gpu_codec_cubins().to_vec(), ...). So a peer rank's own offload copy engine batches (its disk-tier staging through the same Transfers/RankWorker) run without the gate. The PR's Limitations say "multi-host TP ... not tested end-to-end", and claim "pool and CPU codec paths share the same CopyEngineGate wiring" — the multi-host sharded peer path does not.

  2. attach_offload (Selene pool path) is effectively not gated either. NativeModel::attach_offload (helios/src/runtime_core/model.rs:985-991) does pass Copiers::with_gate, but it feeds self.offload.attach(prepared, &copiers), and in selene offload::Startup::attach (selene/src/offload.rs:935-949) the factory is used only when Preparation::Store(store) still has self.pool present: pool.prepare_peer(store, factory). Otherwise the factory is dropped. The factory only matters for the pool-agent peer transfer path. Also NativeModel::attach_offload has exactly one caller (model.rs:981, inside the cache-allocation phase), no other attach site found.

  3. Python/PyO3 core path never marks peer-copy graphs. heliopause/src/python.rs:331 sets peer_copy_graphs: Vec::new(), so any manifest built through Heliopause (in-process Python/SDK path) reports no peer copies regardless of content and the gate never engages there. Description says "defaulting absent entries to false for non-core manifests" — true, but the consequence is those paths get no protection, not just older cores.

  4. Two structural blind spots in peer-copy detection. Memory::Peer marking happens in NativeResources from the allocation's declared memory kind (helios/src/runtime_core/mod.rs:1149-1156), and Memory::Peer means "another rank's device allocation, referenced at its recorded address" (helios/src/runtime_core/format.rs:43-49). Graph copies that go through same-process rank threads but address a local Memory::Device allocation that happens to be peer-mapped are not marked. Only literal Node::Copy nodes count — any kernel-driven DMA (e.g. b12x kernels doing cudaMemcpyAsync inside a kernel, or the DMA-ring code path in helios/tests/collective_core_fixture.py:89-140 twoshot path) is not detected.

  5. Cross-rank gate sharing only within one process. The gate is created per NativeModel; multi-process TP (RankPeers::Processes, i.e. flare run one process per rank, used by multi-host and by docs/prefix-cache-offload.md:1617) gets one gate per process, so a rank's offload batches are not coordinated against another rank's peer-copy graph. Description says "Share one Arc per NativeModel", which is accurate but the reach is narrower than "TP2 deadlock eliminated" suggests outside single-process TP.

  6. Guard release is poll-driven. RankExecutor::poll only pops guards when a FrameCompletion comes back (helios/src/execution/ranks.rs:108-124). Threaded/parallel executors may complete frames out of order? They pop while the front fence <= completed fence, so a head-of-line stall holds every later lease. close() clears remaining leases unconditionally (ranks.rs:170-181).

  7. Deadlock risk in the gate itself for the threaded executor: submit calls enter_peer_graph() (blocking on offload batches) before calling inner submit, from the model worker thread; if an offload worker is concurrently blocked in enter_offload_batch() waiting on peer_graphs_waiting, the gate's condvar protocol says waiting peers take priority, so ok. But OffloadBatchGuard::drop only notify_all()s when the last offload batch drops (copy_gate.rs:97-104); a peer graph waiting while other offload batches remain active can block until all drain — that matches the documented "wait only for in-flight batches to drain".

  8. Undeclared: helios/src/offload/transfer.rs changed RankWorker::run to record+sync the event per batch inside the gated branch and keep the old single record/sync at the end when ungated; the ungated path is behavior-identical, but the gated path now adds a per-batch stream synchronize (transfer.rs:410-430), which is a serialization/latency change for offload throughput that the description does not mention (only "Acquire OffloadBatchGuard per BATCH_BYTES batch").

#4 [high] Project fit: charter root-cause rule and documented "offload never blocks the worker" invariant

Charter (read_charter) fit, as facts:

#5 [high] Change: offload copies become per-batch synchronizing for every prefix-cache run

Offload fast path changes for every prefix-cache run, not only peer-copy runs. copy_gate is Some whenever a NativeModel manages the offload store (helios/src/runtime_core/model.rs:986-989, model.rs:1032-1038), independent of whether any graph in the model has peer copies. Therefore:

#6 [high] Research summary

Case file for PR #628 "helios: gate offload Copy Engine batches during peer-copy graphs" (draft, open 2026-11-30, head 1870a27, base main, 14 files +572/−72, labels bug/performance/priority:P1, no reviews, CI failed, zero comments).

What it does. Adds a per-NativeModel CopyEngineGate (Mutex+Condvar, new file helios/src/offload/copy_gate.rs) with two RAII leases: PeerGraphGuard (taken around submitting a CUDA graph that contains in-graph Node::Copy against Memory::Peer; waits only for in-flight offload batches to drain, and takes priority over waiting offload batches) and OffloadBatchGuard (taken per 16 MiB BATCH_BYTES window by offload copy workers; multiple workers hold it concurrently across ranks). Graph classification is structural at graph reconstruction (helios/src/runtime_core/mod.rs:919,1149-1156,1238 → ExecutionManifest.peer_copy_graphs/has_peer_copies, helios/src/execution/manifest.rs:436-449), unioned across local RankPeers::Threads manifests (helios/src/execution/ranks.rs:39-52), leased in submit and released in poll/close (ranks.rs:90-124,170-181). Gated copy sites: transfer.rs:398-430, codec.rs:958-1028 (CPU codec) and five GPU-codec entry points (codec.rs:290,318,352,668,752). No Protobuf, package-format or flag change.

Highest-value findings a reader could not learn from the description (all verified in code):

  1. Documented invariant reversed, docs not updated. docs/prefix-cache-offload.md:133 says "Offload work never blocks the model worker thread or the model stream" (:907, :1015 repeat it). With the gate, the model worker thread blocks in enter_peer_graph() until in-flight offload batches drain (ranks.rs:90-96, copy_gate.rs:47-56). No docs file is in the changed set.
  2. Offload fast path changes for every prefix-cache run, not only peer-copy runs. Because the gate is Some whenever offload is attached (model.rs:986-989,1032-1038), RankWorker::run now does record+synchronize per batch (transfer.rs:410-430; the single end-of-job sync at :431-434 is now the gate-less path only), and copy_spans_batch likewise (codec.rs:978-1000,1002,1025-1028). The description's "zero gate overhead on graphs without peer-copy nodes" is true for graph submission only; no offload-throughput measurement is presented.
  3. Several paths remain ungated and the description implies otherwise. helios/src/offload/shard.rs:47 (join_peer, the multi-host disk-store peer path used from flare-cli/src/cluster.rs:254) still builds Copiers::new with no gate; heliopause/src/python.rs:331 passes peer_copy_graphs: Vec::new() so the Python/PyO3 manifest path never marks peer copies; attach_offload's factory only reaches the pool-agent peer path (selene/src/offload.rs:935-949). Multi-process TP gets one gate per process (NativeModel-scoped), so cross-rank coordination does not span processes.
  4. Detection breadth. Only literal Node::Copy nodes with a declared Memory::Peer allocation are marked (format.rs:43-49); kernel-driven DMA or copies to a local allocation that is merely peer-mapped are not.
  5. Guard release is poll-driven: a head-of-line frame holds every later lease (ranks.rs:114-121); close clears the rest.
  6. Charter tension. The charter requires bug fixes to address the root cause (#397); #627's own ablation shows the mechanism is not fully characterised (cross-rank mutex serialization of offload workers still deadlocked), and the PR frames itself as coordinating around the conflict rather than removing it.

Why / evidence. Issue #627 (same author, same day, 0 comments, labels area:selene/bug/P1/triage:investigate) reproduces a TP2 prefill deadlock on 4× RTX PRO 6000 (SM120, driver 595.99.02) with Qwen3.8-Flash-Next prefill7168 (8,613 nodes, 1,176 peer Node::Copy, 4.58 MiB) under 8-way uncached ~6,574-token bursts; cuGraphAddEventRecordNode frontier probes showed both ranks stalling inside a PCIeDmaAllReduce copy + FlagLaunch; skipping only stream.copy_batch passed 48/48, disabling the host cache or pausing copy windows passed 80/80. The PR's validation (compiler checks, 5 new gate/ranks unit tests, 162 helios server tests, 245 flare, 200/201 flare-cli, 19/19 offload CUDA tests, live TP2 runs for Qwen3.8 and GLM-5.3) is described in text only — no logs or artifacts; unpatched main deadlocking during the first burst is the only comparative datapoint, so there is no speedup claim of the kind the charter asks for performance changes (#210).

Related work. Nothing else in the repo covers this deadlock; searches return only #627/#628. The change sits on author yatesdr's Selene/offload series (#80, #92, #141, #168, #504 GPU/CPU KV codec, #525, #527, #589/#497 from others) and touches files last changed by #504/#525 (codec.rs), #497 (transfer.rs), #430/#507 (manifest.rs), #280/#334 (ranks.rs). No overlapping or competing PR; nearest neighbours are #497 (offload restore latency, merged 2026-11-29) and #622 (open, GPU limits) — neither conflicts.

Recent activity / people / community. helios/src/offload was last touched 2026-11-28 by Luke Alonso (#589) before this commit; the branch predates only #626 (0a8c20f4) in the touched files. Author yatesdr is a COLLABORATOR with 80 merged PRs in 180 days, the dominant contributor to Selene/offload (34 helios/src commits); Luke Alonso (229) and Martin Vit (52) are the other helios regulars. No reviews, comments or reactions yet; the flare-autobot review that other PRs in this area received has not appeared.

Project fit / reach. Fits the SM120/SM120-Spark focus, keeps the runtime model-agnostic (no per-model branch, no new flag), and lands in Helios rather than ignition. Affects every --prefix-cache-memory/disk/pool run through the extra per-batch sync and the worker-thread blocking, single-host threaded TP2 most of all; no config, compatibility, wire-format or deployment change; exported cores keep loading (peer_copy_graphs defaults absent → false). Process: draft, CI failed on the head commit, no reviewer assigned.

#7 [high] Related work: no competing or duplicate PR; overlaps #497, #621, #334, #280 and the author's Selene series

Searches for the deadlock topic return only #627 and #628 (queries: "copy engine peer deadlock offload", "PCIeDmaAllReduce peteep copy b12x", "b12x collective peer", "prefix cache offload hang deadlock", "prefill interference offload pause copy priority", "draft helios offload prefix cache copy engine" by yatesdr). No duplicate report, no prior PR attempting this fix, nothing superseded.

Files-overlap picture (items_touching, last 180 days):

#8 [medium] Recent activity: base c146d7b, only #626 landed since; change builds on #497/#504/#525 and contradicts docs §2.5/§2.10

#9 [medium] People: yatesdr owns the Selene offload tiers; Luke Alonso/Martin Vit/FujitsuPolycom nearby; no one has engaged yet