PR #483 review — Gemma 4 image preparation profile, bracketed 3×3 packing, atomic spans
PR: #483, head f2340e42, base 6d6fe0c6, 13 files, +732/−164. No human review yet.
Verdict: Changes requested. Not a rejection — the shape of the change is right; three behaviours need to be narrowed, evidenced, or disclosed before this is mergeable.
Key findings
- The description's central design claim is contradicted by the code. It says
Bracketedderives stride and width "directly fromconfig.contract.vision.patches_per_feature… soImageLayoutKindandImagePreparationKindremain orthogonal with no model-identity branching in upload packing".packing.rs:16-22is a two-entry table (4 => (2, 1176),9 => (3, 768)) keyed on a number that does not determine patch width — DeepSeek already runspatches_per_feature = 9at 588 floats per patch (packing.rs:35-38).9 => 768is model identity wearing a geometry name, in shared input packing, whichdocs/design-review.md:38-52explicitly forbids. - The headline evidence cannot fail. Both parity tests return silently without
FLARE_GEMMA4_TEST_SNAPSHOTand../.venv/bin/python(gemma4.rs:236-244,:253-256,:281-283,:336-339), and a silent return counts as a pass. So "45 passed" is the same number whether the Hugging Face comparison ran or not — while every other profile's parity evidence is a checked-in fixture (glm.rs:147-199+tests/frontend/generate_glm_image_fixtures.py(not opened);qwen38_images.json(not opened)). - Atomic spans are a shared-scheduler change presented as a Gemma 4 detail.
prompt.rs:137-151fires for any layout whose contract declares anImageSpanand whosedata.spansis empty, feeding bothvalidate_prompt_data(model.rs:436-451) andScheduler::set_prefill_spans(runtime.rs:1458-1465→scheduler.rs:1912-1936, which makes each span unsplittable). No test in the diff and no in-tree fixture reaches it. - The profile can load configurations the rest of the pipeline cannot represent.
gemma4.rs:23-31accepts anypatch_size ≤ 64andpooling_kernel_size ≤ 16, sopooling²need not equallimits.patches_per_featureand3·patch_size²need not equal the packing stride; the mismatch surfaces only as a per-request error (prompt.rs:171,packing.rs:497) or as silent tensor misalignment. - Unenforced invariant: a 1,120-soft-token image expands to a 1,122-token envelope, which
validate_prompt_data(model.rs:421-423) andset_prefill_spans(scheduler.rs:1922-1930) reject whenprefill_chunk_sizeis smaller. Nothing checks this at load. Latent today (the Ignition default is 4096,ignition/preparation/bootstrap.py:36(not opened)), live for any small-chunk deployment. - The witness to that claim. Correct, additive wire format; correct
Envelopeextraction; correct, overflow-guarded resize/pack arithmetic. See "Verified clean" below.
Blockers
B1 — Bracketed patch width is looked up from patches_per_feature (Architecture, Conventions, Correctness)
Finding. helios/src/frontend/images/packing.rs:16-22:
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()),
}
}
Used from tensor_layout (packing.rs:39-42) and bracketed() (packing.rs:479-481), and reached at core load through helios/src/model/packing.rs:92-97.
Request. Move the width into prepared metadata: add patch_size to VisionCapabilities (helios/src/model.rs:44-51), validate it next to patches_per_feature in VisionCapabilities::validate (helios/src/model.rs:68-87), then in packing.rs compute merge_side = patches_per_feature.isqrt() and patch_width = 3 * patch_size * patch_size. Delete bracketed_patch_geometry and thread the width from config, the way class_token() reads padded_grid::FEATURES (packing.rs:515).
Why. One vision patch vector is 3 · patch_size² floats — a property of the vision tower, not of the merge factor. The key is provably ambiguous in-tree: DeepSeek uses patches_per_feature = 9 with 588 floats per patch (packing.rs:35-38), so 9 => 768 encodes "the model with 9 patches per feature is Gemma 4". docs/design-review.md:38-52 requires input packing to "stay shared; use prepared metadata" and states "Enums, callbacks, schema names, and metadata fields cannot serve as alternative model allowlists"; the charter says "keep the runtime small and model-agnostic … shouldn't accumulate per-model branches (#267, #334)". A future 3×3-merge tower with 14×14 patches silently gets 768 and produces truncated or misaligned pixels. Scope note: only PatchMerge/MiniMax uses ImageLayoutKind::Bracketed today, at patches_per_feature = 4 (helios/tests/message_boundaries.rs:494, layouts/bracketed.rs:104-180), so this is a design violation and a load-path narrowing rather than a present bug for another model. It is still the blocker, because it is the PR's stated architecture and it is wrong.
B2 — The Hugging Face parity evidence cannot fail and is not reproducible (Correctness, Prose, Simplicity)
Finding. helios/src/frontend/images/gemma4.rs:236-244 returns early unless FLARE_GEMMA4_TEST_SNAPSHOT is set and tokenizer.json (not opened) exists; :253-256 returns again without ../.venv/bin/python; :281-283 returns if the template subprocess fails; :336-339 (native_pixels_and_positions_match_the_checkpoint_processor) returns without ../.venv/bin/python. The tests only compare three synthetic rasters ((x % 256) as u8, :378-383) at (91,37), (10,3000), (3000,10).
Request. Replace the subprocess comparison with a checked-in fixture: add tests/frontend/gemma4_images.json (not opened) plus tests/frontend/generate_gemma4_image_fixtures.py (not opened) carrying width, height, grid, token count, and SHA-256 of resized bytes / pixel_values LE / position_ids LE, and assert them the way glm.rs:147-199 does. If a snapshot test is kept, mark it #[ignore = "requires FLARE_GEMMA4_TEST_SNAPSHOT and .venv"] and report the ignore in the description.
Why. AGENTS.md:103-109 requires skipped checks to stay visible and says test counts cannot stand in for the tested contract; AGENTS.md:306 says to "report a skipped test as an unrun check". The skip-return pattern itself has precedent here (the MiniMax test does the same at bracketed.rs:104-111), so the problem is not honesty — it is that the PR's headline result ("exact f32 pixel and (x,y) position parity") has no CI-executable witness, unlike GLM and Qwen, and a regression in resize::resize or the patch loop would pass the suite.
B3 — Atomic spans are produced in shared code, untested, with an undisclosed blast radius (Architecture, Conventions, Correctness)
Finding. helios/src/model/prompt.rs:137-151 fills prepared.data.spans from prepared.conditioned_inputs whenever data.spans.is_empty() and the contract declares an ImageSpan — a profile-independent condition. Consumers: validate_prompt_data (helios/src/model.rs:436-451) and Scheduler::set_prefill_spans via helios/src/server/runtime.rs:1458-1465 → helios/src/scheduler.rs:1912-1936. The span is re-derived from additional + 1 (prompt.rs:129-131, layouts/bracketed.rs:77-81), not from the indices the layout actually emitted.
Request. Emit the span where the envelope is built: have layouts/bracketed.rs:82-91 push data.spans for the range it expanded, mirroring layouts/deepseek.rs:149; delete prompt.rs:137-151; add a Bracketed contract fixture with image_tokens.span set and a test that the span is produced, passes validate_prompt_data, and is rejected/truncated when longer than prefill_chunk_size. In the description, state the before/after for existing span-declaring cores.
Why. The precedent is that the layout owns its PromptData, as deepseek.rs:149 does beside tokens.extend(block); after this PR one field is owned centrally and the rest by the layout. Coverage is zero: the only in-tree Gemma 4 contract fixture has "image_tokens": null (helios/tests/support/contracts/gemma4_frontend.json:38), and the layout matrix in prompt.rs:481-487 declares a span only for Deepseek/DeepseekRowMajor, which already fill their own spans — so the new branch never executes under test. Blast radius is undisclosed: a span-declaring layout that returned no spans previously failed prompt validation and now silently switches to atomic prefill, which is what "existing cores … unaffected" does not say.
Should Fix
S1 — Processor::load accepts settings neither the packer nor the cache validator can represent (Correctness)
Finding. helios/src/frontend/images/gemma4.rs:23-31 checks only patch_size ∈ 1..=64, pooling_kernel_size ∈ 1..=16, and the max_soft_tokens allowlist. It never requires pooling²== limits.patches_per_feature (used by prompt.rs:171 and packing.rs:488) nor that 3·patch_size² equals the packing stride (packing.rs:19).
Request. In load(), reject unless pooling_kernel_size * pooling_kernel_size == limits.patches_per_feature, 3 * patch_size * patch_size equals the declared patch width, and max_soft_tokens * pooling² <= limits.max_patches_per_image.
Why. With patch_size = 14, pooling = 3, the profile loads, emits 588 floats per patch (gemma4.rs:116), and packing.rs:497 slices at the 768-wide stride — truncated pixels or silently misaligned tensors — while conditioned.rs:192's literal 768 makes cached records fail valid_processed forever with no error. The one place where the profile and the packing contract must agree is the one place not validated.
S2 — Patch width authored three times with no compile-time link (Conventions, Simplicity)
Finding. packing.rs:19 (9 => 768), conditioned.rs:192 (Profile::Gemma4(_) => 768, the cache predicate), gemma4.rs:116 (3 * patch_size * patch_size).
Request. One shared constant or helper derived from profile + contract metadata, used by conditioned.rs, bracketed() and gemma4::process (subsumed by B1's fix — listed so the fix is complete).
Why. conditioned.rs:191 already shows the better pattern for PaddedGrid (it references padded_grid::FEATURES); a divergence between the three surfaces as "image preprocessing differs from its prompt geometry", which points the reader at the wrong layer.
S3 — The max_soft_tokens + 2 ≤ prefill_chunk_size invariant is unenforced (Correctness)
Finding. max_soft_tokens: 1120 (gemma4.rs:11) expands to a 1,122-token envelope (patch_merge.rs:58-69 pushes start + image tokens + end; the test asserts start + 261 for 260 tokens at gemma4.rs:318-320). validate_prompt_data rejects spans longer than config.limits.prefill_chunk_size (model.rs:421-423), and set_prefill_spans rejects s.end - s.start > capacity (scheduler.rs:1922-1930); the server turns both into failed requests (runtime.rs:1458-1465).
Request. Reject the combination at load with a named error, or clamp max_soft_tokens to the largest value whose envelope fits, and add a boundary test at exactly the chunk size.
Why. Latent at repository defaults (ignition/preparation/bootstrap.py:36 (not opened) sets prefill_chunk_size = 4096; limits require ≥64 and 64-alignment, scheduler.rs:67-73), but a 1024-chunk Gemma 4 deployment admits every image at geometry time and then fails it at prompt validation with an error naming neither images nor spans.
S4 — Ignition's gate pins one vision tower and derives nothing from the checkpoint (Architecture)
Finding. ignition/preparation/frontend.py:126-129 asserts num_hidden_layers 27, hidden_size 1152, num_attention_heads 16, head_dim 72, intermediate_size 4304 — one architecture variant, not a preprocessor fact — and the three image tokens are literals (:134-136) rather than checked against the checkpoint's added tokens.
Request. Assert only what the preprocessor consumes (model_type: gemma4_vision, patch_size, pooling_kernel_size, max_soft_tokens, rescale/normalize/convert flags), take the three token strings from the tokenizer config with an assertion that each encodes to exactly one added token, and either add a second checkpoint to the evidence or narrow the claim.
Why. The charter's "New model recipes … must list supported checkpoints from an official or widely used source … and support more than a single checkpoint (#74)" is not met by one snapshot (google/gemma-4-31B-it, 842da379), while docs/model-preparation.md:345 lists e2b/e4b/12b/26b-a4b/31b. An otherwise identical checkpoint is rejected by preparation with a generic "unexpected … vision configuration"; a checkpoint with different token spellings fails later at request time ("image envelope marker must encode one token", patch_merge.rs:46).
S5 — Documentation the change makes stale was not updated (Prose)
Finding. helios/README.md:702-704 lists the profiles and omits Gemma 4; docs/runtime-core-design.md:226-233 enumerates image settings per profile with no Gemma 4 entry and says nothing about Bracketed deriving its stride; helios/model-contract.md:251-254 covers atomic spans and layout data and does not mention the new preparation kind; docs/TODO.txt has no entry for the recipe dependency.
Request. Add Gemma 4 (16×16 patches, 3×3 pooling, soft-token set) to the three enumerations and record the companion-recipe dependency in docs/TODO.txt.
Why. AGENTS.md:52-59 treats documents as present-state specifications and puts unrun checks and pending measurements in docs/TODO.txt; since the parallel text lists every other profile, the omission reads as "not supported" after merge.
S6 — Description corrections (Prose)
Findings and requests.
- Delete or reword the orthogonality sentence:
packing.rs:16-22does the opposite of what it claims (see B1). - Drop
Execution.persistent_workersfrom the evidence bullet — it is #430 (66bf6d03), not in this diff. - Replace "Existing cores and non-Gemma image profiles remain wire-compatible and unaffected" with the concrete load-path narrowing (
patches_per_featuremust now be 4 or 9, reached frommodel/packing.rs:92-97at core load) and say which cores were swept. - Rewrite "Why" to name the failing workflow and the serve-time errors ("prefill splits an atomic image span",
helios/src/model/packing.rs:624; admission of a Gemma 4 multimodal request without the profile). - State that no serving-path timing or memory was measured, and that the parity comparison does not run under a plain
cargo test.
Why. AGENTS.md:72-140 requires the four description parts to carry real evidence and scope, and :129-132 says to remove process assurances that add no technical evidence.
S7 — Regenerated Python bindings went backwards in generator version (Conventions, Prose)
Finding. ignition/preparation/runtime_core_pb2.py:5 changes Protobuf Python Version: 7.36.2 → 7.36.1 and the ValidateProtobufRuntimeVersion minor argument 2 → 1, while pyproject.toml:34 pins protobuf>=7.36.2,<8.
Request. Regenerate with the tree's protoc (protoc --proto_path=helios/proto --python_out=ignition/preparation helios/proto/runtime_core.proto, documented at helios/manifest.md:465-472) so the header returns to 7.36.2 and only descriptor bytes change, or state the intended version change in the description.
Why. Not a runtime break (the check rejects an older runtime, not an older gencode), but the checked-in artifact now records a generator older than the pin, against "be explicit and pin everything".
Nits
- N1 (Simplicity).
packing.rs:494-502rewrites the one-linestaging.put("vision_pixel_values", …)into a six-lineflat_map(f32::to_le_bytes)call whose only real change is1176 → patch_width. Keep the original line and change the constant (AGENTS.md:188-193on churn). - N2 (Testing).
packing.rs:574-585asserts the lookup table (4 → 16·1176,9 → 630·768,16errors), so it keeps passing through exactly the B1 mistake. Test the behaviour instead:bracketed()atpatches_per_feature = 9(thetokens·ppf == patchesidentity, the truncated-pixel error at:498, an odd-grid rejection).bracketed()at 9 is currently untested. - N3 (Simplicity).
packing.rs:486'sh % merge_side || w % merge_sidecheck is redundant with the geometry its only producer emits (gemma4.rs:46-48,:63-64floor both sides to multiples ofpatch_size * pooling). If the profile keeps that guarantee,bracketed_patch_geometrycollapses to a width and this check can go. - N4 (Duplication). The soft-token allowlist is written twice with no citation:
gemma4.rs:11([70, 140, 280, 560, 1120]) andignition/preparation/frontend.py:123. The Python producer rejects everything else first, so the Rust copy is unreachable — keep one authority and name the upstream field (image_processor.max_soft_tokens) at both sites. - N5 (Testing). No round-trip test for the new protobuf tag.
helios/src/runtime_core/protobuf.rs:167-171mirrors thePatchMergearm correctly, but GLM and padded-grid each have aserialized_*_selects_only_image_preparationtest (protobuf.rs:726,:749). Addserialized_gemma4_profile_selects_only_image_preparation— it is the only automated evidence for the additive wire claim. - N6 (Prose).
conditioned.rs:192's bare768wants a comment ("3×3 pooling over 16×16×3 = 768 floats per feature");patch_merge.rs:10's "shared by enveloped image layouts" is self-referential (name the layouts and the three fields); the newfrontend.py:113-137branch has no note that the fixed dimensions and tokens are the checkpoint's canonical processor values validated by_expectedbelow (siblings do document themselves, e.g.:99);packing.rs:491's "bracketed patch-merge" mixes the enum name with the README's "patch-merge" label — pick one. - N7 (Prose). The description repeats the base commit
6d6fe0c6in both "Branch logistics" and "Verified on base".
Verified clean (do not re-litigate)
- Wire format is additive and preserves ids.
ImagePreparationKind::Gemma4 = 11(contract.rs:68,runtime_core.proto:383-387),ImageSettings.gemma4 = 11(runtime_core.proto:510-524), newGemma4ImageSettings(:535-542); decode and describe arms mirrorPatchMerge(protobuf.rs:167-171,describe.rs:442-444); JSON usesdeny_unknown_fieldssnake_case like its neighbours (mod.rs:332-341). A core prepared here is not readable by an older binary (expected direction); older cores still load. Envelopeextraction is genuine de-duplication.patch_merge.rs:10-81shared by PatchMerge and Gemma 4;Envelope::loadkeeps the token-uniqueness checks (:19-30) andexpandkeeps the one-token/marker-count checks (:38-57);Processorremains a thin wrapper, so callers inmod.rsare untouched.- Gemma 4 arithmetic is self-consistent and guarded. Aspect-preserving resize to
patch_size * poolingmultiples,checked_add/checked_mul/try_fold(gemma4.rs:103-129),limits.check_batchapplied before and after geometry,check_input_extent/check_image_patcheson the new path, sharedresize::resizerather than a new kernel, EXIF/alpha handling inherited frommod.rs:537,613,705. - No other layout or width changed. All non-Gemma arms of
tensor_layoutkeep their fixed widths;class_token()still asserts 4; no existing graph shape is resized.
Open questions and what could not be established
- Does any shipped core declare an
ImageSpanwith an envelope-expanding layout? This decides whetherprompt.rs:137-151is a no-op for existing models or a scheduling change. Core manifests live inlocal-inference-lab/hyperflare-recipes, outside this repository. - What
prefill_chunk_sizedo Gemma 4 cores get? Only a real prepared core or recipe shows whether the 1,122-token envelope fits (model.rs:422,scheduler.rs:1926); the Ignition default of 4096 makes S3 latent. - Did the live
Gemma4ImageProcessorcomparison actually run for the reported "45 passed"? Only a run with the snapshot and.venvpresent, plus per-test skip visibility, settles it. - Which
protocregeneratedruntime_core_pb2.py, and does 7.36.1 satisfy theprotobuf>=7.36.2pin?pyproject.toml:34was not re-opened in this pass; the pin value should be confirmed. - Does any second Gemma 4 checkpoint share the vision tower pinned at
frontend.py:126-129? Running preparation against the e2b/e4b/26b-a4b checkpoints indocs/model-preparation.md:345would settle charter #74. - Should a prefix-cache match ending inside an atomic image envelope fail the request or fall back to the envelope boundary?
scheduler.rs:2149consultsvision.patches_per_feature, suggesting image-aware boundary handling may exist, but no test asserts either behaviour.