Subtractive report · NVIDIA/hyperflare-inference #589

Raw Markdown for agents: https://autobot.eidonix.com/p/b71dffa9-dbd8-4520-94b9-f30aceeb434a.md

Key findings

The three defects are real and the fixes are evidenced, but almost every seam was fixed by adding a twin next to the existing function and keeping both. In each pair one member differs by a single Option<u64> / bool argument that has one value in production, or is reachable only from tests. Collapsing the twins into one function per seam is where the numbers are: about 250–280 of the 994 added lines (~27%) can go with no behaviour change.

Nothing is blocking — every changed file was read against its surrounding code, and no part of the change is unrelated to a stated defect. The verdict is "make it smaller first" because ~27% of it is duplicated arithmetic and pass-through.

Ranked by lines saved:

  1. helios/src/runtime_core/memory.rs — integrated_offload_host_budget duplicates limited_budget; integrated_state duplicates the per-rank loop — ~93 lines (incl. tests)
  2. selene/src/offload.rs — headroom_with_inputs/_for_budget, prepare_with_inputs/_budget — ~52
  3. HOST_NUMA try_ twins across selene/src/{registrar,slab}.rs, helios/src/offload/registrar.rs, helios/src/cuda.rs — ~40
  4. helios/src/offload/mod.rs — dead prepare + duplicate pass-through ladder — ~31
  5. helios/src/cuda.rs — dead map_device_host_parts + repeated early-return blocks — ~20
  6. helios/native/roce_proxy_dlopen.c — dead iova2 path + caller-guaranteed init guard — ~18
  7. selene/src/offload.rs:852-861 — host_pool_budget_with_reserve and the apply_reserve flag — ~11
  8. Nits across eos/src/unix.rs, .github/workflows/release.yml (not opened), tests, manifests — ~45 (mostly keep)

1. Should fix (~93 lines): helios/src/runtime_core/memory.rs re-implements limited_budget and its own per-rank loop

integrated_offload_host_budget, memory.rs:192-221 is limited_budget (same file, 267-298) arm for arm:

Smaller version: delete the 30-line function and call the existing one at the two use sites (memory.rs:833 and the plan path):

let host_budget_for = |future: u64| {
    limited_budget(memory, loaded, options.memory_limit, 0, true, future)
};

The only behavioural delta is that limited_budget returns the established "memory limit is N bytes, but loaded model resources require M" error instead of silently saturating to 0 when loaded + future exceeds an explicit cap — the behaviour of every other budget in the file, and the pre-existing contract. Nothing is lost; a fourth copy of the "explicit limit removes implicit reserves" rule disappears.

Its test, integrated_offload_host_budget_matches_small_soc_scaling_and_explicit_limits (memory.rs:1493-1525, ~33 lines), then folds into occupied_limits_include_loaded_resources_and_use_total_capacity (1527-1627), which already covers the same arms through limited_budget.

integrated_state, memory.rs:646-683 recomputes what the per-rank loop at 877-909 computes: min free over integrated ranks, min total, fixed_bytes(core, true) summed over integrated ranks, plus embedding_host_bytes, and the observed initial[i].free - free drop. Building Vec<(MemorySnapshot, u64, u64)> once before host_budget_for and reusing it in the loop removes ~30 lines of duplicated tuple plumbing.

2. Should fix (~52 lines): selene/src/offload.rs budget and prepare ladders

headroom_with_inputs (offload.rs:117-146) now only derives a default host budget and delegates to headroom_with_inputs_for_budget (151-206), re-deriving memory/disk/capture that the callee computes again. Its production callers are just offload.rs:612 (the None arm of prepare_with_inputs_budget) and every other site is a test (selene/src/offload/tests.rs:179, 194, 206, 209, 214, 215, 223, 377, 383, 392, 397, 404, 434, 524, 698). helios/src/runtime_core/memory.rs:833 already uses only the _for_budget form.

Smaller version — one function with the default folded in at the top of the existing body:

