Review of PR #483 — simplicity lens (what can be deleted)
Charter/guidance used: docs/design-review.md:16 ("Keep Helios as simple as possible"), AGENTS.md:188-193 ("Reject unsupported abstractions and churn. Do not add … configuration switches without a concrete requirement. Unsolicited formatting … are not contributions by themselves"), AGENTS.md:194-199 ("Tests must exercise the affected behavior or contract"), AGENTS.md:431-444 (protobuf additions must be additive and preserve existing behavior), AGENTS.md:466-468 (tests may read opt-in variables but must not change what the code under test does).
Key findings
- The two new
Gemma4ImageSettingsnumbers are not knobs, only duplicated constants.patch_sizeandpooling_kernel_sizetravel proto → Rust struct → Python producer, are validated ingemma4.rs, and are then contradicted by three hard-coded copies of768elsewhere. Deleting both fields is a strictly smaller diff and removes a silent cache-invalidation bug (details below). - Two thirds of the new test code is scaffolding that proves nothing, or nothing on CI. The envelope test spawns Python to build a chat template it never renders (and leaks the temp file); the parity test silently returns when a local venv is missing, so the "45 passed" evidence depends on an unpinned local
transformersinstall, unlike every other profile's checked-in fixture. prompt.rs:137-151is a second span producer that duplicateslayouts/deepseek.rs:149and is unreachable for the only other layout that declares a span.- The genuinely good de-duplication this PR does (extracting
Envelopeout ofpatch_merge::Processor, patch_merge.rs:10-131) is fine and should stay; it is not the target here.
Unneeded options and configuration switches
1. patch_size / pooling_kernel_size are dead configuration that also add copies of 768 — should fix
Where it appears:
helios/proto/runtime_core.proto:535-542—Gemma4ImageSettings { uint32 patch_size = 1; uint32 pooling_kernel_size = 2; ... }.helios/src/frontend/images/mod.rs:334-341— the Rust struct,#[serde(deny_unknown_fields)], with the same two fields.ignition/preparation/frontend.py:113-137—_expected(...)rejects any checkpoint whosepatch_size/pooling_kernel_sizeis not exactly 16/3, then hard-codespatch_size=16, pooling_kernel_size=3in the returned dict.helios/src/frontend/images/gemma4.rs:23-44—load()validates them (!= 0,<= 64,<= 16) and stores them.
Why it is dead weight, not flexibility: the Python producer rejects every other value before the core is ever written (frontend.py:116-119), so no exported core can carry a different pair. Meanwhile nothing else derives from the fields consistently:
helios/src/frontend/images/gemma4.rs:116computespatch_features = 3 * self.patch_size * self.patch_size;helios/src/frontend/images/conditioned.rs:192hard-codesProfile::Gemma4(_) => 768for the "is this cached image still valid" check;helios/src/frontend/images/packing.rs:16-22mapspatches_per_feature == 9to width768for graph binding.
So there are three independent statements of the same number, and the only code that would notice a mismatch silently misbehaves: with a patch_size other than 16 (which load() accepts) valid_processed in conditioned.rs:185-194 is always false, so every cached Gemma 4 image is recomputed without an error.
Precedent in-tree: profile constants live in the module — helios/src/frontend/images/glm.rs:13 const FACTOR: usize = 28.
Smaller version:
- Drop
patch_sizeandpooling_kernel_sizefromGemma4ImageSettings(proto, Rust struct, serde) and from the Python return dict — proto field numbers 1 and 2 must bereservedrather than reused (AGENTS.md:441-443), and the message keepsmax_soft_tokens,image_token,start_token,end_token(tags 3-6 unchanged, so wire compatibility holds). - In
gemma4.rskeepconst PATCH: usize = 16; const POOLING: usize = 3; const FEATURES: usize = 3 * PATCH * PATCH;and useFEATURESinconditioned.rs:192andpacking.rs:19. - The validation block at
gemma4.rs:24-31then reduces to themax_soft_tokensallowlist (which is itself duplicated — see nit 4), and the unreachablepatch_size > 64/pooling > 16arms disappear.
Parallel paths and duplicated logic
2. prompt.rs back-fills data.spans that layouts already own — should fix
helios/src/model/prompt.rs:137-151:
if prepared.data.spans.is_empty()
&& config.contract.frontend.image_tokens.as_ref()
.and_then(|layout| layout.span.as_ref()).is_some()
{
prepared.data.spans = prepared.conditioned_inputs.iter()
.map(|input| input.token_span.clone()).collect();
}
This is the only span producer that is not in the layout. helios/src/frontend/images/layouts/deepseek.rs:149 already pushes start + padding..start + block.len() while it builds the expansion, so for Deepseek is_empty() is false and the new block never fires; for Bracketed/Gemma4 it fires. The result is a construct where the guard silently prefers one producer's answer over another instead of establishing that they agree, i.e. a second path where a single check would do.
Smaller version, in order of preference:
- Have
layouts/bracketed.rs::prepare_inputpushdata.spansnext to the expansion it computes — the conditioning/prompt path there is the natural owner — and delete lines 137-151 entirely. That puts Gemma 4's span production where the token expansion that produced it lives, and removes a model-shaped conditional from shared code. - If the shared location is kept, drop the
is_empty()preference and make overlap a defect: error unless exactly one producer filled spans, then letvalidate_prompt_data(helios/src/model.rs:436-452) keep checking them.
Either way the net deletion is the is_empty() branch; option 1 also deletes the shared block.
Tests that do not prove a behaviour
3. The envelope test shells out to Python for a template it never uses — should fix; also leaks a temp file
helios/src/frontend/images/gemma4.rs:236-332 (checkpoint_tokens_expand_the_image_envelope):
- requires
FLARE_GEMMA4_TEST_SNAPSHOTand bails silently (line 238-244); - then requires
../.venv/bin/pythonand bails silently (253-256); - writes
gemma4-template-<pid>.jinjainto the temp dir (257-258), runs a Python snippet importingignition.preparation.frontend.downloaded_template_asset(261-283), hashes the result into aFrontendAssets.chat_template(284-298), and callsremove_fileonly on the success path (299) — thereturnat 281-283 leaks the file.
The assertions at 311-331 exercise Envelope::expand via frontend.encode("Look <|image|> now", false). Chat-template rendering is never called anywhere in the test, and FrontendAssets.chat_template is Option<Asset> (helios/src/frontend/mod.rs:96-100), so the whole subprocess block is deletable: load tokenizer.json (not opened) + tokenizer_config.json (not opened), pass chat_template: None, keep the four assert_eq!s. The shared expansion itself is already covered end-to-end with a real rendered prompt, two images, feature order and start/end tokens by helios/src/frontend/images/layouts/bracketed.rs:104-180 — a test this PR makes apply to Gemma 4 too by moving both profiles onto Envelope.
If the reviewers want the envelope covered for the Gemma 4 checkpoint specifically, the reduced test is roughly:
let frontend = Frontend::load(FrontendAssets {
tokenizer: asset("tokenizer.json (not opened)"),
tokens: crate::frontend::test_support::tokens(&asset("tokenizer_config.json (not opened)")).unwrap(),
chat_template: None,
}, Default::default()).unwrap();
// ... then the existing asserts on expanded.token_ids / mm_token_type_ids
That deletes ~55 lines, one cross-language dependency, and one file-lifetime bug.
4. The checkpoint parity test depends on an unpinned local venv and proves nothing on CI — should fix
helios/src/frontend/images/gemma4.rs:334-415 (native_pixels_and_positions_match_the_checkpoint_processor):
if !python.is_file() { return; }(336-339) — on any machine without../.venv/bin/pythonthe test is a no-op that still reports as passed;- inside, it imports
transformers.models.gemma4.image_processing_gemma4.Gemma4ImageProcessor(340-354), so the numbers it compares against depend on whatevertransformershappens to be installed; - it also carries a hand-rolled binary stdout protocol (struct header at 351, offset arithmetic at 365-371 and 390-404) purely to get that data back.
This is the evidence behind the PR's headline claim ("exact f32 pixel and (x, y) position parity"), and AGENTS.md:194-199 requires tests that exercise the contract while keeping skips visible. Every other profile's parity evidence in this repository is a checked-in fixture: helios/src/frontend/images/glm.rs:147-199 reads tests/frontend/glm53_images.json (not opened) via include_str! and compares SHA-256 of resized bytes, pixels and positions; the generator lives at tests/frontend/generate_glm_image_fixtures.py (not opened). Qwen does the same (decoding_tests.rs with qwen38_images.json (not opened)).
Smaller and stronger version: add tests/frontend/gemma4_images.json (not opened) (width, height, grid, and hashes of resized, pixel_values LE bytes, position_ids LE bytes) plus a generator script, and reduce the test to the glm.rs shape — which also deletes the struct packing, the offset constants (pixel_offset = 32), and the two for loops of element-by-element comparison. Note the file also repeats the geometry expectations already asserted in geometry_matches_the_hugging_face_processor (197-216), so the fixture can carry geometry and the duplicate table can shrink.
Consequence to state in the PR description: with the current form, "45 passed" does not distinguish tests that ran from tests that silently returned.
Churn, redundant checks and duplicated constants (nits)
Nit 1 — redundant merge_side test. helios/src/frontend/images/packing.rs:486 checks h % merge_side != 0 || w % merge_side != 0, where merge_side comes from the same patches_per_feature as the adjacent identity at line 488. The only producer of these geometries is the Gemma 4 profile, which already guarantees the divisible grid: gemma4.rs:46-48 side_multiple() and geometry() floors both target sides to multiples of patch_size * pooling. bracketed_patch_geometry exists for that one check plus the width; if the shape check stays in the profile, packing.rs needs only geometry.tokens * patches_per_feature == patches and a const FEATURES width, and bracketed_patch_geometry's tuple return collapses to a width.
Nit 2 — unrelated reformatting. packing.rs:494-502 turns the previous one-line staging.put("vision_pixel_values", ...) into a six-line call with flat_map(f32::to_le_bytes); the actual change is 1176 -> patch_width. Under AGENTS.md:188-193 this is churn that makes the real one-token change harder to see. Keep the original line and change the constant.
Nit 3 — the new packing test only proves a table lookup. packing.rs:570-586 (bracketed_tensor_layout_derives_patch_width_from_patches_per_feature) asserts tensor_layout returns patches * 768 for patches_per_feature == 9 and errors on 16. The PR's claim is that bracketed() now handles 9; nothing tests bracketed() at 9 — not the tokens * ppf == patches identity, not the truncated-pixel error at 498, not the 47-row rejection. A bracketed(...) test with grid_thw [1, 48, 48] (2304 patches, 256 tokens) and a rejected odd grid would prove the behaviour; the current test proves an integer literal.
Nit 4 — the soft-token allowlist is written twice. helios/src/frontend/images/gemma4.rs:11 SUPPORTED_SOFT_TOKENS = [70, 140, 280, 560, 1120] and ignition/preparation/frontend.py:123 if image.get("max_soft_tokens") not in (70, 140, 280, 560, 1120). Nothing else in the profile branches on the value — geometry derives everything from it through max_patches() (gemma4.rs:50-52). Either keep the producer check and let Rust accept any positive value, or drop both and let the budget check at gemma4.rs:77-81 be the guard. The Rust copy cannot be exercised once the Python producer rejects other values first, so it is the one to delete.
Checked and fine (no finding)
Envelopeextraction inhelios/src/frontend/images/patch_merge.rs:10-81is real de-duplication:patch_merge.rs:123-131andgemma4.rs:160-167now share oneexpand. KeepingProcessoras a thin wrapper (83-131) is right — callers inmod.rsare untouched.- The additive proto tag (
ImageSettings.gemma4 = 11, runtime_core.proto:522), thedescribe.rs/protobuf.rsarms andImagePreparationKind::Gemma4 = 11are the minimum required forAGENTS.md:431-444, not bloat. ignition/preparation/runtime_core_pb2.py:1-30is generated; the diff reverts the header to "Protobuf Python Version 7.36.1" while main says 7.36.2. Not a functional defect; flagging only so the next regeneration does not churn it back.gemma4.rs:135-152raster loop and* (1.0/255.0)scaling are the checkpoint layout; no simpler in-tree form.gemma4.rs:95-101resized_rgbhas no non-test caller for this profile, but every other profile implements it andmod.rsdispatches on it (theglm.rsfixture test uses the same hook), so keeping it is consistency rather than bloat.
Open questions / not verifiable from the code
- Whether
bracketed_patch_geometry's(2, 1176)branch still has any producer: the PatchMerge path (layout=bracketed,patches_per_feature = 4) appears to be exercised only by the Minimax test inlayouts/bracketed.rs:104-180. If no exported core uses it, the 4/branch and its 1176 are deletable too — that needs a check againstlocal-inference-lab/hyperflare-recipes, which is outside this repository. - Whether the removed temp-file cleanup and the silent skips show up in CI is not something the diff can settle; no CI checks are reported on
f2340e4. - I did not review the resize numerics or the packing arithmetic for correctness (other lenses); nothing above depends on them.