Final review report · NVIDIA/hyperflare-inference #726

Raw Markdown for agents: https://autobot.eidonix.com/p/1fe56347-bf37-4519-a961-dfb478c0ffdb.md

Recommendation: Changes Requested

PR #726 tackles a real startup bottleneck in the right shared runtime layer (helios/src/runtime_core), and its core mechanics—4 KiB-aligned zero-copy MappedHost reads with staged edges, 512 MiB registration chunking, RegistrationGate ordering, and reverse-order VMA/registration teardown—hold up well under boundary review. However, the PR is not ready to merge as-is: the headline 75.0 s → 45.5 s speedup was measured pre-rebase on the combined feat/gb300-tiered-runtime stack (#710) rather than on head 60d1b6b against main (violating Charter #210 / Principle 12 / AGENTS.md:99-100), and independent verification confirmed four real issues that should be fixed before merge: error-path RegistrationGate::close() bypass in register_pending_mapped_host, silent partial-load Ok(()) / unwoken sibling waiters in load_mapped_host_chunks, unconditional MADV_HUGEPAGE + 8-thread eager pre-faulting reintroducing the #616/#625 THP compaction-stall hazard, and un-updated normative loader/CLI docs paired with a multi-rank staging-cap overshoot in choose_io_plan.

Merge Risk

Level: High

Walkthrough

Pre-merge Checks

