Conventions report · NVIDIA/hyperflare-inference #483

Raw Markdown for agents: https://autobot.eidonix.com/p/3ab6108e-08de-43ae-a72b-37985b7b217a.md

PR #483 — Conventions and duplication review (head 2b4a31e, base main 27716185)

Key findings

No blocking findings and no should-fix findings remain in this lens. The revised head resolves every structural finding from my earlier pass on this PR: patch width now comes from prepared metadata instead of a lookup table keyed on patches_per_feature, the duplicated pixel-width table in conditioned.rs is gone, atomic spans are emitted by the layout that builds the envelope rather than by the prompt dispatcher, and the Gemma 4 envelope test no longer shells out to Python. Seven nits remain, all recorded below with fixes; the only one with structural risk is nit 1 (per-profile patch width authored twice, in two matches keyed on different enums, linked only by a test).

Rules applied: docs/design-review.md:31-52 (principle 3 — shared input packing and frontend processing, model-dependent behaviour expressed through prepared metadata, no enum or metadata field acting as a model allowlist), :25-26 and principle 13 (append, do not renumber, prepared contract requires approval), and AGENTS.md:31-36 (read design-review before reviewing). The charter line "Keep the runtime small and model-agnostic" (read_charter) is the same requirement stated at project level.


What closed since the previous pass (verified in code, not just in the reply)

  1. patches_per_feature → patch width table removed. helios/src/frontend/images/packing.rs:16-32 now has bracketed_patch_features(&VisionCapabilities) (prepared metadata; 0 means the legacy 1176) plus square_merge_side(patches_per_feature) using isqrt and rejecting non-squares. tensor_layout takes &VisionCapabilities (packing.rs:34-39) and the Bracketed arm reads width from it (packing.rs:49-56); bracketed() derives the merge stride the same way. This is the metadata route principle 3 asks for, and it removes the model-identity encoding (DeepSeek already uses patches_per_feature = 9 with 588 floats, so the old key was ambiguous).
  2. Second width table in conditioned.rs removed. mod.rs:459-471 ImageProcessor::patch_features() is now the single per-profile authority, and conditioned.rs:187 calls it. The PaddedGrid = 1200 / PatchMerge = 1176 cache-validation path is covered by the profile loop.
  3. Atomic spans moved into the layout. layouts/bracketed.rs:52-111 builds spans from mm_token_type_ids runs and returns them in PromptData, mirroring layouts/deepseek.rs:149; model/prompt.rs:52-65 now passes only an atomic_spans bool derived from image_tokens.span. The former generic span-filling block in model/prompt.rs is gone.
  4. Gemma 4 span coverage exists. model/prompt.rs:1171-1256 bracketed_layout_emits_atomic_spans_only_when_contract_declares_them (two spans, marker assertions, 64-aligned chunk rejection, no-span case), plus server-side bounds at server/config.rs:935-1021.
  5. Test no longer duplicates the template machinery. gemma4.rs:394-402 writes the {% mark %}{{ messages[0].content }} template inline, matching model/prompt.rs:428, patch_merge.rs:266, server/config.rs:613; the live-parity test is #[ignore]d with hard assertions (gemma4.rs:522-531).
  6. New tag has a round-trip test. runtime_core/protobuf.rs:812-860 serialized_gemma4_profile_selects_only_image_preparation, next to the GLM and padded-grid equivalents.

Nits (severity: nit — none block merge)

Nit 1 — Per-profile patch width still authored twice, in two matches over different enums

Files: helios/src/frontend/images/packing.rs:41-100, helios/src/frontend/images/mod.rs:459-471, test packing.rs:695-824. tensor_layout maps ImageLayoutKind → pixel width (Qwen|Mimo → 1536, Bracketed → bracketed_patch_features(vision), Radio → 768, …), while ImageProcessor::patch_features() maps Profile → the same widths (mod.rs:461-469). Nothing links the two at compile time; only processor_patch_features_match_tensor_layout_for_every_profile (packing.rs:695, 11 cases to packing.rs:808-823) notices a drift, and it can only enumerate profiles someone remembered to add. Why it matters: a new profile (or a changed default) that is added to one table and not the other produces a silently wrong upload buffer extent, caught only if a test case is also added. Fix: make one delegate to the other, e.g. tensor_layout takes the ImageProcessor (or a patch_features value derived from the profile) instead of re-deriving it from capabilities, so a single match is authoritative. Graded nit because the duplication is bounded to two tables over the same 11 profiles and is test-covered today.