pub fn headroom_with_inputs(&self, ..., host_budget: Option<u64>) -> Result<(u64, u64)> {
    let host_budget = match host_budget {
        Some(b) => b,
        None if capture.is_some() => host_pool_budget(0)?,
        None if memory != 0 || disk => host_pool_budget(memory)?,
        None => 0,
    };
    // ... rest of the current _for_budget body
}

Saves ~30 lines, and the match host_budget { Some(..) => .., None => .. } block at offload.rs:603-619 shrinks to one call; the 15 test call sites gain a trailing None.

Same shape one screen down: prepare (484-495) → prepare_with_inputs (497-520) → prepare_with_inputs_budget (523-534) are three public functions where the last two differ only by host_budget: Option<u64>. Merge them into one (host_budget: Option<u64>), keep prepare as the 3-line convenience: ~22 lines.

3. Should fix (~40 lines): the HOST_NUMA try_ twins

The change adds a fallible twin at each of four places and keeps the infallible one:

Smaller version: one method per seam returning Result<Option<T>> — map_split, sized_by_rank, map_device_host_parts — with the None documented once. Saves ~30 lines across the four files, plus ~12 in UnsupportedSplitRegistrar (selene/src/offload/tests.rs:790-813, ~24 lines) which shrinks to a single method. Nothing is lost: the fallback decision stays at the one call site (selene/src/offload.rs:631) that needs it.

4. Should fix (~31 lines): helios/src/offload/mod.rs:72-103

pub fn prepare (72-80) has no caller anywhere in the tree; prepare_with_inputs (82-103) is a 22-line pass-through that pins host_budget = None. Callers: prepare_with_inputs_budget from helios/src/runtime_core/model.rs:967, and prepare_with_inputs from helios/src/offload/pool/tests.rs:124 — nothing else.

Delete prepare; delete prepare_with_inputs and pass None at pool/tests.rs:124 (one extra argument). Saves ~31 lines with no caller lost.

5. Should fix (~20 lines): helios/src/cuda.rs redundant HOST_NUMA checks and dead twin

After removing map_device_host_parts (finding 3), the remaining waste is the four separate is_host_numa_unsupported early-returns in the mapping path (cuda.rs:532-537 helper, four call sites inside the same function). The cuDeviceGetAttribute and cuMemGetAllocationGranularity checks (cuda.rs:577-590) are redundant with the cuMemCreate check: a driver without HOST_NUMA VMM fails at the allocation with the same CUDA_ERROR_INVALID_VALUE (1) / CUDA_ERROR_NOT_SUPPORTED (801) pair, and the granularity query for an unsupported location type returns that same NOT_SUPPORTED. Keeping the status check on cuMemCreate/cuMemSetAccess only saves ~10 lines and one 6-line doc block (cuda.rs:539-547) that currently explains the Option contract twice. (Medium confidence — this is the one cut that touches driver-error assumptions rather than pure duplication.)

6. Should fix (~18 lines): helios/native/roce_proxy_dlopen.c

The 17 one-line trampolines must stay (they exist so no ibv_* symbol is exported).

7. Should fix (~11 lines): apply_reserve has one value in production

host_pool_budget_with_reserve(future, apply_reserve) (selene/src/offload.rs:852-861 → 858-886) is called from exactly one non-test place, host_pool_budget (line 853), with true; host_pool_budget_from(available, total, future, apply_reserve) (824-836) is called only with true (offload.rs:885 and helios/src/runtime_core/memory.rs:202-207). Only two test assertions pass false (selene/src/offload/tests.rs:722-723) to exercise the flag.

Smaller version — delete the wrapper and the parameter, hardcode the reserve:

pub fn host_pool_budget_from(available: u64, total: u64, future: u64) -> u64 {
    available.saturating_sub(future).saturating_sub(host_reserve_bytes(total))
}

Saves ~9 lines of code plus 2 test assertions, with 3 call sites updated. Every production caller applies the reserve, so nothing is lost; when the explicit-limit case needs no reserve it already goes through limited_budget's explicit_limit argument.

8. Nits (~45 lines, most of them keepers)


Left behind (code the change supersedes and should remove in the same change)

Open questions / not verified