Subtractive scratchpad · NVIDIA/hyperflare-inference #505

Raw Markdown for agents: https://autobot.eidonix.com/p/4ad94cbf-1e65-47df-883e-a23df7284a6d.md

#1 [high] Should fix: duplicate core-parameter copies and bit-equality guard (~55 lines)

Both copies come from the same source and cannot diverge, so one copy plus the guard can go.

Sources of the same value:

What goes:

  1. Admission.core_parameters field (admission.rs:62) and its config.contract.validate_core_parameters(&self.core_parameters)? (admission.rs:74-76): the values were already resolved and range-checked by PreparedContract::resolve_core_parameters at the HTTP boundary (server/request.rs:333-335) before the Prompt existed, and validated again in plan_admission_with_core_parameters (scheduler.rs:1548-1552).
  2. The 14 core_parameters: Default::default(), fixture lines this change added in helios/src/model/tests.rs (:544, :689, :1005, :1163, :1377, :1592, :1811, :2050, :2152, :2415), model/packed_round_tests.rs:124, server/runtime.rs:3030, :3286, :3621, server/runtime/phase_tests.rs:215, prompt_tests.rs:53 — they exist only to fill the new field.
  3. The pack-time cross-check in packing.rs:588-597 (planned + value.to_bits() != planned.to_bits() + error), which compares the two copies, plus LiveRequest::core_parameters() if packing reads the plan copy instead.

Smaller version: packing.rs:582-587 reads the value from one place only:

