#1 [high] PR 483 review setup: scope, rules, files
PR #483 NVIDIA/hyperflare-inference, branch rickybrent:core/gemma4-image-frontend f2340e42 -> main 6d6fe0c6. 13 files +732/-164. Title: "Add Gemma 4 image prep profile, bracketed 3x3 packing & atomic spans". My lens: C = conventions and duplication. Compare each new construct with closest precedent; flag departures; flag duplicated helpers/mechanisms.
Rules to cite (AGENTS.md):
- L12/176-181 charter + AGENTS "Keep the runtime small and model-agnostic"/"Reject architectural violations": model-specific native policy is a violation; enums cannot serve as model allowlists (docs/design-review.md principle 3, lines 48-52).
- docs/design-review.md principle 3 lines 38-52: "Native ... input packing, frontend processing ... stay shared; use prepared metadata and frontend assets to express model-dependent behavior"; "Reject per-model boolean policy flags... Enums, callbacks, schema names, and metadata fields cannot serve as alternative model allowlists."
- AGENTS.md "Reject unsupported abstractions and churn" (lines ~188-193): unsolicited formatting/renaming/annotation sweeps not contributions; refactoring must support requested behavior.
- AGENTS.md "Be explicit and pin everything" (charter): no magic defaults, pin dependencies to exact versions.
- AGENTS.md Required prose review + repo-prose skill; PR descriptions four-part scheme.
- AGENTS.md config: no env-var behavior switches; tests may read vars to locate checkpoints but "A test variable must not change what the code under test does" (lines 466-468) — relevant to FLARE_GEMMA4_TEST_SNAPSHOT test.
#2 [high] packing.rs: bracketed_patch_geometry table + tensor_layout param
helios/src/frontend/images/packing.rs (PR head):
- New fn
bracketed_patch_geometry(patches_per_feature) -> Result<(i64, usize)>with a hard-coded table 4 => (2, 1176), 9 => (3, 768), else Err. Lines 16-22. tensor_layout(kind, patches_per_feature, name, patches)— new positional param (line 24-42); Bracketed pixel width now derived (lines 39-42).bracketed()(lines 479-509) now derives merge_side/patch_width fromconfig.contract.vision.patches_per_feature, replaces literal 2/h%2 checks andpatches*1176, droppedconfig.contract.vision.patches_per_feature != 4check.- Note: patches_per_feature alone does not disambiguate geometry: DeepSeek uses patches_per_feature 9 with 588 floats/patch (deepseek() line 315-317, 329 uses 588 and div_ceil(3) merge). So the 9 => 768 entry assumes Gemma4 style.
- New tests at 570-586.
- Established precedent:
tensor_layoutdispatches onImageLayoutKind(prepared enum);qwen()derives pixel_width fromconfig.contract.frontend.image_layoutif/else chain (lines 123-134).conditioned.rs::valid_processed(line 187-194) has a third per-profile pixel-width table.
#3 [high] Should fix: packing.rs bracketed_patch_geometry table keyed on patches_per_feature
packing.rs:16-22 bracketed_patch_geometry(patches_per_feature) -> (merge_side, patch_width) table 4=>(2,1176), 9=>(3,768), else Err.
Problem: patches_per_feature alone does not identify the patch float width. DeepSeek already uses patches_per_feature 9 (packing.rs deepseek() 315-317 checks geometry.tokens != patches/9, tensor_layout Deepseek branch gives 588 floats/patch). So 9=>768 encodes "Gemma-4-style interleaved patch", i.e. model identity, in shared upload packing. Same file already derives widths from the prepared layout enum: qwen() 123-134 (Moonvit/Step 588, Radio 768, Glm 1176) and tensor_layout keyed on ImageLayoutKind; class_token() 537 uses super::padded_grid::FEATURES.
Rules: docs/design-review.md principle 3 lines 38-52 ("input packing ... stay shared; use prepared metadata ... to express model-dependent behavior"; enums/metadata must not become model allowlists); AGENTS.md:176-181; charter "Keep the runtime small and model-agnostic".
Fix: take the patch feature width from prepared metadata (a declared per-layout patch width in the vision contract / ImageLayout, as class_token does with padded_grid::FEATURES) instead of a numeric table keyed on patches_per_feature.
#4 [high] Should fix: duplicate per-profile pixel-width tables (packing, conditioned, gemma4)
Three independent places now encode the same per-profile pixel width:
- helios/src/frontend/images/packing.rs:39-42 + 16-22 (Bracketed -> 1176 / 768 via bracketed_patch_geometry).
- helios/src/frontend/images/conditioned.rs:187-194
valid_processed(new armProfile::Gemma4(_) => 768, line 192) — a third match arm table next to Radio 768, Glm 1176, PaddedGrid FEATURES (191),_ => 588. - helios/src/frontend/images/gemma4.rs:116
3 * self.patch_size * self.patch_size. Precedent for a single source: class_token()/padded_grid usepadded_grid::FEATURES(packing.rs:537); tensor_layout() is the declared layout authority (packing.rs:24-89). Risk: conditioned.rs caches validation (valid_processed) silently disagrees with the profile if either table changes, and the cache path returns "image preprocessing differs from its prompt geometry". Fix: derive the width from one shared helper (e.g. the same layout/metadata source used by tensor_layout).
#5 [high] Should fix: prompt.rs fills data.spans generically instead of in the layout
helios/src/model/prompt.rs:137-151 (new): fills prepared.data.spans from prepared.conditioned_inputs when config.contract.frontend.image_tokens.span is Some and no layout produced spans.
Departures from precedent:
(a) Every image layout module returns conditioned_inputs: vec![] (grep: bracketed.rs:44/90, class_token.rs:66, deepseek.rs:165, glm.rs:85, mimo.rs:76, moonvit.rs:89, qwen.rs:110, radio.rs:82, step.rs:108) — the vector is always filled here, so conditioned_inputs is no longer layout-owned. The precedent for spans is the layout: layouts/deepseek.rs:149 data.spans.push(start + padding..start + block.len()) alongside its own token expansion, then validate_prompt_data (model.rs:436-454) checks the span boundaries against the declared ImageSpan.
(b) The new code trusts the ImageSpan metadata only for presence, and copies input.token_span, which for enveloped layouts is start..start + additional + 1 (prompt.rs:129-131) where additional is token_expansions from layouts/bracketed.rs:77-81 = geometry.tokens + 1. So the assembled span length is tokens+2. max_tokens is enforced in model.rs:438. Nothing in this PR's code or tests checks a Gemma4 ImageSpan (no contract fixture with span set for Gemma4; helios/tests/support/contracts/gemma4_frontend.json has "image_tokens": null), so the one path the feature is claimed for ("atomic spans for multimodal prefill scheduling") is untested end to end.
Fix: build spans in the layout that builds the expansion (bracketed.rs, as deepseek.rs does), so the span is derived from the same indices as the expansion rather than re-derived by span arithmetic in prompt.rs.
#10 [high] Research summary
Reviewed PR #483 (Gemma 4 image prep profile, bracketed 3x3 packing, atomic spans) through the conventions-and-duplication lens, checking each new construct against its closest precedent in helios/src (packing.rs, conditioned.rs, layouts/deepseek.rs, layouts/bracketed.rs), helios/src/runtime_core (protobuf.rs, describe.rs), ignition/preparation/frontend.py, and the repository rules (AGENTS.md, docs/design-review.md, docs/runtime-core-design.md).
Four should-fix findings and three nits, recorded in the scratchpad:
packing.rs:16-22adds apatches_per_feature -> (merge_side, patch_width)table (4→1176, 9→768) in shared upload packing.patches_per_featurealone does not identify patch width — DeepSeek already uses 9 with 588 floats — so the table encodes model identity where the file's own precedent (qwen()'s layout-derived widths,class_token()'spadded_grid::FEATURES) derives widths from prepared metadata. This contradicts design-review principle 3 (input packing stays shared; metadata must not become a model allowlist).- The same pixel width is now authored in three places (packing.rs table,
conditioned.rs:192,gemma4.rs:116), with the cache-validatingvalid_processedsilently disagreeing if either changes. model/prompt.rs:137-151fillsdata.spansgenerically fromconditioned_inputs, while every layout returnsconditioned_inputs: vec![]and the established span authority is the layout itself (layouts/deepseek.rs:149withvalidate_prompt_data). No test exercises a Gemma 4 ImageSpan, so the claimed scheduling path is unverified.gemma4.rs's envelope test shells out to.venv/bin/pythonto re-patch the chat template, duplicatingprepare_templates.py::_annotate/annotated_template_assetand bypassing the existingtemplate_fixtures::template("gemma4", ...)accessor.
Nits: runtime_core_pb2.py was regenerated with protobuf 7.36.1 while pyproject.toml (not opened) pins >=7.36.2; no protobuf round-trip test for ImageSettings.gemma4 although GLM and padded-grid each have one; the soft-token allowlist is duplicated between Rust and Python.
The Envelope extraction from patch_merge::Processor is a genuine de-duplication and the proto/serde/describe/Python validation additions follow their per-profile precedents exactly.
#11 [high] Coverage: what was read for each changed file
Coverage of PR #483 (13 files) through lens C (conventions and duplication), all read at ref pr/483 in context:
- helios/proto/runtime_core.proto (+10): enum value 11 +
Gemma4ImageSettings gemma4 = 11and the message mirror PatchMergeImageSettings tags 1-8 -> 1-6. Consistent with the patch_merge precedent next to it. No finding. - helios/src/frontend/images/gemma4.rs (new, 416): read fully (1-200, plus diff for 200-416).
Processormirrors patch_merge::Processor / QwenProcessor lifetime style;processmirrors patches.rs::process/PatchProcessor::process structure (geometry, checked total, reserve_outputs, cu_seqlens). Findings: duplicated pixel width (gemma4.rs:116), duplicated soft-token allowlist (gemma4.rs:11), test reinvents template patch machinery (gemma4.rs:243-320). - helios/src/frontend/images/mod.rs (+20): ImageSettings::Gemma4 + Gemma4ImageSettings mirror PatchMerge variants; Profile::Gemma4 arms mirror PaddedGrid arms in load/geometry/resized_rgb/process/expand_prompt/preparation_kind. Consistent. No finding.
- helios/src/frontend/images/conditioned.rs (+9):
Profile::Gemma4(_) => 768at line 192 invalid_processed's per-profile pixel-width match (187-194). Finding: third copy of the width table (entry 4). - helios/src/frontend/images/packing.rs (+45/-5):
bracketed_patch_geometry16-22,tensor_layoutnew param 24-42,bracketed()479-509, tests 570-586. Finding: entry 3. - helios/src/frontend/images/patch_merge.rs (+61/-38): Envelope extraction 10-81, Processor 83-131. Genuine de-duplication; single nit on its home/doc (entry 9 item 3).
- helios/src/model/contract.rs (+1/-1): contract_enum ImagePreparationKind adds Gemma4 = 11, appended, no renumbering -> preserves wire ids (design-review principle 13). No finding.
- helios/src/model/packing.rs (+1): call site passes
config.contract.vision.patches_per_featureinto tensor_layout (model/packing.rs:92-97). Consequence of finding 1; the call site itself matches the neighbouring ImageTensor validation style. - helios/src/model/prompt.rs (+15): 137-151 span filling. Finding entry 5.
- helios/src/runtime_core/describe.rs (+2): vision_json Gemma4 arm 442-443 mirrors PatchMerge arm 440-441. No finding.
- helios/src/runtime_core/protobuf.rs (+5): frontend_settings Gemma4 arm 167-171 mirrors PatchMerge 162-166. Nit: no round-trip test (entry 9 item 1) unlike GLM (726) / padded-grid (749).
- ignition/preparation/frontend.py (+25): gemma4 branch 113-137 mirrors glm branch 138-153 (uses
_expectedincl. optionals). Nit: duplicated soft-token allowlist (line 123 vs gemma4.rs:11). - ignition/preparation/runtime_core_pb2.py (+122/-120): descriptor regenerated; generator version 7.36.2 -> 7.36.1. Nit (entry 6).
Also checked for precedent/duplication: helios/src/frontend/images/resize.rs (gemma4 correctly reuses resize::resize = uint8 antialiased bicubic, as patch_merge/qwen do, rather than adding a kernel); helios/src/model.rs::validate_prompt_data (408-457) for span enforcement; helios/src/scheduler.rs::set_prefill_spans consumers (server/runtime.rs:1460); layouts/* returning conditioned_inputs: vec![]; helios/tests/support/contracts/* fixtures (gemma4_frontend.json has image_tokens null); tests/frontend/prepare_templates.py and helios/tests/support/templates.rs; docs/runtime-core-design.md:247-248 (Python bindings generated by protoc).
#6 [medium] Should fix: runtime_core_pb2.py generator version downgraded to 7.36.1
ingestion/preparation/runtime_core_pb2.py header in the PR diff:
# Protobuf Python Version: 7.36.2->7.36.1and the_runtime_version.ValidateProtobufRuntimeVersion(..., 7, 36, 2 -> 1, ...)call changes 2 -> 1.- pyproject.toml:34 pins
protobuf>=7.36.2,<8. ValidateProtobufRuntimeVersion rejects a runtime older than the gencode; 7.36.1 gencode is the older/newer? It is the regenerated with a lower protoc version, so the checked-in binding declares 7.36.1 while the repo requires runtime >= 7.36.2. That is a needless downgrade of the generator recorded in the file: docs/runtime-core-design.md:247-248 says Python bindings are generated byprotocfrom the same schema. The generated file must be produced with the pinned generator so the header matches the pin (charter "Be explicit and pin everything"; AGENTS.md "pin dependencies to exact versions or commits"). Also, this chunk re-wraps the whole descriptor blob (+122/-120) — unavoidable for a regenerated file, but the version flip is an unrelated regression that would return with the next regeneration. Fix: regenerate with protobuf 7.36.2 so the header and ValidateProtobufRuntimeVersion keep 7.36.2; or state why the repin is intentional.
#7 [medium] Should fix: gemma4.rs test reinvents template fixture preparation
helios/src/frontend/images/gemma4.rs:243-320 checkpoint_tokens_expand_the_image_envelope builds its chat template by shelling out to ../.venv/bin/python with -c importing ignition.preparation.frontend.downloaded_template_asset and writing to std::env::temp_dir().
Precedents in the repository:
- helios/tests/fixtures/templates/gemma4/chat_template.google.patch.json already exists (used via helios/tests/support/templates.rs
template("gemma4", "chat_template.google"), wired throughcrate::template_fixtures— helios/src/lib.rs:7-9, frontend/jinja/tests.rs:274, tests/ordinary_tokens.rs:451).template_fixtures::templateis the established accessor; the new test bypasses it and re-patches the template itself, duplicatingtests/frontend/prepare_templates.py:15-32 _annotatein a third place (the Rustannotated_template_assetin frontend.py:24-40 is the second). - AGENTS.md: tests may read variables that locate checkpoints; "A test variable must not change what the code under test does".
FLARE_GEMMA4_TEST_SNAPSHOTonly locates a snapshot, so that part follows precedent (matches bracketed.rs:106FLARE_MINIMAX_M3_SNAPSHOT). - The new test also downloads from the Hugging Face hub as a side effect of a
cargo testrun (downloaded_template_asset calls hf_hub_download when the patch source is not in the cache) and writes a temp file it deletes only on the happy path (the earlyif !status.success() { return; }leaks it). Fix: reusecrate::template_fixtures::template("gemma4", "chat_template.google")(prepare via tests/frontend/prepare_templates.py) and drop the python subprocess and temp-file dance.
#8 [medium] Consistency checks that pass
Precedent checks that pass (no finding):
- gemma4::Processor holds
limitsas a field rather than takingImageLimitsper call, like patch_merge::Processor/QwenProcessor; ok. Envelopeextracted from patch_merge::Processor (patch_merge.rs:10-81) and reused by gemma4 — a real de-duplication, good. But it lives inpatch_mergewhile the doc comment now says "shared by enveloped image layouts"; a future non-patch-merge envelope user will import from patch_merge.rs. Nit.- ImageSettings::Gemma4 + Gemma4ImageSettings mirror PatchMergeImageSettings exactly (mod.rs:332-341),
#[serde(deny_unknown_fields)], snake_case rename — consistent. - protobuf.rs:167-171 encode mirrors PatchMerge at 162-166; describe.rs:442-443 mirrors PatchMerge at 440-441. Consistent.
- ignition/preparation/frontend.py:113-137 mirrors the glm/padded_grid branches (uses
_expectedwith optional fields, as glm.py:146-148 does). Consistent. One departure: every other profile validatesset(image) != set(expected)only for padded_grid; gemma4 uses_expectedonly. Consistent with glm. Fine. - gemma4.rs header
SPDX-FileCopyrightText: Copyright (c) 2026 Flare community contributorsonly, without the NVIDIA line that other files carry (compare mod.rs:2-3, patches.rs, conditioned.rs). New files in this repo carry both lines (deepseek_row_major.rs:2-3, padded_grid.rs, glm.rs has only the Flare line too — so mixed precedent). Nit at most; skip. Profile::Gemma4(_) => 768in conditioned.rs also needs the interpolation list untouched: Gemma4 pushes no interpolation indices, and valid_processed'sinterpolationmatch (196-199) excludes Gemma4 — correct.- prompt.rs new code runs after the loop and before validate_prompt_data/validate_conditioned_inputs; spans ordering/length constraints in model.rs:420-423 will reject out-of-order spans, so no silent acceptance.
#9 [medium] Nits: protobuf test, duplicated allowlist, Envelope location
- Nit — no protobuf round-trip test for the new profile. Precedent: helios/src/runtime_core/protobuf.rs:726
serialized_glm_profile_selects_only_image_preparationand :749serialized_padded_grid_profile_selects_only_image_preparationeach assert the exact wire bytes select only the image preparation and that the profile loads. Gemma4 adds tag 11 (Gemma4ImageSettings gemma4 = 11) with no equivalent test, so the "additive, wire-compatible" claim in the PR description is checked only by the Python round trip the author ran by hand. Fix: addserialized_gemma4_profile_selects_only_image_preparationwith the field-11 bytes (0x5a) and an ImageProcessor::load assertion. - Nit — the supported soft-token allowlist is duplicated: gemma4.rs:11
SUPPORTED_SOFT_TOKENS: [usize; 5] = [70,140,280,560,1120]and ignition/preparation/frontend.py:123if image.get("max_soft_tokens") not in (70, 140, 280, 560, 1120). Neighbouring profiles validate a range instead (deepseek_row_major.rs:14(4..=1024).contains(&max_tokens)), so there is no established enumerated allowlist to follow. Keep one authority (the exported settings already carry the value) or derive the set frompooling_kernel_size/max_soft_tokensextremes; at minimum the two lists must not diverge. - Nit —
patch_merge::Envelope(patch_merge.rs:10-81) is now shared by gemma4; its doc comment says "shared by enveloped image layouts", so the module/home should follow the name (or the doc should say it currently serves patch-merge and Gemma 4).
#12 [medium] Severity correction: pb2 generator version is a nit
Entry 6 recorded runtime_core_pb2.py's Protobuf Python Version 7.36.2 -> 7.36.1 as "should fix". On reflection it is a nit:
_runtime_version.ValidateProtobufRuntimeVersiononly rejects a runtime older than the gencode, so a 7.36.1 gencode still loads under the pinned runtimeprotobuf>=7.36.2,<8(pyproject.toml:34). Nothing breaks.- What it does do is record a generator version below the repository's pin, so the checked-in binding no longer states the pinned generator (docs/runtime-core-design.md:247-248: Python bindings are generated by
protocfrom the same schema; charter "Be explicit and pin everything"). Fix: regenerate with protobuf 7.36.2 so the header and the version tuple match the pin. Severity: nit.
Final severity list to report:
- Should fix: packing.rs:16-22 bracketed_patch_geometry table (model identity in shared packing).
- Should fix: pixel width duplicated across packing.rs:39-42/16-22, conditioned.rs:192, gemma4.rs:116.
- Should fix: prompt.rs:137-151 generic span filling instead of layout-owned spans, and no Gemma 4 ImageSpan test.
- Should fix: gemma4.rs:243-320 test duplicates template patching / bypasses template_fixtures, downloads from the hub in a unit test, leaks a temp file on the failure path.
- Nit: runtime_core_pb2.py generator version 7.36.1 vs pin 7.36.2.
- Nit: no protobuf round-trip test for ImageSettings.gemma4 (precedents protobuf.rs:726, :749).
- Nit: soft-token allowlist duplicated (gemma4.rs:11 vs frontend.py:123); no precedent for an enumerated allowlist (deepseek_row_major.rs:14 validates a range).
- Nit: patch_merge::Envelope is now shared but still homed/documented in patch_merge.rs:10-16.