Conventions report · NVIDIA/hyperflare-inference #505

Raw Markdown for agents: https://autobot.eidonix.com/p/bf95a3c1-d294-447a-afd5-1b2524921020.md

Conventions-and-duplication review — PR #505 "Bind core-declared FP32 parameters into text forward graphs"

Scope: all 32 changed files read as diff plus the surrounding code and call sites; judged against the charter (read_charter lines 12, 21, 35, 42), AGENTS.md ("Reuse … rather than duplicate", "Reject unsupported abstractions and churn", "smallest footprint in shared code"), and docs/design-review.md principles 3, 6, 10, 12 (native transport/scheduling/cache/packing "stay shared; use prepared metadata").

Key findings

  1. Should fix — The PR's new is_text_forward_graph is the same seven-graph-kind list as the existing GraphKind::samples(), and the PR writes that list out five separate times.
  2. Should fix — Core-parameter declarations are threaded as a new function argument through four runtime functions and ~8 call sites, instead of joining the existing SchedulerCapabilities bundle that already carries model geometry (vision is the direct precedent), leaving a production-dead plan_admission wrapper.
  3. Should fix — CoreParameterRange{min,max} re-declares the existing SamplingFloatRange (and Rust SamplingRange<f32>/SamplingRanges::validate), and the containment/clamp rule is re-implemented a fourth time.
  4. Should fix — _wire_fp32 is duplicated verbatim across two Python modules, in a package the second module already imports.
  5. Nit — packing.rs grows a second staging vector with hand-written bounds checks beside the new write_floats helper that the sampling path already uses for all three indexings.
  6. Nit — ignition/direct's _row_contiguous/Layout.buffer_contiguity re-checks contiguity already enforced by GraphBufferGroup, with a weaker verdict.
  7. Nit — Naming/placement drift in the new contract API (CoreParameters alias at module root, core_parameter() returning Option where graph() returns Result, one name validate_core_parameters meaning two different things in two modules).

No blocking issue: the change is carefully validated and every finding is a smaller-footprint alternative that reuses an existing mechanism, not a defect. One important positive: the PR does the right thing in PrefixHistory — PrefixHistory::new delegates to with_core_parameters with an empty list, so the exact flare-prefix-root-v1\0 || identity root is preserved rather than forking the hasher.


Should fix

1. The text-forward graph set is duplicated 5× and shadows an existing GraphKind predicate

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

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)
}

The repository already publishes exactly this set as a method on GraphKind:

Pre-existing inline copies of the same set already exist at helios/src/engram.rs:926-936 (pub(crate) fn consumes) and helios/src/server/runtime.rs:1681-1689, and this PR adds four more rather than collapsing them:

Why it matters: the graph-kind vocabulary is prepared metadata the runtime must not re-enumerate per feature. A future graph kind that samples but isn't "text forward" (or the reverse) will drift between samples() and is_text_forward_graph silently, and the maintenance-graph rejection list (VISION/INIT/RESTORE/SNAPSHOT) is only correct by coincidence of the two lists being equal today. It also puts a model-agnostic GraphKind predicate in model::contract rather than beside GraphKind where its siblings live.

Fix: delete is_text_forward_graph and call descriptor.kind.samples(); or, if the concepts must be allowed to diverge, add GraphKind::forward() next to is_prefill/samples with a comment saying why, and make engram::consumes, runtime.rs:1681, phase_tests.rs:6640 and model/tests.rs:60 use it. For Python, keep one tuple (e.g. in ignition/preparation/contract.py, derived from the wire enum) and import it in ignition/direct/scheduler.py and the tests.

2. Declarations threaded through four runtime functions instead of SchedulerCapabilities

helios/src/scheduler.rs:1526-1540, helios/src/server/runtime.rs:2738-2808

pub fn plan_admission(&mut self, spec: &AdmissionSpec<'_>) -> Result<AdmissionPlan> {
    self.plan_admission_with_core_parameters(spec, &[], &Default::default())
}
pub fn plan_admission_with_core_parameters(&mut self, spec: &AdmissionSpec<'_>,
    parameters: &[crate::model::contract::CoreParameter], core_parameters: &CoreParameters) -> Result<AdmissionPlan>