Nit 2 — patch_features() accessor bypassed inside process

File: helios/src/frontend/images/gemma4.rs:54-56 vs gemma4.rs:132. Processor::patch_features() computes 3 * self.patch_size * self.patch_size, and process re-inlines exactly that expression when sizing the pixel buffer: let patch_features = 3 * self.patch_size * self.patch_size; (:132). Why it matters: the value the loader validates against vision.patch_features (server/config.rs:448-463) and the value used to size the buffer must agree; two spellings invite a one-sided edit. Fix: let patch_features = self.patch_features();. Pre-existing analogue: patches.rs:89 does the same inlining, so this is consistency with the wrong neighbour rather than a regression.

Nit 3 — Soft-token allowlist duplicated across the language boundary

Files: helios/src/frontend/images/gemma4.rs:13 (SUPPORTED_SOFT_TOKENS: [70, 140, 280, 560, 1120]) and ignition/preparation/frontend.py:132 (max_soft_tokens not in (70, 140, 280, 560, 1120)). Both sites cite defence-in-depth deliberately (the Rust comment at gemma4.rs:11-12 says so), and no neighbouring profile enumerates an allowlist (deepseek_row_major.rs:14 (not opened) validates a range), so there is no in-repo precedent to follow. Why it matters: adding a Gemma 4 soft-token budget requires editing two files in two languages with no test asserting they match. Fix: accept as-is, or have Ignition emit the allowed set in Gemma4ImageSettings so Helios validates against prepared metadata (which principle 3 prefers).

Nit 4 — Shared Envelope still homed in patch_merge

File: helios/src/frontend/images/patch_merge.rs:10-17; imported at gemma4.rs:8. The doc comment now says it is "shared by PatchMerge and Gemma4 image preparation profiles", i.e. the type has become a general frontend construct but lives in one profile's module. Why it matters: the next enveloped profile imports from super::patch_merge::Envelope, which reads as depending on the PatchMerge profile. Fix: move it to frontend/images/envelope.rs (not opened) (or next to ImageGeometry in mod.rs) with patch_merge re-exporting or importing.

Nit 5 — server::config reaches into image-packing internals

File: helios/src/server/config.rs:456-464. validate_loaded_image_processor calls crate::frontend::images::packing::bracketed_patch_features(vision) to compute the legacy-default expectation for the Bracketed mismatch error. The rule ("patch_features == 0 means 1176") is packing knowledge, restated in the server layer. Why it matters: layering — server::config otherwise talks to ImageProcessor/VisionCapabilities accessors (compare processor.patch_features() and processor.max_image_envelope_tokens() on the lines above and below). Fix: add VisionCapabilities::bracketed_patch_features() (or an ImageProcessor accessor) and call that.

Nit 6 — Fixture generator copies helpers from the GLM generator

Files: tests/frontend/generate_gemma4_image_fixtures.py:17-25 vs tests/frontend/generate_glm_image_fixtures.py:18-25 (pattern and digest are byte-identical apart from the comment). Every generator in tests/frontend/ is written standalone, so this matches the existing convention; the duplication is real but consistent. Fix: optional shared helper module; not worth a change on its own.

Nit 7 — Marker-presence check partially duplicated with validate_prompt_data

File: helios/src/frontend/images/layouts/bracketed.rs:57-65 vs helios/src/model.rs:441-456. flush_span rejects start == 0 || end >= len ("missing envelope markers"), while validate_prompt_data already asserts tokens[s.start] == span.start_token && tokens[s.end-1] == span.end_token for every declared span. The layout check only proves a marker slot exists, not that it is the declared marker, so the stronger check lives one layer away. Why it matters: two places encode the same invariant with different strength; a reader must check both to know what is guaranteed. Fix: none required (the layout check yields a clearer per-request error); if touched, express it as the same predicate as model.rs or drop it and rely on validate_prompt_data.


Precedents that hold (checked, no finding)


Open questions and limits