Subtraction review of PR #483 — "Add Gemma 4 image preparation, Bracketed patch-width metadata, and atomic spans"
Head ab9a432, base main 27716185, 38 files, +2490 / −251 (pr_files).
Key findings
This is two changes stapled together. One half is a real, small fix: make Bracketed patch width and merge stride come from the prepared contract instead of a hardcoded 2×2 / 1176 table, and emit atomic spans from layouts::bracketed. That half fixes a genuine defect on main and is worth roughly 1,280 lines. The other half — an entire Gemma 4 image profile — has no consumer in this repository and is roughly 1,210 lines, 49% of the diff. The charter requires new formats to "prove they export and serve cleanly from the PR branch" (read_charter, roadmap item #74), and the PR's own docs/TODO.txt:331-337 lists exactly that work as not yet done.
Everything else below is ordinary duplication: a hand-rebuilt test manifest, an 11-row profile table that repeats existing tests, unread fixture keys, and two tests that restate fixture cases already pinned by SHA-256.
Totals: ~1,514 lines removable (61% of the diff) if the profile is deferred; ~304 lines (12%) if it is kept.
1. Blocking — the Gemma 4 image profile has no in-tree consumer (~1,210 lines)
Files and sizes (pr_files added-line counts):
helios/src/frontend/images/gemma4.rs— 504tests/frontend/gemma4_images.json— 256tests/preparation/test_frontend_gemma4.py— 257tests/frontend/generate_gemma4_image_fixtures.py— 94ignition/preparation/frontend.py:114-173— ~60 (the wholeprofile == "gemma4"branch)- wire/enum/describe/conditioned/config arms plus the protobuf round-trip test — ~40:
helios/proto/runtime_core.proto(not opened) (Gemma4ImageSettings,ImagePreparationKind::Gemma4tag 11),helios/src/model/contract.rs,helios/src/runtime_core/{describe,protobuf}.rs,helios/src/frontend/images/conditioned.rs:354-361,helios/src/server/config.rstest.
What goes: the whole Gemma4 preparation kind and its fixture set. What replaces it: nothing today.
Why nothing is lost:
- No prepared contract in the repository declares
Bracketed: nothing underhelios/tests/support/contractsuses that layout, so no core can reachimage_profile="gemma4".ImagePreparationKind::Gemma4has no non-test caller. - The production code changes that are not Gemma-specific are separable and should land:
packing.rsreadingVisionCapabilities::bracketed_patch_features()instead of the width table,ImageProcessor::patch_features(),layouts/bracketed.rsspan emission, andserver::configenvelope-bounds checks (see findings 3 and 6 for trims within those). - The PR itself concedes the gap:
docs/TODO.txt:331-337(added here) says qualification happens "once the companion Gemma 4 vision recipe is wired", then lists E2B/E4B/26B-A4B/31B export + serving and the partial-span prefix-cache audit as open. - Charter roadmap #74 and AGENTS.md:194-199 ("Do not present scaffolding or partially wired features as supported"). The recipes were extracted to
local-inference-lab/hyperflare-recipes(commit17bb3c4a, "Remove extracted hyperflare_recipes, qualification drivers, and model tests from core Flare"), so the consumer cannot arrive in this repository at all.
Smaller version: land the shared Bracketed fix; move gemma4.rs, the two tests/frontend/gemma4* fixture files, tests/preparation/test_frontend_gemma4.py and frontend.py:114-173 to the companion recipe PR that declares vision.patch_features = 768, where they can be qualified against a real export.
2. Should fix — model/tests.rs:1277-1452 rebuilds testing::manifest by hand (~110 lines)
legacy_bracketed_core_omitting_patch_features_loads_and_stages_1176_wide_pixels is 177 added lines. Inside it:
:1304-1332hand-writes nineValueBindings for the graph contract it just constructed at:1312-1332.:1343-1411is a 68-linebuild_manifestclosure that clones a manifest and repeats the descriptor/stride loop thathelios/src/model/testing.rs:307-336already implements (samenext_multiple_of(8)address walk, same reversed-stride computation, sameBufferDescriptor+InputBindingpairing).
What replaces it: crate::model::testing::manifest (helios/src/model/testing.rs:242), with one GraphOperation::Vision => GraphKind::Vision arm at testing.rs:344-355 (currently _ => unreachable!()) and the existing _ => 1 width at :257 extended to size vision_pixel_values from vision.bracketed_patch_features(). That removes :1304-1411 entirely.
Alternatively, drop the manifest half altogether: the load behaviour under test is square_merge_side/bracketed_patch_features via Inputs::new (helios/src/model/packing.rs:92-102), and packing.rs:594-682 already asserts all three arithmetic outcomes (768 accepted, 0 → 1176, non-square rejected) without a manifest. Keep only the serde-default assertion at :1334-1338.
Why nothing is lost: the assertions stay; only the hand-rolled fixture construction goes. Saving ~110 lines.
3. Should fix — packing.rs:684-814 11-row profile table repeats existing coverage (~110 lines)
processor_patch_features_match_tensor_layout_for_every_profile builds a Vec<(ImageSettings, ImageLimits, ImageLayoutKind, usize, usize)> with 11 rows (Qwen, Mimo, Glm, PatchMerge, PaddedGrid, Deepseek4, DeepseekRowMajor, Moonvit, Step, Radio, Gemma4) and asserts one width per row.
Those widths are already asserted twice elsewhere: helios/src/frontend/images/conditioned.rs:329-363 and :428-504 (valid_processed compares images.pixel_values.len() == patches * processor.patch_features()), and helios/src/model/packing.rs:92-102 rejects a mismatched buffer at Inputs::new.
What replaces it: four rows — Glm 1176, PatchMerge 1176/Bracketed/0, PaddedGrid 1200/ClassToken, Gemma4 768/9 — which are the only ones carrying a distinct outcome. The genuinely new test directly above (bracketed_packs_3x3_metadata_widths_and_rejects_invalid_extents, :594-682) stays untouched.
Why nothing is lost: every distinct arithmetic path (nonzero width, legacy 0 → 1176, non-square rejection, non-Bracketed unaffected) is exercised by the surviving rows; the deleted seven rows only restate per-profile constants. Saving ~110 lines.
4. Should fix — tests/frontend/gemma4_images.json provenance blocks carry keys nothing reads (~75 lines)
ignition/preparation/frontend.py:114-141 reads exactly: processor_class, image_processor (image_processor_type, patch_size, pooling_kernel_size, do_resize, do_rescale, do_normalize, image_mean, image_std, optional resample/rescale_factor/do_convert_rgb, max_soft_tokens), model_type, vision_config.model_type / patch_size / pooling_kernel_size, and the three token ids. tests/preparation/test_frontend_gemma4.py:187-225 feeds the same blocks through _write_synthetic_snapshot and image_settings.
Nothing reads:
"feature_extractor"(gemma4_images.json:5-25, 21 lines) and"audio_ms_per_token"/"audio_seq_length"(:3-4) — audio is not part of this profile."video_processor"(:51-75, 25 lines) — video is not part of this profile.- ~32 keys inside
vision_config(:79-120):attention_bias,dtype,global_head_dim,hidden_size,intermediate_size,num_hidden_layers,rope_parameters,id2label/label2id, etc. The PR description says encoder depth and width "belong to the preparing recipe" (frontend.py:116-117), so storing them here contradicts the code that reads them.
What replaces it: the processor block reduced to processor_class + image_processor (the keys frontend.py:120-133 validates) and the model block reduced to model_type, vision_config's three checked keys, and the three token ids. Saving ~75 lines.
Why nothing is lost: if a key is dropped that the validator would have rejected on, the synthetic-snapshot test (test_frontend_gemma4.py:180-184) already covers mismatched and bool token ids; the remaining keys are the ones the code branches on.
5. Should fix — two gemma4.rs tests restate fixture cases (~37 lines)
helios/src/frontend/images/gemma4.rs:383-402 geometry_matches_the_hugging_face_processor has nine rows; seven of them (1×1, 672×672, 1008×672, 91×37, 1920×1080, 10×3000, 3000×10) are cases in the checked-in fixture asserted by canonical_processor_pixels_positions_and_resize at :314-381 (grid, tokens, patches, resized SHA, pixels SHA, positions SHA). Only (100, 3000) and (3000, 100) are unique shapes.
What replaces it:
for (width, height) in [(100, 3000), (3000, 100)] {
let g = processor.geometry(width, height).unwrap();
assert_eq!(g.tokens * 9, g.patches, "{width}x{height}");
}
helios/src/frontend/images/gemma4.rs:404-420 pixels_interleave_rgb_and_positions_are_xy re-derives the 91×37 case: same grid [1, 30, 78], same pixel count, (x, y) ordering (exactly what the positions SHA pins), and the same cu_seqlens already asserted at :378. Delete the function.
Why nothing is lost: the fixture is generated from Hugging Face's Gemma4ImageProcessor and verified unconditionally in cargo test; these tests assert the same numbers by hand. Saving ~37 lines.
6. Nit — layouts/bracketed.rs:55-88 run-tracking state machine (~14 lines)
Three pieces of state — run_start: Option<usize> (:55), the flush_span closure (:57-65), and the trailing flush after the loop (:86-88) — exist to find each run's end, which is known when the run starts: processed.geometry[image].tokens. Envelope::expand (patch_merge.rs:59-70) always wraps a run in exactly one start and one end token.
What replaces it (span pushed where the run begins, atomic_spans: bool → span: Option<&ImageSpan>):
if position == 0 || expanded.mm_token_type_ids[position - 1] == 0 {
let source = images.get(image).ok_or("unexpected image token span")?;
conditioning.push(ConditioningEvent { position: position as u64, identity: source.identity });
if let Some(_) = span {
let end = position + processed.geometry[image].tokens + 1;
spans.push(position.checked_sub(1).filter(|_| end <= expanded.token_ids.len())
.ok_or("bracketed image feature run is outside the expanded prompt")?..end);
}
image += 1;
}
and at the call site helios/src/model/prompt.rs:52-65, pass the Option<&ImageSpan> directly instead of the .and_then(|layout| layout.span.as_ref()).is_some() chain. The bounds error is preserved (both ends checked at run start instead of at flush). Saving ~14 lines.
7. Nit — patch_size / pooling_kernel_size wire knobs and a twice-spelled allowlist (~18 lines)
Gemma4ImageSettings.patch_size and .pooling_kernel_size (helios/proto/runtime_core.proto:598-599 (not opened), helios/src/model/contract.rs mod arms at :334-336, gemma4.rs:18-19) are pinned by ignition/preparation/frontend.py:169-170 to 16 and 3, and gemma4::Processor::load already rejects anything else (the 16/3 relationship to limits.patches_per_feature is checked at load). Keeping them on the wire adds a field, a serde default question, a describe path and a decode arm for values that cannot vary. The soft-token allowlist (70, 140, 280, 560, 1120) is spelled twice, once per language: gemma4.rs:13 and frontend.py:132.
What goes: the two wire fields (derive 16 and 3 inside the processor, as the layout already does for Bracketed), and one copy of the allowlist (keep the Python one, where the checkpoint is validated; Rust needs only the hard cap). Saving ~18 lines. This one is small and stands or falls with finding 1.
Examined and rejected (do not report as subtractions)
patch_features = 0decoding to the legacy 1176 width (helios/src/model/model.rs(not opened) /contract.rsdefault) — required so existing MiniMax cores keep loading; this is the compatibility half of the fix.- The
patch_merge::Envelopeextraction (helios/src/frontend/images/patch_merge.rs:10-136) — genuine de-duplication between the PatchMerge and Gemma 4 paths, not new generality. bracketed_patch_features()/square_merge_sideload-path validation and its behavioural test athelios/src/model/tests.rs— enforces a stated invariant (positive square merge stride), and the test is the only check of it.- The envelope-bounds checks in
helios/src/server/config.rs(max_image_envelope_tokens <= prefill_chunk_sizeand<= image_tokens.span.max_tokens) — the PR description's stated purpose ("failing at load when the maximum image envelope exceeds ..."), so removing them would remove a claimed behaviour. - The author's second push already fixed the earlier round's real problems: per-condition load errors (
gemma4.rs:27-71), a singleBracketedre-export error (server/config.rs:449-463),self.patch_features()reuse (gemma4.rs:164), fixture provenance now asserted (test_frontend_gemma4.py:187-225), the duplicated#[ignore]HF-parity test deleted, and README/docs scoped (helios/README.md:713-730, 798-807;docs/runtime-core-design.md:181-197 (not opened), 236-241).
Open questions / not found
- Whether a Gemma 4 vision recipe is expected to land in
NVIDIA/hyperflare-inference(rather than in the extractedhyperflare-recipes). Nothing in the tree says so;docs/TODO.txt:331-337implies the opposite. - No CI runs on the head commit, so the line counts and test claims in the description could not be re-verified by running anything here.
Counting basis
Added lines per file from pr_files. Production vs test split at head: production ~1,180, tests/fixtures ~1,310. Removable: ~1,514 lines (61%) if finding 1 is accepted; ~304 lines (12%) for findings 2-7 alone if the profile is kept.