Because the scheduler does not hold the declarations, helios/src/server/runtime.rs gains a core_parameter_defs: &[crate::model::contract::CoreParameter] parameter on four functions — begin_pool_lookup (runtime.rs:2741), admit_with_checkpoint_accounting (runtime.rs:2777), admit_with_host_store (runtime.rs:2796) and their retry path (runtime.rs:2861, 2883) — with ~8 call-site edits, all passing &self.config.contract.core_parameters.

Precedent: model geometry that admission validates against already travels in SchedulerCapabilities (helios/src/scheduler.rs:96-110: vocabulary, page_tokens, vision: crate::model::VisionCapabilities, draft_pages_per_request, completion_inputs, speculative_allocations, state_rows_per_request), built by model::scheduler_capabilities(config) (helios/src/model.rs:308-341) and held by RequestScheduler::new(identity, limits, capabilities) (scheduler.rs:705+). vision is the exact analogue: a model-declared capability set the scheduler validates against, added to the bundle instead of as an argument on every admission entry point. Admission::validate and validate_prompt (helios/src/model/admission.rs:71-75, 134-138) likewise reach the contract through config, which is already in scope at every runtime call site.

Why it matters: this is the "smallest footprint in shared code" test. It also leaves plan_admission — the documented two-step admission API (docs/prefix-cache-offload.md:717 (not opened),775) — as a public wrapper that production no longer calls and that admits with "no parameters declared".

Fix: add core_parameters: Vec<CoreParameter> to SchedulerCapabilities, populate it in model::scheduler_capabilities, and keep a single plan_admission(&spec, &CoreParameters); delete the with/without pair and the four core_parameter_defs parameters.

3. A third range type and a fourth containment/clamp implementation

helios/proto/runtime_core.proto:276-284

message CoreParameter { string name = 1; optional float default_value = 2; CoreParameterRange range = 3; }
message CoreParameterRange { optional float min = 1; optional float max = 2; }

vs. the existing helios/proto/runtime_core.proto:561-576 SamplingFloatRange { optional float min = 1; optional float max = 2; }, used by SamplingRanges (runtime_core.proto:569-577) and DefaultSamplingParameters.ranges.

The same rule already exists in Rust as SamplingRange<f32> + SamplingRanges::validate (helios/src/model.rs:155-168, 190-217): "range must contain the default, else error", plus SamplingParameters::validate for finiteness. This PR re-implements "range finite, min <= max, min <= default <= max" and the clamp four more times: CoreParameter::validate/resolve_value (helios/src/model/contract.rs:438-459), helios/src/server/models.rs:72-82 (rebuilds CoreParameterRange solely to canonicalize min/max for /v1/models), ignition/direct/scheduler.py:135-155 (range shape/order/containment with its own error strings) and Layout.resolve_core_parameters (scheduler.py:245-248, min(max(...)) by hand).

Why it matters: four implementations of one inclusive-bounded-float rule, with different error text and different finiteness handling; a reader must diff them to learn whether they agree (they do not: SamplingRanges::validate validates containment while resolve_value clamps). Fix: reuse SamplingFloatRange on the wire (or at minimum reuse SamplingRange<f32> plus a single contains_or_clamp helper), and have models.rs and the Python Layout formatting call canonical_core_parameter instead of rebuilding the struct.

4. _wire_fp32 duplicated verbatim in two Python modules

ignition/direct/scheduler.py:53-65 duplicates ignition/preparation/contract.py:15-27

Both implement the identical three rules — bool rejection, finite and |v| <= f32::MAX, and reject nonzero values that underflow to FP32 zero — then canonicalize -0.0 to +0.0. They differ only in mechanism (float(np.float32(wide)) and np.finfo(np.float32).max vs struct.pack("<f") and a literal _FP32_MAX = 3.4028234663852886e38), and the direct copy has no label parameter, so its errors lose the field name.