Blockers

  1. Performance claim is not measured on 60d1b6b against main (combined-stack pre-rebase result from #710) — PR description ("Supporting Evidence and Limitations") vs Charter (#210), docs/design-review.md:109-115 (Principle 12), and AGENTS.md:99-100.
    • Verified issue: The PR states that the 75.0 s → 45.5 s cold-start measurement was collected "on the equivalent feat/gb300-tiered-runtime build prior to rebasing cleanly onto main". That branch is open draft #710, which also includes the host-VMA/THP/pre-fault changes (helios/src/runtime_core/mod.rs +120/−44), speculative cost/forecast changes, and GB300 AOT updates. Charter #210 requires performance PRs to show "an actual speedup over main on a served workload", and AGENTS.md:99-100 explicitly prohibits attributing a combined-stack measurement to a single PR.
    • Fix: Re-run the flare run cold-startup A/B benchmark on rebased head 60d1b6b directly against current main (attaching the raw per-phase timing output and hardware/THP configuration) and clarify ownership of the duplicated VMA work relative to #710.

Should Fix

  1. register_pending_mapped_host bypasses RegistrationGate::close() on every error path — helios/src/runtime_core/mod.rs:804-847 (callee helios/src/runtime_core/payload.rs:583-630; caller helios/src/runtime_core/model.rs:1152-1170, 1359-1390).

    • Verified issue: Lines 804-843 place ? (805, 810-813, 831-834) and return Err(...) (836-839) directly inside an unsafe { ... } block rather than an immediately invoked closure. In Rust, those return immediately from register_pending_mapped_host, completely skipping if let Some(gate) = gate { gate.close(); } at 844-846. In single-rank startup, model.rs:1165-1170 happens to close all gates after runtime_result returns, masking a permanent deadlock—but in multi-rank TP (devices.len() > 1), model.parallel (model.rs:1380-1388) joins every rank thread before returning Err to line 1165, so a failing rank leaves its host readers parked until every other rank finishes registering all 512 MiB chunks (and any direct caller relying on register_pending_mapped_host's contract would deadlock permanently).
    • Fix: Wrap the body in (|| -> Result<()> { unsafe { ... } })() (or a Drop guard that closes gate even on unwind) so gate.close() is structurally guaranteed on every return path.
  2. load_mapped_host_chunks silently returns Ok(()) on premature non-cancelled gate closure and does not wake parked sibling readers on I/O error — helios/src/runtime_core/payload.rs:682-696, 754-777 (callee payload.rs:620-629; caller model.rs:1085-1143, 1180-1181).

    • Verified issue: Two error-handling defects in the host reader loop:
      1. At payload.rs:691-696, when !gate.wait_for(required, cancel), the worker simply breaks without recording an error. If gate.close() occurred before chunk required was registered while cancel == false, load_mapped_host_chunks returns Ok(()) with unread/zeroed MappedHost weight chunks and an under-counted Load weights progress total. (Note: when cancel == true due to an external failure in runtime_result, returning Ok(()) is needed so model.rs:1180-1181 surfaces runtime_result's root error rather than a synthetic cancellation error—so the error should fire specifically when !cancel.load(Ordering::Relaxed).)
      2. At payload.rs:754-761, when a reader encounters an I/O error, it sets cancel.store(true, Ordering::Relaxed) without calling gate.close(). Any sibling reader on the same rank already parked in Condvar::wait (payload.rs:626) will not wake until register_pending_mapped_host finishes its in-flight 512 MiB cuMemHostRegister_v2 call and closes the gate (and model.rs:1117 cannot close gates until load_mapped_host_chunks joins all sibling readers).
    • Fix: On !gate.wait_for(required, cancel) when !cancel.load(Ordering::Relaxed), record an error in first_error (e.g. invalid("mapped host registration closed before chunk was ready")) and set cancel. On reader error at payload.rs:754-761, also call if let Some(gate) = gate { gate.close(); } so parked sibling readers wake immediately.
  3. Unconditional MADV_HUGEPAGE + 8-thread eager pre-faulting reintroduces the #616/#625 THP compaction-stall hazard — helios/src/runtime_core/mod.rs:2260-2265, 2274-2324 vs docs/prefix-cache-offload.md:540-557 and merged #625.

    • Verified issue: Prior main (pr/721 mod.rs:623-658) did not call MADV_HUGEPAGE or pre-fault MappedHost spans. #726 unconditionally issues libc::madvise(mapped, span_bytes, libc::MADV_HUGEPAGE) on every coalesced MappedHost span (316.6 GiB in the PR's workload) and immediately faults it at 2 MiB stride across up to 8 concurrent threads (mod.rs:2288-2324). Under Linux's default workstation THP settings (enabled=madvise, defrag=madvise or defer+madvise) on fragmented memory, this triggers synchronous direct reclaim/compaction (__GFP_DIRECT_RECLAIM) on every hugepage fault—the exact stall that caused #616 (>15 minutes on 119 GiB) and that merged #625 retired in eos::map_host (docs/prefix-cache-offload.md:541-557, where #625 measured 128.6 s vs 31.0 s for just 48 GiB on SM120).
    • Fix: Inspect /sys/kernel/mm/transparent_hugepage/{enabled,defrag} (reusing or sharing eos/src/unix.rs's Linux THP policy logic) so MADV_HUGEPAGE is only applied unconditionally under non-blocking defrag policies (defer/never), or falls back cleanly to base pages when huge pages are scarce / compact_stall climbs; disclose the THP policy behavior explicitly in the PR description.
  4. Normative loader/CLI design docs contradict the shipped changes, and choose_io_plan can exceed its stated 128 MiB cross-rank staging bound at high rank counts — helios/src/runtime_core/payload.rs:143-150, 205-251, helios/src/startup.rs:178-203, helios/src/runtime_core/model.rs:858-862 vs docs/runtime-core-design.md:1006-1018, 1095, docs/core-format-design.md:853-861, docs/cli-design.md:1589-1607.

    • Verified issue:
      • docs/runtime-core-design.md:1010-1018, 1095 specifies 4 reader threads, 4 pinned staging buffers of 4 MiB / rank_count, a 16 MiB process-wide staging bound, staging copies for host-resident payloads, and readers joining before module/graph setup. docs/core-format-design.md:857-858 states "The staging bound is process-wide; adding ranks must not multiply it." docs/cli-design.md:1589-1607 describes startup rows without the new " · overlapped" replay suffix (startup.rs:186) or "(overlapping)" allocation detail (model.rs:859). None of these docs are updated.
      • In choose_io_plan (payload.rs:222-244), optimal_io_size can round chunk_bytes up to MAX_CHUNK (8 MiB) without dividing by ranks, while per_rank_budget clamps at .max(chunk_bytes * 2) (240) and budget_slots clamps at .max(2) (242). On multi-rank setups with a large optimal_io_size or tight RAM (e.g., ranks = 16, optimal_io_size = 8 MiB), total pinned staging across ranks reaches 16 × 2 × 8 MiB = 256 MiB, violating both docs/core-format-design.md:857-858 and the PR's claimed <= 128 MiB cross-rank cap.
    • Fix: Cap chunk_bytes (including after optimal_io_size rounding) against (total_budget / ranks / 2) so multi-rank staging cannot exceed total_budget (<= 128 MiB), add a unit test asserting ranks * slots * (chunk_bytes + 2 * BLOCK) <= MAX_STAGING_BYTES across TP1/TP4/TP8/TP16, and update docs/runtime-core-design.md, docs/core-format-design.md, and docs/cli-design.md to document the new runtime staging budget, zero-copy host loading, and overlapped stage output.

Subtract / Simplify

  1. Replace four duplicated cleanup(&mut outcome) sites with RAII Drop on MappedHostAllocation — helios/src/runtime_core/mod.rs:2167-2170, 2230-2258, 2325-2342. Implementing Drop to reverse-munmap self.mappings (disarmed when attach_mapped_host drains mappings into self.host_mmap_spans) eliminates the cleanup closure and all four manual error/cancel teardown blocks while mechanically enforcing the SAFETY comment at line 2187.
  2. Deduplicate the read_at short-read loop in Chunk::read and Chunk::read_direct_into_host — helios/src/runtime_core/payload.rs:363-422. Both implement identical Interrupted-retry, EOF, and BLOCK-alignment checks; extracting one fn read_full_at(file: &File, offset: u64, dst: &mut [u8]) -> io::Result<()> removes ~25 duplicated lines.
  3. Hoist the duplicated post-load tail and simplify pending_registrations round-tripping in NativeModel::load_agreeing — helios/src/runtime_core/model.rs:882-906, 1146-1155, 1182-1217. The four post-load statements (apply_payload_relocations, integrated release_page_cache, load_phase.finish) are identical in both arms (1182-1191 and 1208-1217), and pending_registrations is converted Vec → Mutex<Vec<Option>> → Vec → Mutex<Vec<Option>> with silent unwrap_or_default() fallbacks.
  4. Remove dead tuple element from tier_io_plan and redundant optimal_io_size bounds check — helios/src/runtime_core/payload.rs:173-175, 222, 482-522, 640, 792. Both callers discard tier_io_plan's second return value (plan, _), and choose_io_plan:222 re-checks the exact BLOCK..=MAX_CHUNK / % BLOCK == 0 predicate already enforced by detect_optimal_io_size:173-175.
  5. Unify PendingHostRegistration platform fields and RegistrationGate emptiness checks — helios/src/runtime_core/mod.rs:2132-2163, 797-856, model.rs:1053-1059, payload.rs:599, 621. Making PendingHostRegistration.chunks: Vec<(u64, usize, u32)> unconditional (always empty off-Unix) removes redundant #[cfg(not(unix))] arms and duplicated emptiness checks.
  6. Keep StartupObservation.completed retention opt-in — helios/src/startup.rs:111-113, 136-138, 170-175. Only model.rs:1075 (overlapped background phases) and tests call completed_phases(); making completion retention opt-in avoids cloning and retaining every completed snapshot across all non-overlapping observed loads.

Nits

Dropped on verification