if binding.source == ValueSource::CoreParameter {
    let value = live.core_parameters().get(&binding.parameter).copied()
        .ok_or("core-parameter admission is incomplete")?;

Nothing is lost: the resolved map is immutable after admission, so a mismatch between two clones of it is unreachable; the prefix hash already used the same bits (scheduler.rs:1560-1566).

Lines: ~2 + 3 + 15 fixtures + 12 guard + 4 accessor ≈ 36-55 depending on whether the accessor stays.

#2 [high] Should fix: is_text_forward_graph duplicates GraphKind::samples (~14 lines)

helios/src/model/contract.rs:424-435 adds

pub(crate) fn is_text_forward_graph(kind: GraphKind) -> bool {
    matches!(kind, GraphKind::Prefill | GraphKind::TerminalPrefill | GraphKind::ScoredPrefill
        | GraphKind::Resume | GraphKind::Decode | GraphKind::Speculative | GraphKind::Mixed)
}

helios/src/execution/manifest.rs:89-100 already has GraphKind::samples() with the identical set (Prefill, TerminalPrefill, ScoredPrefill, Decode, Speculative, Mixed, Resume) and it is already the vocabulary used elsewhere for "this graph runs a forward that samples" (manifest.rs:940, transport.rs:1537/1552, server/runtime.rs:2969, model/testing.rs:171).

Replace both call sites (contract.rs:665, packing.rs:140) with descriptor.kind.samples() / graph.kind.samples() and delete the helper. Saves 12-14 lines, and removes a second list that must be kept in sync with samples(). Also delete the duplicated seven-kind matches! in the new test helper helios/src/model/tests.rs:59-77 and phase_tests.rs:6637-6652 by using kind.samples() there too (~+12 lines).

#7 [high] Overall assessment and what is justified

The change touches 32 files, +2393/-261 (orientation packet). Roughly +1,530 of that is Rust and Python product code, +760 tests, and +45 docs. Nothing in this repository binds a core parameter (PR description: "No model recipe in this repository binds a core parameter (official recipes live in local-inference-lab/hyperflare-recipes)"), and the GPU path was never run on this head ("Live GPU export and serving of a core declaring core_parameters were not run").

Verdict against the charter: this is a new captured-graph op contract (CORE_PARAMETER = 43 changes ValueSource, shared by every core) and the charter says such an addition "requires owner approval before you write it" (Charter, Standards & Contributions: "Captured-graph op contracts: Adding a new one—even if it reuses an existing graph kind—requires owner approval"). Luke's comment on #404 (2026-11-21) is the request that motivated it ("implement this not as a hardcoded steering_scale parameter, but as a generic system by which model cores can expose scalar arguments"), so the direction is sanctioned; the size is not, and the same #404 review demanded the shared-path cost be kept small.

Checked and found justified (no subtraction):

Total available subtraction: ~150-330 lines, dominated by the Python direct-path validator reimplementation.

#8 [high] Research summary

Reviewed PR #505 (Bind core-declared FP32 parameters into text forward graphs, +2393/-261, 32 files) through a subtraction lens. The direction is sanctioned — Luke's #404 comment asked for exactly this generic mechanism — and the core wire additions (CoreParameter, ValueSource::CORE_PARAMETER, ValueBinding.parameter, the recipe-facing contract.py helpers) are minimal and necessary. What is not minimal is the amount of duplicated validation and duplicated copies of the same resolved value.

Six findings recorded, ranked by size:

  1. ignition/direct/scheduler.py:131-185 (~90-200 lines) re-implements, in Python, the entire load-time core-parameter contract validation (distinct names, finite defaults, ranges, per-graph completeness, maintenance-graph rejection, indexing/offset/padding/tensor/dtype/row-count/contiguity). All of it already runs in helios/src/model/contract.rs:473-482,665-728 when the core is loaded, on the same prepared model object ignition/direct serves.
  2. Admission.core_parameters plus the pack-time bit-equality guard (helios/src/model/admission.rs:62,74-76; helios/src/model/packing.rs:588-597; ~36-55 lines) — the field is a second clone of the same map that LiveRequest.core_parameters holds, and the guard compares two clones that cannot diverge.
  3. is_text_forward_graph (helios/src/model/contract.rs:424-435; ~14 lines, +12 in tests) duplicates GraphKind::samples() (helios/src/execution/manifest.rs:89-100), which lists exactly the same seven kinds and is already the shared vocabulary.
  4. The same FP32 wire validation written four times (ignition/preparation/contract.py:12-28, ignition/direct/scheduler.py:50-65, helios/src/server/protocol/decode.rs:49-75, helios/src/model/contract.rs:453-462), plus -0.0 canonicalization threaded through five call sites for an invariant the charter does not ask for (~20-40 lines).
  5. helios/src/model/packing.rs:139-145,236-245,540-603 re-checks dtype, indexing and buffer extent that contract.rs already rejected at load (~12 lines).
  6. Nits (~25 lines): pass-through wrappers, six different error strings for the same overflow condition, and 17 lines of docs/api.md restating helios/model-contract.md.

Nothing was found that the change makes dead elsewhere. I explicitly checked and found justified: keeping PrefixHistory::new as a delegate to preserve the old root hash, AdmissionPlan.core_parameters surviving refresh_admission_plan, and the Inputs::core_parameters pre-allocation.

#9 [high] Diff accounting and smaller-version snippets for the report

Change size: 32 files, +2393/-261.

Product code added (~1,530 of it is Rust+Python, product code):

Where the Rust test bulk sits: helios/src/model/tests.rs ≈+460 (of which the two new tests ≈+390), server/runtime/phase_tests.rs ≈+225, runtime_core/protobuf.rs ≈+100, model/contract/kani_proofs.rs +60, cache/tests.rs +31, server/models.rs +31, server/protocol/decode.rs +44. The 15 one-line core_parameters: Default::default(), fixture lines are spread across model/tests.rs, packed_round_tests.rs, server/runtime.rs, phase_tests.rs, prompt_tests.rs.

Smaller version for finding 2 (packing.rs:582-597 collapses to):

if binding.source == ValueSource::CoreParameter {
    let value = live.core_parameters().get(&binding.parameter).copied()
        .ok_or("core-parameter admission is incomplete")?;
    ... write value ...
}

i.e. drop admission.core_parameters entirely and read the plan copy on LiveRequest.

Smaller version for finding 3: replace is_text_forward_graph(graph.kind) at contract.rs:665 and packing.rs:140 with graph.kind.samples() / descriptor.kind.samples(), delete contract.rs:424-435, and use kind.samples() in the two new test helpers (model/tests.rs:59-77, phase_tests.rs:6637-6652).

Smaller version for finding 5: delete the CoreParameter => { is_text_forward_graph(..) && matches!(indexing, SubmissionRow|RequestRow|ActiveRow) } arm at packing.rs:139-145 — the fallback arm _ => matches!(indexing, SubmissionRow | RequestRow | ActiveRow) already states the rule — and drop CoreParameter from the dtype group at packing.rs:236-239, restoring that group to SamplingParameters | ImageTensor | PageTable as it was before the change.

#3 [medium] Should fix: same FP32 wire validation written four times (~20-40 lines)

The change implements the same FP32 wire validation three times (twice in Python, once in Rust) plus a fourth canonicalization in Python direct:

Smaller version: one helper in ignition/preparation/contract.py imported by ignition/direct/scheduler.py, and in Rust one fn fp32(value: f64) -> Option<f32> next to canonical_core_parameter:

fn canonical(value: f32) -> f32 { if value == 0. { 0. } else { value } }

with resolve_value calling it and the decode map reusing resolve_value-style narrowing instead of its own copy. Saves ~20-30 lines and one whole duplicated float validator.

Also: the -0.0 canonicalization buys nothing observable. -0.0 == 0.0 and (-0.0f32).clamp(0.0, 1.0) returns -0.0, but hashing -0.0 and +0.0 as different prefix roots would only split cache entries for values the model computes identically. If canonicalization is dropped, canonical_core_parameter, its 5 call sites, the validate_value bit check (contract.rs:466), the /v1/models re-canonicalization (models.rs:79-85), the -0.0 test in models.rs:369-374, and the Python 0.0 if narrowed == 0.0 else narrowed lines all go (~40 lines). The stated behaviour "canonicalizes -0.0 to +0.0" is a self-imposed invariant, not something the charter requires.

#4 [medium] Should fix: packing.rs re-validates what contract.rs already enforced (~12 lines)

helios/src/model/packing.rs duplicates, at runtime, checks the load-time contract validator already made:

Smaller version: drop the CoreParameter arm from the valid_indexing match (falls through to the existing _ => matches!(indexing, SubmissionRow | RequestRow | ActiveRow), which is already the right rule) and the CoreParameter clause from the dtype check; the grouping becomes SamplingParameters | ImageTensor | PageTable again as before. Saves ~12 lines. Loss: none — an unloadable core never reaches Inputs::new.

#5 [medium] Should fix: ignition/direct re-implements contract validation already done in Rust (~90-200 lines)

The Python direct path re-implements the whole load-time contract validation in Layout.__post_init__ (ignition/direct/scheduler.py:131-185, 55 lines), covering: distinct named parameters, finite defaults, range keys {"min","max"}, range containing the default, every text forward graph binding every declared parameter, no bindings on maintenance graphs, indexing in {SUBMISSION_ROW, REQUEST_ROW, ACTIVE_ROW}, zero value_offset/padding, empty tensor, FP32 dtype, row count >= capacity, contiguity.

Every one of those rules already exists in helios/src/model/contract.rs:473-482 + :665-728 and is applied when the core is loaded/exported (serving_contract → PreparedContract::validate). ignition/direct serves the same prepared model object (ignition/preparation/model.py:24-36 copies the already-validated contract into server_config), and _validate_resources (ignition/preparation/graphs.py:125-181) already asserts buffer contiguity for every registered buffer. So the only new thing needed for direct execution is the packing case in packing.py:84 and the request-side resolution in scheduler.py:227-249.

Smaller version: keep _wire_fp32, resolve_core_parameters, core_parameter_identity, and drop the contract re-validation block (scheduler.py:131-185) and its buffer_contiguity field/_row_contiguous/_core_parameter_rows helpers (scheduler.py:68-81, :117-118, :213-216). Saves ~90 lines in scheduler.py plus ~110 of the tests that only exercise those rejections (tests/direct/test_scheduler.py:726-800 _core_parameter_layout knobs, :840-847, :910-940).

Caveat to state: ignition/direct can be pointed at a core produced by an older/other exporter, so if the maintainers want the Python path independently defensive this stays; but helios validates the same contract before Inputs is built (packing.rs:67), and the direct path is documented as diagnostic-only (docs/direct-execution.md:409 in the printed banner "not production serving").

#6 [low] Nit: small wrappers, duplicated error strings and docs (~25 lines)