Subtraction review of PR #483 (+2269 / −240, 36 files)
Key findings
The change is two changes stapled together: a genuine shared fix (per-profile patch width, contract-driven Bracketed packing, Bracketed atomic spans) worth ~1,070 lines, and an entire Gemma 4 image profile (~1,200 lines, 53% of the diff) that nothing in the repository consumes and that the PR itself says cannot serve until an unlanded recipe PR exists. Charter #74 requires new recipes/formats to "prove they export and serve cleanly from the PR branch"; AGENTS.md forbids "presenting scaffolding or partially wired features as supported." The profile half should be deferred, and the remaining half is itself carrying ~350 lines of tests and fixture data that duplicate each other or are read by nothing.
Nothing in the PR is dead behaviour in the shared half — the shared fix removes a real defect (conditioned.rs's _ => 588 fallback was wrong for PatchMerge = 1176 and PaddedGrid = 1200), and I verified the patch_features = 0 → 1176 legacy default is required by docs/design-review.md principle 13 and AGENTS.md core compatibility (existing MiniMax cores have no such field), so it is not a finding.
Ranked by lines saved:
| # | Severity | Where | Saves |
|---|---|---|---|
| 1 | Blocking | Gemma 4 profile (gemma4.rs, fixtures, tests, ignition block, enum arms) | ~1,200 |
| 2 | Should fix | gemma4.rs:374-533 two #[ignore] tests |
~160 |
| 3 | Should fix | gemma4_images.json:2-125 + generator 28-29, 81-85 | ~134 |
| 4 | Should fix | packing.rs:694-825 all-profile table | ~132 |
| 5 | Should fix | gemma4.rs:335-372 geometry/pixel tests | ~24 |
| 6 | Nit | server/config.rs:449-464 duplicate width compare; packing.rs:26-32 square_merge_side |
~20 |
| 7 | Nit | layouts/bracketed.rs:52-88 run-tracking closure + atomic_spans: bool |
~14 |
1. Blocking — the Gemma 4 profile is scaffolding with no in-tree consumer (~1,200 lines)
Evidence it is not needed yet
- The PR's own Limitations: "End-to-end multimodal serving requires the companion Gemma 4 vision recipe PR in
local-inference-lab/hyperflare-recipes(which declaresvision.patch_features = 768)." docs/TODO.txt:330-337(added by this PR) is entirely deferred work: "[ ] Qualify Gemma 4 vision end-to-end once the companion Gemma 4 vision recipe is wired … verify E2B, E4B, 26B-A4B, and 31B checkpoints through export and native serving."- No core in the repo declares it:
helios/tests/support/contracts/*.jsonuseimage_layoutvalues 1, 2, 3, 5, 6, 10 only;image_profile = "gemma4"has no non-test caller (its only users aretests/preparation/test_frontend_gemma4.py:87,204). - Charter rules against it: read_charter — new recipes/formats must "list supported checkpoints from an official or widely used source, prove they export and serve cleanly from the PR branch, and support more than a single checkpoint (#74)"; and "Keep the runtime small and model-agnostic … Helios shouldn't accumulate per-model branches (#267, #334)".
What goes if the profile is deferred
| Path | Added lines |
|---|---|
helios/src/frontend/images/gemma4.rs (whole file; 185 production, 350 test) |
534 |
tests/frontend/gemma4_images.json |
256 |
tests/preparation/test_frontend_gemma4.py |
216 |
tests/frontend/generate_gemma4_image_fixtures.py |
94 |
ignition/preparation/frontend.py:114-173 (Gemma 4 checkpoint gate) |
~60 |
helios/proto/runtime_core.proto:598-605 Gemma4ImageSettings, ImagePreparationKind::Gemma4, mod.rs arms, protobuf.rs arm + round-trip test, describe.rs, conditioned.rs:354-361, config.rs Gemma 4 test, docs |
~40 |
~1,200 lines, leaving ~1,070 that carry only the shared fix.
What should stay and land on its own (all of it addresses a demonstrable defect or a missing invariant):
ImageProcessor::patch_features()(helios/src/frontend/images/mod.rs:459-469) replacing the duplicated table atconditioned.rs:184-194, whose_ => 588fallback was wrong forPatchMerge(1176) andPaddedGrid(1200).Bracketedreading width and merge stride from the contract instead of the hardcoded 1176 / 2×2 (packing.rs:49-56,493-518).- The
patch_featurescontract field itself with0= legacy 1176 (helios/src/model.rs:51-53), which core compatibility requires. Bracketedatomic spans (helios/src/frontend/images/layouts/bracketed.rs:52-88) — a span-declaringBracketedlayout currently fails per request atvalidate_prompt_data.- Load-time envelope bounds (
server/config.rs:465-488).
Smaller version of the whole PR: one commit adding the contract field + per-profile width + contract-driven Bracketed packing + Bracketed spans; the profile moves to the recipe PR that can actually export and serve it, and brings its own fixtures and tests then.
2. Should fix — two #[ignore] tests duplicate the checked-in fixture (~160 lines)
helios/src/frontend/images/gemma4.rs:374-533 (only relevant if the profile stays).
checkpoint_tokens_expand_the_image_envelope(374-447, 74 lines,#[ignore = "requires FLARE_GEMMA4_TEST_SNAPSHOT"]) asserts a 262-token start/feature/end envelope from a real tokenizer. The sameEnvelope::expandbehaviour is already asserted unconditionally by the new pure-Rust testpatch_merge.rs:218-305(start ids, end ids, feature ids,mm_token_type_ids, mismatch rejection) and again bymodel/prompt.rs:1170-1283(span.len() == 262, markers at both ends).native_pixels_and_positions_match_the_checkpoint_processor(449-533, 85 lines,#[ignore = "requires .venv with transformers Gemma4ImageProcessor"]) shells out to Python and callsGemma4ImageProcessorover (91,37), (10,3000), (3000,10).tests/frontend/generate_gemma4_image_fixtures.py:27-80runs the same reference processor over the same and more sizes; the resulting SHA-256s are asserted unconditionally under plaincargo testbycanonical_processor_pixels_positions_and_resize(gemma4.rs:266-333).
Neither runs in CI (both require an environment variable or .venv), and both deviate from the repo's existing optional-snapshot pattern of an early return (layouts/bracketed.rs:126, frontend/images/decoding_tests.rs (not opened), helios/tests/tools/test_images.rs) — the PR description frames this as deliberate, which only makes them fail-if-you-fiddled tests.
Smaller version: delete both functions plus the imports they alone need (crate::frontend::{Asset, FrontendAssets, images::ImageSettings} at 189, sha2 at 190, std::path::PathBuf at 191). Every assertion stays covered unconditionally. ~160 lines.
3. Should fix — the fixture ships 124 lines no test reads (~134 lines)
tests/frontend/gemma4_images.json:2-125 contains a full processor block (audio feature extractor, image processor, video processor — lines 2-76) and a full model block (vision_config + model_type + image_token_id/boi_token_id/eoi_token_id — lines 77-125).
The only consumer is helios/src/frontend/images/gemma4.rs:269-273, which parses the file and reads fixture["cases"].as_array(); a repo-wide search for gemma4_images returns that single hit, and helios/tests/tools/test_images.rs expects an assets key and is not pointed at this file. Nothing reads ["processor"] or ["model"].
tests/frontend/generate_gemma4_image_fixtures.py:28-29 reads processor_config.json (not opened)/config.json (not opened) only to build those blocks (81-85), which are written at line 86 as dict(processor=raw, model=profile, cases=cases).
Smaller version: write dict(cases=cases); delete generator lines 28-29 and 81-85 and JSON lines 2-125. ~124 JSON + ~10 Python lines.
Honest caveat: tests/frontend/glm53_images.json:2-87 and generate_glm_image_fixtures.py:29-30,43-44 already do the same thing, so this copies an existing (already dead) convention rather than inventing one. For a newly added 256-line file it is still 134 lines of data no code reads.
4. Should fix — packing.rs 11-profile table test repeats conditioned.rs (~132 lines)
helios/src/frontend/images/packing.rs:694-825 processor_patch_features_match_tensor_layout_for_every_profile builds an 11-row table of ImageSettings + ImageLimits + layout + patches_per_feature + patch_features and asserts processor.patch_features() == tensor_layout(...).1.
That equality is already enforced twice, unconditionally:
conditioned.rs:329-362already enumerates the same 11 profiles (this PR adds the Gemma 4 row at 354-361), andconditioned.rs:428-504independent_preparation_matches_batches_for_every_profileruns each throughImageProcessor::load→process→materialize, which goes throughvalid_processed(conditioned.rs:185-218, nowpixel_width = self.processor.patch_features(), line 213images.pixel_values.len() == patches * pixel_width). A wrong per-profile width fails there today.- The buffer-side half is enforced at load by
helios/src/model/packing.rs:92-102, which rejects a captured buffer whose dtype or element count differs fromtensor_layout.
Smaller version: delete the table (694-825) and the ImageSettings imports it needs. Keep bracketed_packs_3x3_metadata_widths_and_rejects_invalid_extents (603-693), which is the only genuinely new behaviour (3×3 stride, 768 width, truncation/odd-grid rejection). If direct table coverage is wanted, three rows (PatchMerge 1176, PaddedGrid 1200, Bracketed/Gemma4 768) say the same in ~12 lines instead of 132.
5. Should fix — gemma4.rs geometry/pixel tests restate the fixture (~24 lines)
geometry_matches_the_hugging_face_processor(335-354): nine hardcoded(width, height, grid, tokens)rows. Seven of them (1×1, 672×672, 1008×672, 91×37, 1920×1080, 10×3000, 3000×10) are exactly the cases intests/frontend/gemma4_images.json, already asserted from HF-derived values bycanonical_processor_pixels_positions_and_resize(gemma4.rs:288-302). Only (100,3000) and (3000,100) are new; keep those two rows and drop seven (~7 lines).pixels_interleave_rgb_and_positions_are_xy(356-372): assertsgrid_thw == [1,30,78],pixel_values.len() == patches*768,cu_seqlens == [0, patches], plus the first threeposition_ids. The 91×37 fixture case already pinsgrid,pixelsandpositionsby SHA-256 (gemma4.rs:303-330), andcu_seqlensis asserted at line 330 of that same test. Delete the function (~17 lines).
No loss: the only unique bit, (x, y) ordering, is exactly what the positions hash pins.
6. Nit — one duplicated width comparison and one misplaced helper (~20 lines)
helios/src/server/config.rs:443-464 compares the processor width against the contract twice:
if vision.patch_features != 0 && width != vision.patch_features { /* err A */ }
if image_layout == Some(Bracketed) {
let expected = packing::bracketed_patch_features(vision);
if width != expected { /* err B */ }
}
The second block is unreachable after the first whenever patch_features != 0, since bracketed_patch_features returns vision.patch_features in that case. One condition covers both, with one error string instead of two:
let bracketed = model.contract.frontend.image_layout == Some(ImageLayoutKind::Bracketed);
if let Some(expected) = (vision.patch_features != 0 || bracketed)
.then(|| packing::bracketed_patch_features(vision))
.filter(|expected| width != *expected)
{
return Err(format!("image preparation patch width ({width}) differs from the prepared layout width ({expected}); re-export the core with vision.patch_features").into());
}
All three rejections exercised by the test at config.rs:936-1024 (legacy 0 → 1176 mismatch, explicit mismatch, match) still fire. ~10 lines.
Related: square_merge_side (packing.rs:26-32) exists only so tensor_layout can reject a non-square patches_per_feature at load, and it forces a vision argument through tensor_layout (packing.rs:34-39), through model/packing.rs:92-97, through four test call sites, plus a duplicate call in bracketed() (packing.rs:495). Every in-tree profile has a square ratio (Qwen 4, Mimo 4, Deepseek 9, DeepseekRowMajor 9, Moonvit 4, Step 4, Radio 4, Glm 4, PatchMerge 4, PaddedGrid 4, Gemma 4 9), so it is a contract invariant: fold it into VisionCapabilities::validate() (helios/src/model.rs:72-92) and delete the helper plus the extra parameter. ~8-12 lines and a smaller signature.
7. Nit — the span can be computed where the run starts (~14 lines)
helios/src/frontend/images/layouts/bracketed.rs:52-88 threads run_start state, a two-branch flush_span closure and a trailing flush in order to push start-1..end+1. The run's extent is already known when the run starts (processed.geometry[image].tokens), so the state machine disappears:
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) = 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 span is missing envelope markers")?..end);
}
image += 1;
}
~10 lines, no closure. The closure's two error branches are also redundant with admission: validate_prompt_data (helios/src/model.rs:425-428 requires s.start < s.end <= tokens.len(); 441-456 requires tokens[s.start] == span.start_token and tokens[s.end-1] == span.end_token) already rejects a mis-placed boundary.
Separately, atomic_spans: bool (bracketed.rs:23) is computed in exactly one place — helios/src/model/prompt.rs:58-64 — from image_tokens.span.is_some(). Passing Option<&ImageSpan> instead removes the boolean and the .is_some(), matching how class_token::prepare_input already receives a prepared layout field (model/prompt.rs:69-73). ~4 lines.
Open questions / what I could not establish
- Is the Gemma 4 profile wanted on this timeline? If a maintainer has asked for it (charter: "PRs that address a maintainer request" get merged), finding 1 shrinks to "land half A now, half B when the recipe lands"; findings 2-5 then still apply in full (~450 lines).
- Could the fixture serve double duty? The
model/tokenizerids ingemma4_images.json:121-124would be a legitimate input for an ignition-side checkpoint test, but no such test is added here and the ignition tests use real cached checkpoints (tests/preparation/test_frontend_gemma4.py), so today they are unread. If a future ignition test wanted them, they should live with that test rather than in a Helios hash fixture. - Perf/memory of the new resize path: not measured by the PR (it says so); out of scope for subtraction but it means the profile is unqualified on the axis that matters most for a runtime.
- I did not find any existing helper that already implements the antialiased bicubic resize (the
helios/src/frontend/images/*profiles each carry their own resampler), sogemma4.rs's production code is not duplicating a utility — the duplication is at the test/fixture level, as recorded above.