Final review report · NVIDIA/hyperflare-inference #576

Raw Markdown for agents: https://autobot.eidonix.com/p/ae2d8f1b-339c-4e5e-9bb3-5453854f467b.md

Recommendation: Changes Requested

Pinning latency-critical execution and RoCE proxy threads to high-capacity CPUs on asymmetric ARM64 Linux hosts (DGX Spark GB10) directly addresses a real scheduling jitter problem, and the core tier-selection helper in eos/src/unix.rs cleanly respects existing operator cpusets and no-ops on homogeneous or x86_64 systems. However, two concrete blockers remain (consistent with @original-el8's review, plus critical system-level interactions verified against main): (1) editing vendored helios/native/roce_proxy.c breaks its byte-identity contract with FlashInfer and duplicates 66 untested C lines when main (#589) already provides the Flare-owned roce_proxy_dlopen.c wrapper; and (2) pinning at entry to flare-model (helios/src/server/runtime.rs:568) leaks the narrowed X925-only mask to background offload, disk, image-prep, and KV-codec threads — halving the flare-kv-codec-* rayon pool on GB10 — while moving that call alone would silently unpin same-process threaded TP ranks (flare-rank-*).

Merge Risk

Level: High

Walkthrough

Pre-merge Checks

Blockers

  1. Vendored helios/native/roce_proxy.c divergence and duplicated untested C logic (helios/native/roce_proxy.c:1505-1577)

    • Verified behavior & impact: Adding pin_high_capacity_cpus() and calls inside proxy_main modifies a vendored FlashInfer file whose own header (helios/native/roce_proxy.c:6-8), NOTICE:16-19, and docs/roce-ring.md:360-364 explicitly require keeping identical to FlashInfer's pinned source. Since this PR branched, #589 (ba3afb13) merged on main adding the Flare-owned helios/native/roce_proxy_dlopen.c:7-9,216-236 (which #include "roce_proxy.c" and explicitly states "keeping the vendored roce_proxy.c byte-for-byte identical to FlashInfer") and updated helios/build.rs:69-74 to compile only roce_proxy_dlopen.c. The 66-line C function also duplicates eos/src/unix.rs:172-245 with no test coverage.
    • Concrete fix (choose one, after rebasing onto main):
      • Preferred (zero vendored diff, zero duplicated C): Revert all edits to helios/native/roce_proxy.c. Apply affinity from Rust around roce_start(self.context) in helios/src/execution/roce.rs:295 using a scoped save-and-restore affinity guard (save sched_getaffinity, call prefer_high_capacity_cpus(), call roce_start, then immediately restore the caller's mask). Important: Do not omit the restore — RoceTransport::connect (roce.rs:295) runs on flare-cli's main thread (flare-cli/src/cluster.rs:203,250) before Bootstrap::load (flare-cli/src/main.rs:623), Server::start (:631), and peer join_peer (cluster.rs:254), so an unscoped pin there would narrow the entire process (shrinking Frontend's EncodeThreadBudget at helios/src/frontend/mod.rs:334,1121 and confining Tokio/HTTP and peer offload threads to X925). To preserve the "flare-roce" thread name (which the placement check relies on), wrap the single pthread_create call (roce_proxy.c:1674) in helios/native/roce_proxy_dlopen.c via #define pthread_create ... (matching its existing ibv_* wrapper pattern at :216-232) and call pthread_setname_np(*thread, "flare-roce") on success.
      • Alternative: Land FlashInfer PR #156 first, re-vendor roce_proxy.c verbatim from the updated pinned commit, and update NOTICE:17 to the new commit SHA.
  2. Child-thread affinity inheritance in flare-model confines demoted background threads, halves the KV-codec pool, and hides a threaded-TP coverage trap (helios/src/server/runtime.rs:568, selene/src/shared/codec.rs:41, helios/src/execution/threaded.rs:652-655)

    • Verified behavior & impact: Because flare_eos::prefer_high_capacity_cpus() is the first statement of the flare-model closure (runtime.rs:568), Linux affinity inheritance propagates the X925-only mask to every child thread spawned during startup:
      • crate::offload::open (runtime.rs:698) → flare-offload-{rank} (helios/src/offload/transfer.rs:509-535, demoted via SCHED_BATCH + NICE at :531) and flare-offload-disk (selene/src/offload.rs:676 → selene/src/disk.rs:358-360,470,489-491, also demoted via SCHED_BATCH + NICE).
      • ImagePreparation::new (runtime.rs:721 → runtime.rs:1011).
      • Downstream KV-codec regression: When flare-offload-{rank} lazily initializes selene/src/shared/codec.rs:37-60 (helios/src/offload/transfer/codec.rs:353,514,751), std::thread::available_parallelism() (selene/src/shared/codec.rs:41) honors the inherited sched_getaffinity mask. On GB10 (10 X925 + 10 A725), flare-kv-codec-* silently shrinks from 20 / 2 = 10 threads to 10 / 2 = 5 threads, and all 5 nice(10) codec workers (:52) are pinned onto X925 alongside the model worker and RoCE proxy — directly contradicting docs/prefix-cache-offload.md:863-867 ("Adding CPU affinity requires a serving-latency measurement that shows a benefit").
      • Subtle interaction with moving :568: flare-rank-{1..N} in same-process threaded TP (helios/src/execution/threaded.rs:652-655) has no direct pin call and is currently pinned only by inheriting flare-model's mask via RankExecutor::new (runtime.rs:585). Moving runtime.rs:568 down to before worker.run alone will silently unpin all threaded-TP peer ranks.
    • Concrete fix:
      1. Move flare_eos::prefer_high_capacity_cpus(); in helios/src/server/runtime.rs from :568 to right before worker.run(&mut executor) (:726), after RankExecutor::new, crate::offload::open, and ImagePreparation::new have spawned their background threads.
      2. Add an explicit flare_eos::prefer_high_capacity_cpus(); at entry to the flare-rank-* thread closure in helios/src/execution/threaded.rs:654 so same-process threaded TP ranks remain explicitly pinned without relying on parent inheritance.

Should Fix

  1. Rebase onto main (resolving #589 drift in eos/src/unix.rs and helios/build.rs)

    • main (50c876df) has 11 commits above this PR's base, including #589 (ba3afb13) which added map_host_advises_hugepages_and_prefaults_zeroed_pages to eos/src/unix.rs:207-248 and introduced helios/native/roce_proxy_dlopen.c + helios/build.rs:67-77. Rebasing is required before merge and unlocks the Flare-owned wrapper for Blocker 1.
  2. serve_rank mutates the caller's thread affinity permanently and before validation (helios/src/execution/parallel.rs:539)

    • Verified behavior & impact: Unlike the other call sites (which run on dedicated newly spawned threads), serve_rank runs on the caller's thread (flare-cli/src/main.rs:560, which exits after return, and heliopause/src/python.rs:548, which runs on the Python interpreter thread inside py.detach). Calling prefer_high_capacity_cpus() at :539 narrows the caller's affinity even if early validation rejects the manifest (:540-550), never restores it on return, and is undocumented in # Safety (:529-532). (Note: do not delete pinning from serve_rank, as it IS the peer execution loop for multi-host TP ranks 1..N.)
    • Concrete fix: Move the affinity narrowing after manifest validation (parallel.rs:550) and use the same scoped save-and-restore RAII affinity guard recommended for roce_start in Blocker 1 so any caller (especially embedded Python via heliopause) gets its original affinity mask restored on return.

Subtract / Simplify

  1. Delete the 66-line C duplicate in helios/native/roce_proxy.c:1505-1570 (covered in Blocker 1) — eliminates the entire duplicated, untested C implementation in favor of the single unit-tested Rust helper in eos/src/unix.rs.
  2. Delete the speculative three-tier fallback and its test (eos/src/unix.rs:195-204, :298-314) — 27 lines that only trigger on three-tier SoCs (1 prime + mid + little cores), which are not a supported Flare target (AGENTS.md:188-193: no speculative compatibility/fallback layers). The existing selected.len() >= 2 && selected.len() < allowed_with_capacity.len() check at :205 already guarantees the selector never collapses onto a single core.
  3. Make select_high_capacity_cpus private (eos/src/unix.rs:172) — eos/src/lib.rs:12 uses pub use unix::*;, leaking select_high_capacity_cpus into flare-eos's public crate API on Unix only (asymmetric with Windows) despite having no external callers. Change to #[cfg(any(target_os = "linux", test))] fn select_high_capacity_cpus(...) (gating avoids a dead_code warning on non-Linux Unix targets like macOS).

Nits

None. (Note: @original-el8's existing review item 3 regarding commit-message text and Design-Signed-Off-By hygiene remains to be addressed on rebase/amend.)

Dropped on verification