Review of PR #483 — Gemma 4 image preparation, Bracketed patch-width metadata, atomic spans
Lens B: architecture & scope. Reviewed at head 2b4a31e against main 27716185. This supersedes my earlier 2026-11-24 report (written against the pre-rebase head).
Note on diff scope: the raw head diff also shows a large amount of unrelated base-branch churn (banner removal, flare doctor, parallax, download rewrites, RebuildManifest→PreparationManifest). Those are commits that landed on main between the old base and now, not this PR's files — pr_files against the merge base lists only the 36 files in the orientation packet. Not reported.
Key findings
Verdict: should-fix issues only. No blocking findings.
Every blocker and should-fix from my previous review is fixed at head 2b4a31e, verified in code:
- The
patches_per_feature → widthmodel-identity table is gone from shared packing. gemma4::Processor::loadnow enforces the packing contract (pooling² ==patches_per_feature, patch budget).- Patch width is authored once behind
ImageProcessor::patch_features(), with an 11-profile consistency test. - Atomic spans moved out of
prompt.rsintolayouts::bracketed, gated on the contract'sImageSpan, with markers validated. - The maximum-envelope vs
prefill_chunk_size/span.max_tokenscheck moved to bootstrap, with 64-aligned boundary tests. - Ignition no longer pins one vision tower and reads envelope tokens from the tokenizer.
- Docs and
TODO.txtupdated. My earlierruntime_core_pb2.pyversion concern was wrong and is withdrawn:main's own file already declares7.36.1.
Three should-fix items remain, all about the writer side of layering and about CI evidence, plus one evidence nit.
Everything from my previous review is fixed
Blocker 1 (model-identity table in shared packing) — fixed
The 4 => 1176, 9 => 768 match is gone. helios/src/frontend/images/packing.rs:16-24:
const LEGACY_BRACKETED_PATCH_FEATURES: usize = 1176;
pub(crate) fn bracketed_patch_features(vision: &VisionCapabilities) -> usize {
if vision.patch_features != 0 { vision.patch_features } else { LEGACY_BRACKETED_PATCH_FEATURES }
}
and packing.rs:26-32 square_merge_side derives the merge stride from patches_per_feature.isqrt() with a square check. Patch width is now prepared metadata rather than something inferred from a merge count, which is the right split. tensor_layout threads &VisionCapabilities (packing.rs:34-39, used at :49-56) from its one caller model/packing.rs:92-97.
Blocker 2 (parity tests passing by skip) — fixed
tests/frontend/generate_gemma4_image_fixtures.py + the checked-in tests/frontend/gemma4_images.json (8 cases across max_soft_tokens 280 and 1120) are consumed unconditionally by gemma4.rs:266-333 under plain cargo test. The live-checkpoint tests are now #[ignore]d with explicit assertions rather than early returns. (Residual evidence gap: should-fix 3 below.)
Blocker 3 (spans emitted in shared code) — fixed
The prompt.rs fallback block is deleted; layouts/bracketed.rs:52-107 emits spans, gated on atomic_spans and rejecting missing envelope markers at either end (bracketed.rs:57-65). Tests at helios/src/model/prompt.rs:1171-1284 cover span-bearing (2 spans, len 262, marker ids), a 64-aligned chunk that is too small (256 vs 262 rejected), and no-span MiniMax (empty spans). Shape comment: should-fix 2.
Should-fix: Processor::load vs. the packing contract — fixed
gemma4.rs:25-52 rejects pooling_area != Some(limits.patches_per_feature), max_patches > limits.max_patches_per_image, plus patch_size/pooling/max_soft_tokens bounds, with checked_mul and Option composition so overflow cannot silently pass. Negative tests at gemma4.rs:219-264 (patches_per_feature 4, budget 2519, unsupported soft token count).
Should-fix: patch width authored three times — fixed
ImageProcessor::patch_features() (frontend/images/mod.rs:459-474) covers all 11 profiles; conditioned.rs:187 now calls it instead of a private match, which also fixes the cache validation for PaddedGrid (1200) and PatchMerge (1176). PatchMerge derives 3*2*14*14 (patch_merge.rs:124-126), PaddedGrid uses padded_grid::FEATURES. Cross-profile test at packing.rs:690-826 asserts processor.patch_features() == tensor_layout(...).1 for 11 profile/layout pairs.
Should-fix: 1,120-soft-token envelope vs. prefill_chunk_size — fixed
server/config.rs:443-490 validate_loaded_image_processor now, at bootstrap (server/config.rs:290-298):
- checks
processor.patch_features()againstvision.patch_features(:448-455); - for
Bracketed, checks it againstbracketed_patch_features(vision)and emits the actionable "re-export the core with vision.patch_features" error (:456-464); - rejects
max_image_envelope_tokens > prefill_chunk_sizeand> span.max_tokens(:465-488).
Boundary tests at server/config.rs:985-1023: 1122 fits in 1152, fails at 1088; span.max_tokens 1121 fails, 1122 passes. This is the correct layer — load time, not per request.
Should-fix: Ignition pinned one vision tower — fixed
ignition/preparation/frontend.py:114-173 now asserts only model_type, vision_config.model_type, patch_size, pooling_kernel_size, the processor flags, and max_soft_tokens; the 27-layer/1152-hidden/16-head/72-dim/4304-FFN block is gone. Envelope tokens are read from tokenizer_config.json (not opened) (image_token/boi_token/eoi_token), validated to encode as exactly one token against tokenizer.json (not opened), and cross-checked against optional config.json (not opened) ids. gemma4_unified is rejected on all three surfaces. Covered by tests/preparation/test_frontend_gemma4.py with E2B-sized synthetic towers plus three cached checkpoints.
Should-fix: stale docs — fixed
helios/README.md:706-717 (Gemma 4 in the profile list, processor described), docs/runtime-core-design.md:184-194 (not opened) (patch_features and the bootstrap cross-check), helios/model-contract.md:82 (field documented), docs/TODO.txt:330-337 (recipe wiring, E2B/E4B/26B-A4B/31B qualification, partial-span prefix-cache audit).
Withdrawn: runtime_core_pb2.py version
main's own runtime_core_pb2.py:5,16 already declares 7.36.1 / 1, and the PR's file declares the same. pyproject.toml:34 (not opened) (protobuf>=7.36.2) bounds the runtime, not the generator's emitted header. My earlier concern was wrong; the diff is descriptor-only plus the two new fields.
Should fix
1. Ignition's contract helper cannot author the new field — ignition/preparation/contract.py:112
vision={"feature_slots": 0, **(vision or dict(features_per_request=0, max_images=0, patches_per_feature=0, patch_capacities=[]))},
The default vision dict carries the historical four keys and not patch_features, the only field that conveys the Bracketed patch width added by this PR (helios/proto/runtime_core.proto, VisionCapacity.patch_features, tag 6). A Gemma 4 recipe that fills in the four historical keys exports patch_features = 0; bracketed_patch_features (frontend/images/packing.rs:18-24) reads that as the legacy 1176; and server/config.rs:456-464 then rejects the core at flare run with "bracketed image layout patch width (1176) differs from image processor (768); re-export the core with vision.patch_features".
Why it matters: the PR made the Rust side of Bracketed model-agnostic (correct), but left the Python authoring surface that must declare the width unchanged. The first feedback a recipe author gets is a serve-time error, and the only other hint is a docs/TODO.txt line. That is "right problem, wrong layer" on the writer side.
Fix: add patch_features=0 to the default dict at contract.py:112 and note in the docstring that Bracketed vision cores must set it. Compatibility is otherwise intact: MiniMax keeps loading because PatchMerge::patch_features() is 3*2*14*14 = 1176 and max_image_envelope_tokens() is None for non-Gemma 4 profiles, so the new envelope bound does not apply.
2. atomic_spans: bool is derived contract state threaded into the layout — layouts/bracketed.rs:23, model/prompt.rs:52-65
prompt.rs:58-64 computes .image_tokens.as_ref().and_then(|layout| layout.span.as_ref()).is_some() and passes the resulting bool down to layouts::bracketed::prepare_input, which stores it as a field-shaped parameter used only at bracketed.rs:58.
Why it matters: layouts::deepseek needs no such flag — it always populates data.spans (deepseek.rs:149) because validate_prompt_data already rejects non-empty spans when the contract declares no ImageSpan (helios/src/model.rs:457-458: } else if !data.spans.is_empty() { return Err("image layout does not declare atomic spans") }). So the flag is not needed for correctness; it duplicates contract state one layer away from where it already lives, and it makes the "span is missing envelope markers" check (bracketed.rs:57-65) conditional on caller-supplied input rather than on the contract.
Fix: drop the parameter; populate spans unconditionally as Deepseek does and let model.rs:457-458 be the gate. That returns prompt.rs to the same one-line-per-layout shape as every other arm (prompt.rs:66-88).
3. The checked-in fixture pins pixels only; its model/token block is dead data — tests/frontend/gemma4_images.json, gemma4.rs:266-333
generate_gemma4_image_fixtures.py:82-86 writes three top-level blocks:
profile = {key: model[key] for key in ("vision_config", "model_type", "image_token_id", "boi_token_id", "eoi_token_id") if key in model}
output.write_text(json.dumps(dict(processor=raw, model=profile, cases=cases), indent=2) + "\n")
but the only consumer in the tree (gemma4.rs:270, the sole gemma4_images.json reference) iterates fixture["cases"] (:273) and reads width, height, seed, max_soft_tokens, grid, tokens, patches, resized, pixels, positions. Neither processor nor model is ever read.
Why it matters: the fixture therefore pins resize/pixel/position parity only. Envelope and token behaviour — the start_token/image_token/end_token chain the PR's "atomic image envelope" claim rests on — is exercised exclusively by #[ignore]d tests (gemma4.rs:375-451) and by tests/preparation/test_frontend_gemma4.py, whose checkpoint cases pytest.skip without HF_HOME. On a clean CI node, the claim of parity against more than one checkpoint has no executed evidence, which is exactly the evidence standard the charter asks for ("Supported matrix & compatibility … verify that existing data, artifacts, and exported cores still load"). Dead data in a checked-in fixture also drifts silently.
Fix: consume the model block in Rust — assert the configured envelope token strings map to the recorded image_token_id/boi_token_id/eoi_token_id, and that processor round-trips into Gemma4ImageSettings — or delete the two blocks so the fixture states only what is checked. Either way, say in the description that the live-checkpoint runs are not part of CI.
Nit / evidence gap
4. The positive-square Bracketed narrowing is enforced at model load, not per request
square_merge_side is now called from tensor_layout (frontend/images/packing.rs:49-56), which model/packing.rs:92-102 runs while binding any core whose graph takes vision_pixel_values. So a Bracketed core with a non-square patches_per_feature fails to load, even if it never serves an image. That is the right place given "existing data, artifacts, and exported cores still load", but the description frames the impact as a load-path change for MiniMax specifically; it should state that the narrowing is load-time and applies to any Bracketed core. Whether any published Bracketed core is affected cannot be settled from this repository: the recipe manifests live in local-inference-lab/hyperflare-recipes. Checking that repo's MiniMax vision vision.patches_per_feature would settle it.
Scope: does this change belong in the repository?
Yes, on both halves of the lens.
- Extension point, not a new mechanism.
helios/src/frontend/images/already owns nine preparation profiles;Gemma4goes in behind the existingImageSettingsenum (frontend/images/mod.rs:257-260, 389). The proto addition is additive and optional (VisionCapacity.patch_features,#[serde(default)],0= legacy). Decode is one arm (runtime_core/protobuf.rs:168-172), describe is one arm (runtime_core/describe.rs:451-453) and omits the field when 0 (:465-468). That matches "keep the runtime small and model-agnostic" rather than adding a per-model branch in the runtime. - Layers kept in role. Image decode/resize/pack stays in the frontend, contract validation at load in
server::config, span semantics in the layout (as Deepseek already did), prompt validation inmodel. TheEnvelopeextraction out ofpatch_merge::Processor(patch_merge.rs:10-31, 84-136) is genuine de-duplication with no behaviour change for MiniMax: token-uniqueness validation moved verbatim andexpand_promptdelegates. - No performance claim is made. The description explicitly says no serving-path timing or memory was measured; the evidence is unit-, fixture-, and preparation-level. The "#210 benchmarks" rule is therefore not engaged, and the PR does not overstate it — the limitation is stated in the description and tracked in
docs/TODO.txt:330-337. - Compatibility. Missing
patch_featuresdecodes as 0 → legacy 1176 forBracketed; the envelope bound applies only to profiles exposingmax_image_envelope_tokens(Gemma 4). Existing span-declaring layouts (Deepseek,DeepseekRowMajor) keep emitting their own spans. The one real narrowing is the positive-square requirement in nit 4.
What I checked and found clean
- Overflow/edge handling in
gemma4.rs:checked_mulforpatch_features(line 55),try_foldfor patch totals,pooling_area/max_patchesasOptionso overflow fails closed rather than wrapping. VisionCapabilities::validate()accepts 0 (legacy) and rejects nonzero non-multiples-of-3 widths (model.rs:72-92).tensor_layoutoverflow-checks the Bracketed extent (packing.rs:52-54).- The protobuf round-trip test (
protobuf.rs:812-866) confirms tag 11 selects only image preparation, i.e. the new profile does not perturb other settings. bracketed()rejects any grid not divisible by the derived merge side and any token/patch mismatch (packing.rs:494-517).layouts/bracketed.rs:89-93cross-checks that the incremented image and feature counters match the processed geometry before returning, so a malformed expansion errors rather than under-populatingvision_token_indices.
Open questions / could not verify
- Whether any published Bracketed core (MiniMax vision, or a companion Gemma 4 recipe) has a non-square
patches_per_feature, or omitspatch_featuresoutright — the manifests are inlocal-inference-lab/hyperflare-recipes, outside this repository. This is what would settle the blast radius of nit 4 and the severity of should-fix 1. - Serving-path behaviour (memory and throughput of 1,120-token image envelopes, partial-span prefix caching) is out of scope for this PR by its own description and is tracked in
docs/TODO.txt:330-337; I did not attempt to measure it. - No test in this repository can settle whether an existing exported Gemma 4 core declares
patch_features; only re-running the exporter over a real recipe would. The description already treats such cores as rejected with an actionable error, which I consider the correct trade.