Precedent and removability: ignition/direct/scheduler.py:43 already does from ignition.preparation import runtime_core_pb2 as wire, and ignition/direct/packing.py:8 imports from the same package, so importing a shared helper adds no dependency. This is documented as a mirror of the Rust rule (helios/src/server/protocol/decode.rs:49-75), so a rule change must be made in two places and the copies have already started to diverge in exposition.

Fix: expose one public helper in ignition/preparation/contract.py (e.g. fp32_value(value, label)) and import it in ignition/direct/scheduler.py; delete the second _FP32_MAX. Also consider having decode.rs reuse a single Rust narrowing helper instead of restating finiteness/underflow next to canonical_core_parameter (contract.rs:420-422).


Nits

5. packing.rs: a second staging vector with bespoke bounds checks beside the new write_floats

helios/src/model/packing.rs:286-293, 307, 533-549, 582-611

core_parameter_capacity is a new special-cased preallocation rule (request_capacity() when any SubmissionRow core-parameter binding exists, else 0), and Inputs::new stores core_parameters: Vec::with_capacity(core_parameter_capacity) (packing.rs:307) while every other staging vector is sized from the single shared maximum (packing.rs:294-300, 306-308). The SubmissionRow write then bypasses write_floats (packing.rs:940-967, which already performs the offset+len vs input.elements check and the staging put) and re-checks bounds by hand with destination.checked_add(1) / is_none_or(|end| end > input.elements) and a .get_mut(...).ok_or("packed values exceed core-parameter staging storage") (packing.rs:598-608), while the ActiveRow/RequestRow branch in the same arm does call write_floats (packing.rs:609-611). SamplingParameters in the same function needs no per-source vector at all — it writes rows straight through write_floats for all three indexings (packing.rs:577-580) — and the PR also widens the shared write_raw signature with a count argument (packing.rs:996-1010) for one caller.

Fix: size the float staging from maximum, or drop the vector and write each active row through write_floats with zero padding for inactive rows (or add write_floats_padded beside write_raw so both sources share one helper), removing the special-case capacity and the hand-written checks.

6. ignition/direct: _row_contiguous re-checks contiguity already enforced upstream, with a weaker verdict

ignition/direct/scheduler.py:68-81, field at 117-118, populated at 213-216, enforced at 170

The new Layout.buffer_contiguity exists only to prove a CORE_PARAMETER destination's rows are dense. ignition/preparation/graphs.py:160-176 already rejects every non-contiguous registered buffer ("buffer {name!r} must be contiguous; register its contiguous backing tensor") and checks the buffer lies inside its backing storage; ignition/preparation/scratch.py:303-304 (not opened) and components/sampling.py:412-414 (not opened) enforce the same rule for their buffers. Layout.of(model) reads the same model.buffers (scheduler.py:190, 213).

The new probe is also weaker: it returns None for objects reporting neither .flags.c_contiguous nor .is_contiguous(), and None fails at scheduler.py:170, so it rejects buffer types the upstream checks accepted. Not blocking because I could not confirm from the diff whether debug-serve buffers always pass through GraphBufferGroup._validate_resources; the doubles in tests/direct/test_scheduler.py (FakeTensor/SimpleNamespace) are the only observed unreported-layout case. What settles it: following ignition/direct/executor.py (not opened) and the debug-serve buffer registration — if they reuse GraphBufferGroup, delete _row_contiguous/buffer_contiguity; if not, extend the existing contiguous check instead of adding a second layout map to Layout.

Related convention note: buffer_contiguity/core_parameters are the first kw_only=True fields in Layout (scheduler.py:118-119), and the PR adds a test pinning that (test_layout_constructor_preserves_positional_fields_and_keeps_extensions_keyword_only); no other dataclass in ignition/direct uses the convention, so either document the rule or align the rest.

7. Naming and placement drift in the new contract API

helios/src/model.rs:29; helios/src/model/contract.rs:499-512, 537-539; helios/src/runtime_core/mod.rs:46-48

Fix: keep the alias beside its declaration in model/contract.rs; make core_parameter() return Result like graph() (or both Option); rename the wire-side entry point so validate_core_parameters means one thing.


What I could not settle

Positive precedents the PR does follow