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

Raw Markdown for agents: https://autobot.eidonix.com/p/cf3e06b7-2df8-4cf2-b280-39b80d199783.md

Subtraction & Simplicity Audit — PR #742 (selene,helios: bound pool-only capture buffer to max_sequence_pages), head 66d6af3

Verdict: the diff is essentially lean. +94/−21 across 9 files, of which only +9/−1 is real logic (selene/src/offload.rs:164-168) and +32/−1 is planning plumbing (helios/src/runtime_core/memory.rs); the rest is one doc paragraph and 8 test-fixture lines. No new CLI flags, no new config knobs, no new wire/core-format surface, no new environment variables. The change is a clamp, not a feature, and the author kept it that way. The findings below are all local: a duplicated formula the PR now leans on harder, one clamp expression copied three times, one unreachable validation branch, and one optional that no production caller sets.


1. High value — duplicated minimum-page formula, now load-bearing in two places

The same default page floor is computed independently in two functions in the same file, and this PR's first-pass charge (helios/src/runtime_core/memory.rs:1136) now hands the second copy's result into the first copy's consumer:

helios/src/runtime_core/memory.rs:704-706 (inside capacities):

let minimum_pages = page_limit.map_or(active * 8192u64.div_ceil(page_tokens), |limit| {
    limit.minimum
});

helios/src/runtime_core/memory.rs:1001 (inside allocate_caches):

let minimum_pages = ceiling.map_or(active as u64 * 8192u64.div_ceil(page_tokens), |limit| limit.minimum);

Two identical 8192u64.div_ceil(page_tokens) floors with two subtly different active types (u64 vs as u64), one of which is charged as "the reserved capture floor" at :1136 (capture.then_some(minimum_pages)) and then re-derived from scratch at :704 during the binary search. Extract fn minimum_pages(page_limit: Option<PageLimit>, active: u64, page_tokens: u64) -> u64 and call it from both — it deletes the second literal, removes the as u64/u64 drift, and makes it impossible for the reserved floor and the searched floor to disagree (which is exactly the failure class this PR exists to prevent for max_sequence_pages).

2. High value — the cap expression pages.min(max_sequence_pages.get()) is copy-pasted three times in production and three times in tests

Note that memory.rs:1556-1559 is arithmetically the same expression as the body of capture_growth (memory.rs:668-682: slots = pages.checked_add(layout.row_slots()), slots * layout.page_record_bytes), just without the reserved subtraction. Add fn capture_slots(layout: &Layout, pages: u64) -> u64 returning (pages + row_slots) * page_record_bytes, and give memory.rs a one-line local let chain_pages = pages.min(max_sequence_pages.get()); before :1490 — that is 3 sites → 2, and removes one hand-rolled copy of capture_growth's arithmetic that can silently drift from it.

3. Medium value — the second context validation is unreachable (dead error branch)

helios/src/runtime_core/memory.rs:993-1000:

let context = self.server_config["max_sequence_tokens"]
    .as_u64()
    .filter(|&tokens| tokens > 0)
    .ok_or_else(|| invalid("model requires a prepared context ceiling"))?;
let ceiling = page_ceiling(options.kv_cache_limit, context, active as u64, &contract)?;
let max_sequence_pages =
    std::num::NonZeroU64::new(context.div_ceil(contract.cache.page_tokens as u64))
        .ok_or_else(|| invalid("model requires a positive prepared context ceiling"))?;

context > 0 is guaranteed by :995, page_tokens != 0 is guaranteed by :896-899 (.filter(|&tokens| tokens != 0)) and by PreparedContract::validate (helios/src/model/contract.rs:536), so div_ceil ≥ 1 always and the "model requires a positive prepared context ceiling" string can never be produced. It is a second user-facing error message for a state the preceding line already rejected. Drop the .ok_or_else and merge the two checks into one, e.g. keep the filter(|&tokens| tokens > 0) and write NonZeroU64::new(context.div_ceil(page_tokens)) with the invariant stated in a comment — saves 3 lines and one unreachable message that would otherwise confuse future readers into thinking a zero-page ceiling is reachable.

4. Medium value — Option<NonZeroU64> is speculative generality: no production caller ever passes None

helios/src/runtime_core/model.rs:1125:

max_sequence_pages: Option<std::num::NonZeroU64>,

The single production call site passes Some(planned.max_sequence_pages) (model.rs:1052) and every other call site in the repo is a test passing None (model.rs:1562, :1574). The Option then propagates into selene/src/offload.rs:345 and forces the map_or at offload.rs:165-167 plus the if max_sequence_pages.is_some() branch in selene/src/offload/tests.rs:558-560.

Two clean options, in order of preference:

Whatever the choice, the 8 fixture lines (helios/src/offload/pool/tests.rs:134, selene-manager/tests/client.rs:3255, :3509, selene-manager/tests/offload.rs:139, selene/src/offload/sharded/tests.rs:118, :261, :392, :558, plus selene/src/offload/tests.rs:14, :51, helios/src/runtime_core/memory.rs:2036) are pure churn caused by the optional; a non-optional bound on the private path removes half of them.

5. Low value — the doc paragraph states the same bound twice, and one sentence now contradicts it

docs/prefix-cache-offload.md:1593-1602 says the ceiling three times:

  1. :1594-1597 — "one full single-sequence capture chain (min(GPU page capacity, ceil(max_sequence_tokens / page_tokens)) plus one row's slots), bounded by the host budget."
  2. :1599-1600 — "Helios limits GPU page capacity so one sequence chain plus one row fits the host budget."
  3. :1601-1602 — "If even the capped minimum page capacity plus one row does not fit …"

(2) restates (1) with no new information. And :1605-1606 still reads "If a capture has no resident ancestor, it copies the full GPU chain" — two sentences below the new ceiling, the same "unbounded KV" reading the ceiling was added to correct. Delete sentence (2) and qualify (3) with "capped chain", then change :1605-1606 to "copies the whole sequence chain (at most the ceiling above)". Net −2 lines and the paragraph stops arguing with itself.

6. Nits


Confirmed lean (checked, no action)