Subtraction and simplicity report · NVIDIA/hyperflare-inference #707

Raw Markdown for agents: https://autobot.eidonix.com/p/11f73882-06cc-4be4-8843-c35ce90109b4.md

Subtraction & Simplicity Audit — PR #707

The diff is decent-sized (12 files, +1247/−129) but it is mostly the vendored C proxy (byte-identical, not ours to simplify) and tests. The hand-written Rust/Python does contain nine concrete subtraction opportunities, of which three are real dead or unreachable code and one is a genuine "invalid states unrepresentable" pairing. Ordered by value.


1. roce_gid_index is a dead export whose fallback can never fire (highest value)

heliopause/src/python.rs:693-706 adds a whole Python-visible function whose only consumer reaches it through unreachable code:

/// The first selected RoCE device's GID index by the rule native serving uses: each active device
/// prefers index 3 when it has a RoCEv2 IPv4 GID there, otherwise its own lowest RoCEv2 IPv4 GID
/// index. Prefer `roce_devices` when HCAs on the host may have distinct GID indices.
#[pyfunction]
fn roce_gid_index() -> PyResult<u32> {

The single call site is the legacy fallback in ignition/preparation/collectives.py:97:

gid_kwargs = {"gid_index": distinct[0] if distinct else flare_heliopause.roce_gid_index()}

distinct derives from devices = flare_heliopause.roce_devices() (:83), which is discover() and therefore survives only when at least one device was found. Discovery itself rejects the empty case, helios/src/execution/roce_fabric.rs:429-431:

if devices.is_empty() {
    return Err(failure("no active RDMA device has a RoCEv2 IPv4 GID"));
}

So distinct is never empty and the else flare_heliopause.roce_gid_index() arm cannot execute. That makes roce_gid_index (python.rs:669 registration + :693-706) dead, and takes Fabric::gid_index() (roce_fabric.rs:1094-1100, "The first selected device's RoCEv2 GID index, or PREFERRED_GID_INDEX when empty") with it — a public accessor whose unwrap_or(PREFERRED_GID_INDEX) default is likewise unreachable, kept alive only by the dead export and by tests (roce_fabric.rs:1242, :1276, :1303).

Subtraction: delete roce_gid_index + its add_function line, delete Fabric::gid_index(), and simplify collectives.py:97 to gid_kwargs = {"gid_index": distinct[0]}. Cleanest end state: move the mixed-GID RuntimeError out of the else and make it the unconditional legacy branch, so the legacy path drops both the fallback and the ambiguity. ~35 lines of Rust + the branch go away, and the PR's own description stops advertising a twice-documented API that nothing should call ("Prefer roce_devices…").

2. The inspect.signature feature probe is speculative generality against a hard pin

ignition/preparation/collectives.py:81-97:

    import inspect

    devices = flare_heliopause.roce_devices()
    gid_kwargs: dict[str, object]
    if "gid_indices" in inspect.signature(roce.AllReduce.__init__).parameters:

The repository pins FlashInfer to one exact commit — pyproject.toml:47:

flashinfer-python = { git = "https://github.com/local-inference-lab/flashinfer.git", rev = "524799c47fca54229c15b6db12261171854a7b7d" }

and the vendored proxy is CI-enforced byte-identical to that revision (new tests/preparation/test_roce_proxy_parity.py:35-65). roce.CreateWithGids exists in the C proxy at helios/native/roce_proxy.c:557, so the pinned AllReduce.__init__ accepting gid_indices is a fact of the pin, not a runtime question. The else branch at :90-97 (the mixed-GID RuntimeError and the uniform-GID legacy call) is unreachable in every environment the project supports, which in turn makes tests/preparation/test_roce_proxy_parity.py:83-85 (_AllReduceLegacy), :108-119 and :121-131 tests of code that cannot run. Signature introspection also costs an inspect import inside the hot preparation entry point.

Subtraction: drop the probe; always pass hca_names + gid_indices. If authority is wanted, assert the pin instead of probing for it. Removes ~18 lines of Python plus ~25 lines of the parity test's third case, and deletes the "fails loudly on an older FlashInfer" user-visible regression path the description itself flags as a limitation.

3. validate_relay_plan duplicates a predicate the C proxy already enforces

helios/src/execution/roce.rs:102-133 restates the C-side check nearly clause for clause — roce_fabric/roce_proxy.c:838-849:

    int bad = (p == c->rank && (via != -1 || to != -1)) ||
              (via != -1 &&
               (via < 0 || via >= c->world || via == c->rank || via == p || plan[via] != -1)) ||
              (to != -1 && (to < 0 || to >= c->world || to == c->rank || to == p));

versus Rust:

        let bad_self = p == rank && (via != -1 || to != -1);
        let bad_via = via != -1
            && (via < 0
                || via as usize >= world
                || via as usize == rank
                || via as usize == p
                || plan[via as usize] != -1);
        let bad_to =
            to != -1 && (to < 0 || to as usize >= world || to as usize == rank || to as usize == p);

roce_set_relay is already called with the same plan and already returns -1 with a message for every one of these conditions (roce.rs:344-353), so the Rust copy buys only a different error string and forces three of the "before modifying region" test cases (roce.rs:536-561, cases 11/12/13) to exist purely to exercise the duplicate. Simplification: keep the two checks the C side cannot make — shape != Shape::Mesh and plan.len() != 2 * world — and delete the per-entry loop (~22 lines) plus test cases 11/13; case 12 survives as the length check. The Shape::Mesh requirement also lands better as a relay_plan: Option<(Shape-agnostic plan)> invariant than as a validation arm (roce.rs:103-105 "RoCE all-gather relay requires a mesh topology" is only reachable because the mesh gate lives in the caller — see #7).

4. hcas + gid_indices should be one vector (invalid state is representable)

roce_fabric.rs:309-310:

    pub hcas: Vec<String>,
    pub gid_indices: Vec<u32>,

Two parallel vectors that must stay index-aligned, and the PR pays for the invariant in three separate places:

Reflecting the same idea back one level: Fabric already holds endpoints: Vec<Endpoint> where Endpoint.name is the HCA name (roce_fabric.rs:77, populated at :459-460 from the same name), so gid_indices is a shadow index into a vector that already carries its own key.

Simplification: make it pub devices: Vec<(String, u32)> (name, gid) on both Fabric and Topology, or keep gid_indices inside Endpoint. Then Fabric::gid_index_for (:1102-1105) collapses to field access, roce.rs builds its Vec<c_int> from the paired vector with no length check, python.rs:714-722 becomes a plain map with no zip truncation hazard, and the two error branches disappear. This deletes two validation blocks and one silent-truncation bug class for a net reduction in code.

5. relay_plan recomputes every route the caller already planned

roce_fabric.rs:1126-1132:

        let rails = endpoints.iter().map(Vec::len).min().unwrap().min(MAX_RAILS);
        let routes = plan_shape_routes(endpoints, rank, rails, shape, links)?;
        let relay_plan = if shape == Shape::Mesh {
            relay_plan(endpoints, rank, rails, links)?
        } else {
            None
        };

relay_plan → partners (:979-1012) constructs a second Planner::new (:988) and calls planner.peer(rank, peer) for all world × world pairs (:996) — O(world² × devices²) of route planning executed a second time, immediately after plan_shape_routes did the same work. The sibling helper direct_peers (:957) shows the intended shape: it takes routes as a parameter and reuses them.

Simplification: pass the already-computed &routes into partners/relay_plan (it contains exactly the (local, remote) pairs the cable test inspects) and drop the Planner construction and the rails/links parameters from both signatures — rails in particular is then only used by the Planner, and links can be folded into the caller's existing Shape::Mesh / Links gate at :1131. Removes a redundant planning pass and two of the four parameters on a pub fn.

6. format_gid_indices has an unreachable arm

flare-cli/src/doctor/spark.rs:259-262:

fn format_gid_indices(indices: &[u32]) -> String {
    match indices {
        [] => "index (none)".into(),

Both call sites guarantee non-empty input: spark.rs:189-190 builds ready_gids inside if !ready.is_empty() (:183), and spark.rs:246 formats fabric.gid_indices, which discover_in has already proven non-empty at roce_fabric.rs:429-431. The arm is additionally inconsistent with its siblings, which use "index N" / "indices [..]", not "index (none)".

Subtraction: drop the [] arm (or take first: u32, rest: &[u32] so emptiness is unrepresentable) and, per #4, the whole helper collapses to comparing indices.first() against the rest.

7. Interface::gid_index exists only to be collected straight back into a Vec

flare-cli/src/doctor/spark.rs:277 adds the field, :177 sets it, :189 immediately turns it back into a Vec<u32>:

            let ready_gids: Vec<u32> = ready.iter().map(|port| port.gid_index).collect();
            let gid_label = format_gid_indices(&ready_gids);

Interface is the output record of the readiness pass; the GID index is only needed as a label. Simplification: push gid_index into a separate Vec<u32> alongside ready, or compute gid_label from fabric/per-device lookups at :190, and keep Interface free of the field. Saves three touch points (struct field, two test literals at :516 and :524) and keeps Interface describing an interface, not a discovery decision.

8. cluster.rs nested if/else inside a format!

flare-cli/src/cluster.rs:101-113 grows the format to four placeholders and adds:

        if topology.relay_plan.is_some() {
            ", all-gather relay"
        } else {
            ""
        },

Now connected() has two independently-built "conditional middle segment" arms — Links::All => "" / Links::Shared => ", switch only" (pre-existing, :105-106) and this new one — spliced into one format string. Simplification: build the segments as a Vec<&str> and join(""), or implement Display for Topology and let both cluster.rs:94-113 and spark.rs:191-195 render it; one conditional-arm pattern instead of two. Small, but it's the kind of growth that makes the next transport flag add a fifth placeholder.

9. The mesh gate is split from the plan builder, leaving a redundant arm

relay_plan (roce_fabric.rs:1021) takes no Shape and gates only on world, % 2, and Links::Shared (:1031); the caller re-adds the shape gate (:1128). That split is what makes validate_relay_plan's shape arm (roce.rs:103-105) and roce.rs test case 11 (:536-539, which sets relay_plan on a Shape::Ring topology purely to trip the shape check) necessary in the first place. Simplification: fold shape into relay_plan's signature (:1021) and make it the single owner of "relay applies here"; the duplicate shape check in roce.rs and its test case disappear with it.


What is already lean

Minor, not worth its own item

tests/preparation/test_roce_proxy_parity.py holds both the vendoring guard (:35-65) and create_roce_runtime unit tests (:68-131) despite its name; if #1 and #2 are taken, the latter half shrinks to one forwarding assertion and belongs in tests/preparation/test_collectives.py (not opened).

Net

Taking #1, #2, #3, #6 and #7 removes roughly 100 lines of hand-written Rust/Python and three unreachable branches with no behavioural change; #4 and #5 remove two duplicated invariants and a redundant O(world²) planning pass. The PR's genuinely added logic — per-HCA discovery, the relay-plan derivation, and the parity guard — is lean and should stay as written.