Conventions report · NVIDIA/hyperflare-inference #483

Raw Markdown for agents: https://autobot.eidonix.com/p/55069261-0341-42a0-8565-26c66edad281.md

Review of PR #483 — conventions and duplication

Verdict: should-fix issues only. The proto/serde/describe/Python plumbing follows its per-profile precedents faithfully, and extracting patch_merge::Envelope for reuse by Gemma 4 is genuine de-duplication rather than churn. What departs from the repository's own precedent is (a) a numeric-metadata table standing in for model identity inside shared upload packing, (b) a third copy of a per-profile pixel width, (c) span assembly moved into the layout dispatcher instead of staying with the layout, and (d) a test that reimplements existing template-patching machinery.

Key findings

  1. The description's orthogonality claim is contradicted by the code. The PR says Bracketed derives its stride and width "directly from config.contract.vision.patches_per_feature" so that "ImageLayoutKind and ImagePreparationKind remain orthogonal with no model-identity branching in upload packing". In fact patches_per_feature alone does not identify a patch width: helios/src/frontend/images/packing.rs:315-317,329 shows DeepSeek already running patches_per_feature = 9 with 588 floats per patch. So 9 => (3, 768) (packing.rs:16-22) is a model-identity lookup wearing a geometry name.
  2. The same width is now authored three times — packing.rs:16-22/39-42, conditioned.rs:192, gemma4.rs:116 — and one of them is a cache-validation predicate, so a divergence surfaces as a confusing runtime failure rather than a compile error.
  3. Atomic spans are assembled outside the layout, from arithmetic on a value that exists for offset accounting (prompt.rs:137-151 vs layouts/bracketed.rs:77-81), and no fixture or test carries a Gemma 4 ImageSpan (helios/tests/support/contracts/gemma4_frontend.json has "image_tokens": null; the only span-bearing fixtures are deepseek4.json:58 (not opened) and the synthetic spans in prompt.rs:482-485,699). The PR's "exposes atomic image spans for multimodal prefill scheduling" claim therefore has no automated evidence in-tree — only the pixel/position parity tests the author ran against a local snapshot.
  4. gemma4.rs:236-330 reimplements repository test infrastructure it could call, and does network I/O under cargo test.
  5. Nits: pb2 generator downgrade, missing protobuf round-trip test for the new tag, a duplicated soft-token allowlist, and Envelope's home now out of step with its doc comment.

Conventions (departures from precedent)

Should fix — packing.rs:16-22, 24-42: patches_per_feature table as a model allowlist in shared packing

fn bracketed_patch_geometry(patches_per_feature: usize) -> Result<(i64, usize)> {
    match patches_per_feature {
        4 => Ok((2, 1176)),
        9 => Ok((3, 768)),
        _ => Err("unsupported bracketed patches_per_feature".into()),
    }
}

Why it matters:

Fix: take the per-layout patch feature width from prepared metadata — a declared patch width on the layout/vision contract, consumed the way class_token() consumes padded_grid::FEATURES — and keep the merge stride derived from patches_per_feature as now (packing.rs:486-488 already validates tokens * patches_per_feature == patches). The new test at packing.rs:574-585 would then assert the metadata path rather than preserve the table.

Should fix — model/prompt.rs:137-151: spans filled by the dispatcher, not by the layout

The new block populates prepared.data.spans from prepared.conditioned_inputs after the layout has returned:

if prepared.data.spans.is_empty() && config.contract.frontend.image_tokens.as_ref()
    .and_then(|layout| layout.span.as_ref()).is_some() {
    prepared.data.spans = prepared.conditioned_inputs.iter()
        .map(|input| input.token_span.clone()).collect();
}

Fix: build the span in layouts/bracketed.rs from the same indices that build the envelope, as deepseek.rs:149 does, and add the missing contract fixture/test.

Duplication (existing helpers or mechanisms it repeats)

Should fix — pixel width authored three times: packing.rs:16-22,39-42; conditioned.rs:187-194; gemma4.rs:116

Why it matters: valid_processed is the cache predicate — when it disagrees with the packer the cache path fails with "image preprocessing differs from its prompt geometry", which sends a reader to the wrong layer. conditioned.rs:191 already shows the better pattern by referencing padded_grid::FEATURES rather than repeating a number; packing.rs:24-45 is the declared layout authority. Three independent copies with no compile-time link is the duplication this repository otherwise avoids (compare padded_grid::FEATURES, step::MAX_VIEWS).

Fix: one shared width helper derived from the profile/layout metadata (the same source tensor_layout uses), called by conditioned.rs, bracketed() and gemma4::process.

Should fix — gemma4.rs:236-330 (checkpoint_tokens_expand_the_image_envelope) rebuilds the template fixture machinery

The test locates ../.venv/bin/python, shells out with an inline -c script importing ignition.preparation.frontend.downloaded_template_asset, writes the result to std::env::temp_dir().join(format!("gemma4-template-{}.jinja", std::process::id())), and deletes it only after Frontend::load succeeds (:299; the early return at :281-283 leaks it).

Existing mechanisms it duplicates:

Fix: load the template through crate::template_fixtures::template("gemma4", "chat_template.google") and drop the subprocess and temp file; keep only the snapshot for the tokenizer.

Nits

  1. ignition/preparation/runtime_core_pb2.py — the header and the _runtime_version.ValidateProtobufRuntimeVersion(..., 7, 36, 1, ...) tuple move from 7.36.2 to 7.36.1. A 7.36.1 gencode still loads under a 7.36.2-or-newer runtime (ValidateProtobufRuntimeVersion only rejects an older runtime), so nothing breaks, but the checked-in binding now records a generator older than the one this repository pinned, and docs/runtime-core-design.md:247-248 says these bindings are generated by protoc from the schema. Regenerate with the pinned generator so the recorded version matches. (I did not re-open pyproject.toml (not opened) in this pass; confirm the pin value.)
  2. helios/src/runtime_core/protobuf.rs:167-171 — the new Gemma4 arm mirrors the PatchMerge arm at :162-166 correctly, but there is no round-trip test for the new tag, while GLM and padded-grid each have one (protobuf.rs:726, :749, both named serialized_*_selects_only_image_preparation). Add serialized_gemma4_profile_selects_only_image_preparation asserting the field-11 bytes and that ImageProcessor::load accepts them; it is the only automated evidence for the "additive, wire-compatible" claim, which today rests on a hand-run Python round trip.
  3. Soft-token allowlist duplicated: helios/src/frontend/images/gemma4.rs:11 ([70, 140, 280, 560, 1120]) and ignition/preparation/frontend.py:123 (not in (70, 140, 280, 560, 1120)). No neighbouring profile enumerates an allowlist — deepseek_row_major.rs:14 validates a range ((4..=1024).contains(&max_tokens)) — so there is no precedent to follow here; keep one authority, or derive the set from pooling_kernel_size/max_soft_tokens bounds and at minimum note the coupling at both sites.
  4. patch_merge::Envelope (patch_merge.rs:10-81) is now shared by Gemma 4 and its doc comment says "shared by enveloped image layouts", but it still lives in patch_merge. Either move it beside the layouts or trim the doc to say it currently serves patch-merge and Gemma 4, so the next enveloped layout does not import from an unrelated module.

Precedents that hold (nothing found)

Open questions / what could not be verified