Review — PR #483 "Add Gemma 4 image preparation, Bracketed patch-width metadata, and atomic spans"
Head ab9a432b (branch rickybrent:core/gemma4-image-frontend) → main 27716185, 38 files, +2490/−251. Round 4; supersedes the round-3 review of 2b4a31e.
Verdict: no blockers. Every should-fix from the previous round is fixed and verified in code (list below). What remains is one scope/evidence question that needs a maintainer answer, three small code/test items, and ten nits. This is a read-only review: I re-read every cited site, but ran no cargo test, cargo check or pytest, and the head commit reports no CI checks, so every behavioural claim below comes from code and callers. The author's reported test counts are not relied on anywhere in this report.
Key findings
- No blocking issues. The wire additions are additive and defaulted, existing
Bracketedcores still load, and the span path is inert for layouts that do not declareimage_tokens.span. - Four should-fix items, all small and none on the served path: the profile still lands ahead of its exporter with nothing mounting it end to end; the documented default processor path does not exist for Gemma 4 snapshots; only 2 of 5 allowlisted soft-token budgets are loaded; and the new legacy-core test duplicates the shared manifest builder.
- Ten nits: the per-profile patch width is still authored over two enums, repeated test rows and a ten-row profile table, a duplicated cross-language allowlist, a doubled
max_patches, range validation where neighbours pin one value,Envelopehomed in a profile module, theatomic_spansbool shape, an over-broad% 3rule, an untested sub-envelope prefill path, and two documentation/wording fixes.
Verified resolved this round — do not re-litigate
- Per-condition load errors naming field and both values.
helios/src/frontend/images/gemma4.rs:25-84: patch_size:27-33, pooling:34-40, soft tokens:41-47, pooling area vspatches_per_feature:52-60, patch budget:61-71, with the1..=64/1..=16caps commented as defensive wire caps at:26. - One patch-width authority.
gemma4.rs:86-88patch_features()is the single expression, used at:164for capacity and reserve; the count→width lookup table is gone frompacking.rs. - Ignition authors the field.
ignition/preparation/contract.py:109-119puts"patch_features": 0in the vision default with a docstring (:111-115) telling aBracketedrecipe with a non-1176 width to set it. - Legacy
Bracketedcore-load test added and does what was asked.helios/src/model/tests.rs:1279-1452: serializes aBracketedcontract, removespatch_featuresfrom the JSON (:1334-1338), asserts decode is0, loads throughInputs::new(:1414-1415), stages16 * 1176floats (:1438-1443), and rejects a 768-wide manifest (:1446) and a non-squarepatches_per_feature(:1447-1451). - Fixture provenance is consumed, not dead data.
tests/preparation/test_frontend_gemma4.py:187-225reads theprocessorandmodelblocks oftests/frontend/gemma4_images.json(not opened) and asserts the resolved settings (patch 16 / pooling 3 / 280), including the three recorded token ids. - Duplicate bootstrap width check folded into one
Bracketedbranch.helios/src/server/config.rs:449-463, usingVisionCapabilities::bracketed_patch_features()(helios/src/model.rs:74-80) rather than reaching into packing. - Superseded
#[ignore]d test deleted, and the remaining ignored test's temp chat template isDrop-guarded (gemma4.rs:422-424marks the ignore reason; template dropped at:469;gemma4.rsis 505 lines). - Docs:
helios/README.md:721-724now scopes the[N,1536]/ temporal-copy / 2×2 text to Qwen and points per-profile width atImageProcessor::patch_features();:798-807documents the Gemma 4 fixture with pinned Transformers 5.23.0 / PyTorch 2.14.1+cu132 / Torchvision 0.29.1+cu132 and revision842da379…;:713-719the Gemma 4 paragraph;docs/runtime-core-design.md:181-194 (not opened),234-242;helios/model-contract.md:82(not opened);docs/TODO.txt:330-337. runtime_core_pb2.py(not opened) remains descriptor-only and consistent withmain's generator header — that earlier concern stays withdrawn.
Blockers
None. Nothing in this change is incorrect on the served path, no existing core stops loading, and no compatibility guarantee is broken. The items below are gaps in coverage, one authoring default, and cleanup.
Should Fix
S1 — The profile lands ahead of the exporter that can use it, and nothing mounts it end to end
Finding. End-to-end serving is deferred to an unlanded companion PR in local-inference-lab/hyperflare-recipes, and docs/TODO.txt:330-337 records the qualification (E2B/E4B/26B-A4B/31B export and serving, plus the partial-span prefix-cache audit) as open. No prepared contract exercises the profile: helios/tests/support/contracts/gemma4_frontend.json:16-17 (not opened),38 declares image_preparation: null, image_layout: null, image_tokens: null, and no contract JSON under helios/tests/support/contracts/ uses layout 9 (Bracketed) or preparation 11 — the layouts in use are 1, 2, 3, 5, 6, 10 (qwen38.json:38-39 (not opened), mimo_v2.json:38-39 (not opened), deepseek4.json:36-37 (not opened), step5_frontend.json:16-17 (not opened), nemotron_h_frontend.json:16-17 (not opened), inkling2_frontend.json:52-53 (not opened)). Gemma 4 is covered only by Rust-constructed configs (helios/src/model/prompt.rs:1171-1284, helios/src/server/config.rs:935-1023, frontend/images/gemma4.rs) and by Ignition-side tests (ignition/preparation/frontend.py:114-173, tests/preparation/test_frontend_gemma4.py), none of which goes Bootstrap::load (server/config.rs:290-298) → validate_loaded_image_processor → a served image request.
Request. Either state in the description that a maintainer approved landing the profile ahead of its recipe (the author's stack-order argument — recipes were extracted, so the core profile must land first — is plausible and needs one line of confirmation), or split the shared half (the patch_features field, contract-driven Bracketed packing, Bracketed spans, envelope bounds) onto its own PR, since it stands alone and fixes a defect on main. Either way, add one contract fixture shaped like qwen38.json (not opened) with image_layout: 9, image_preparation: 11, a declared image_tokens.span, and vision { patches_per_feature: 9, patch_features: 768 }, loaded through the same helper the other fixtures use. Otherwise say plainly in the description that Gemma 4 serving is unqualified.
Why. The charter makes export-and-serve the bar for a new format ("prove they export and serve cleanly from the PR branch, and support more than a single checkpoint") and separately requires that existing cores still load. The compatibility half is now genuinely tested; the export/serve half is prose. The author's limitations paragraph covers unmeasured timing and memory but not that the profile has never been served. Also note the head commit reports no CI checks, so even the unit evidence has not run in CI.
S2 — The Gemma 4 processor file is not where the default path looks
Finding. ignition/preparation/frontend.py:310 resolves the processor as snapshot / "preprocessor_config.json (not opened)" when preprocessor is None, then feeds that JSON to image_settings (:311-314). Gemma 4 snapshots ship processor_config.json (not opened): the fixture generator reads snapshot / "processor_config.json (not opened)" (tests/frontend/generate_gemma4_image_fixtures.py:28), the padded_grid doc at frontend.py:100 already records the same split, and every test passes the path explicitly (tests/preparation/test_frontend_gemma4.py:88,246). So the documented call shape prepare_frontend(snapshot, eos_token_ids=[…], image_profile="gemma4") raises FileNotFoundError, and no test covers the default argument, so CI cannot catch it. Pre-existing for padded_grid too, so this is consistency plus a missing test rather than a new defect.
Request. Resolve the processor path per profile (try processor_config.json (not opened) for gemma4/padded_grid, or accept whichever of the two exists), or make preprocessor required for those profiles and document it; add one test that calls prepare_frontend without preprocessor against a snapshot holding processor_config.json (not opened).
Why. The first recipe author to follow the documented shape gets a FileNotFoundError instead of a prepared contract, and the failure is invisible to CI.
S3 — Only two of the five allowlisted soft-token budgets are ever loaded
Finding. helios/src/frontend/images/gemma4.rs:13 accepts [70, 140, 280, 560, 1120] and ignition/preparation/frontend.py:132 accepts the same five, but the fixture generator's specs are only 280 and 1120 (tests/frontend/generate_gemma4_image_fixtures.py:31-40), so processor_with_budget is only ever constructed at 280 (gemma4.rs:246-248) and 1120. max_soft_tokens drives max_patches() (gemma4.rs:98-100), the target pixel budget (:106), the aspect-clamp branches (:113-124) and max_envelope_tokens() (:90-92), which feeds the new load-time bound against prefill_chunk_size and span.max_tokens (server/config.rs:464-487). The clamp branches at :118-123 (one dimension rounding to zero) are exactly the edge that behaves differently at a small budget, and 70 is the value the checkpoint's own video_processor declares in the fixture's provenance block.
Request. Add (91, 37, 70), (10, 3000, 140) and one 560 case to the generator specs and regenerate, or add a table test that constructs a processor for each SUPPORTED_SOFT_TOKENS entry and asserts geometry for one fixed shape.
Why. A budget-specific geometry or parity defect would first appear at flare run on a real checkpoint rather than in cargo test. This also closes the cross-language drift risk on the allowlist at no extra cost.
S4 — The new legacy-core test hand-builds a manifest the shared builder could emit
Finding. helios/src/model/tests.rs:1343-1411 is a 68-line local build_manifest closure that repeats the descriptor/stride/address walk of helios/src/model/testing.rs:307-337 and the binding assembly of :369-377, plus nine hand-written ValueBindings at tests.rs:1304-1332. It exists because testing::manifest sends GraphOperation::Vision to _ => unreachable!() (testing.rs:344-355, the _ arm at :354) and fixes image tensor widths to 1 (testing.rs:257, _ => 1), so a vision graph cannot be described. Line tests.rs:1450 then rebuilds a manifest it already holds (base_manifest = build_manifest(1176); immediately before use).
Request. Add GraphOperation::Vision => GraphKind::Vision at testing.rs:344-355 and let the width for vision_pixel_values come from vision.bracketed_patch_features(); the test then overrides one buffer extent to (16, pixel_width), and the local closure, the hand-written bindings and the :1450 rebuild all disappear.
Why. Roughly 110 lines of duplicated manifest arithmetic is a second source of truth for graph layout; when ExecutionManifest changes, this test breaks for reasons unrelated to the behaviour it checks (a legacy core without patch_features loads and stages 1176-wide pixels).
Nits
- Per-profile patch width is still authored twice, over two different enums.
helios/src/frontend/images/packing.rs:32-49mapsImageLayoutKind→ float width (Qwen|Mimo → 1536,Deepseek*|Moonvit|Step → 588,Bracketed → vision.bracketed_patch_features(),Radio → 768,Glm → 1176,ClassToken → 1200), whilehelios/src/frontend/images/mod.rs:459-471(ImageProcessor::patch_features) mapsProfile→ the same numbers. They are linked only by the test atpacking.rs:685-814. Fix: pass the processor width intotensor_layoutfromInputs::new(helios/src/model/packing.rs(not opened)), soProfilestays the single authoring point. - Duplicated test rows.
helios/src/frontend/images/gemma4.rs:386-396lists nine geometry rows, but seven are already pinned by grid/tokens/patches/resize/pixels/positions SHA-256 incanonical_processor_pixels_positions_and_resize(:314-381) againsttests/frontend/gemma4_images.json(not opened); only(100,3000)and(3000,100)(:392-393) are unique.pixels_interleave_rgb_and_positions_are_xy(:404-420) restates the 91×37 fixture case by hand. Fix: keep the two tall/wide rows plus thetokens * 9 == patchesinvariant (:400) and the(x, y)ordering assertions at:415-418, which the hashes cannot express; delete the rest. packing.rs:685-814is ~130 lines for four distinct outcomes.processor_patch_features_match_tensor_layout_for_every_profilerepeatspatch_features: 0ten times. Fix: four rows (Gemma 4 9/768, PatchMerge 4→1176, PaddedGrid 1200, one of 588/1536) cover every distinct path.- The soft-token allowlist exists twice, in two languages, with nothing tying them.
helios/src/frontend/images/gemma4.rs:13SUPPORTED_SOFT_TOKENSandignition/preparation/frontend.py:132max_soft_tokens not in (70, 140, 280, 560, 1120). The Rust comment (gemma4.rs:11-12) argues the duplication is deliberate defence in depth, which is legitimate, but no test asserts the sets agree. Fix: cross-reference both sites in comments and add the table test in S3, or carry the allowed set in the prepared settings so Helios validates metadata instead of a literal. max_patchesis computed twice ingemma4.rs. Checked at:61-64(checked_mul, load-time bound) and unchecked at:98-100(fn max_patches) forgeometry(:104,:139). Fix: haveloadcallmax_patches()on the constructed value, or store the computed budget, so there is one expression.- Validation style departs from its closest precedents.
helios/src/frontend/images/patch_merge.rs:92pinssettings.patch_size != 14andqwen.rs:22(not opened) pinsposition_side != 48, whilegemma4.rs:27-40accepts ranges (1..=64,1..=16) that no producer can emit (frontend.py:124-127,140-141require 16 and 3;:168-173emits them as literals). The caps are documented as defensive at:26, so this is tolerable. Fix: pin 16 and 3, or state in the comment that Ignition is the sole author of those values. Envelopeis a shared frontend construct homed in a single profile module.helios/src/frontend/images/patch_merge.rs:10-17declarespub(super) struct Envelopedocumented as "shared byPatchMergeandGemma4", andgemma4.rs:8imports it viause super::patch_merge::Envelope;. Fix: move it tofrontend/images/envelope.rs(not opened) (or besideImageGeometryinmod.rs); the extraction itself is genuine de-duplication and MiniMax semantics are unchanged (token-uniqueness validation moved verbatim,expand_promptdelegates).atomic_spans: boolshould beOption<&ImageSpan>. Derived athelios/src/model/prompt.rs:52-65, consumed atlayouts/bracketed.rs:23,58, and tests pass barefalse(bracketed.rs:175,199). The gate itself is correct and must stay:helios/src/model.rs:467-469rejects non-empty spans when the contract declares noImageSpan, and MiniMaxBracketedcores declare none (helios/src/model/prompt.rs:478-484setsspan: Nonefor every non-Deepseek layout), so unconditional emission would break existing cores. Fix: pass the preparedOption<&ImageSpan>so the derivation sits with its use, asclass_tokenreceives its token.% 3is enforced on cores that never consume the field, and reported generically.helios/src/model.rs:89rejects any vision core whosepatch_featuresis not a multiple of three, but the value is only read throughbracketed_patch_features()(model.rs:74-80, used fromfrontend/images/packing.rs:40-41and the bracketed arm). The failure surfaces as the generic"invalid prepared vision capabilities"(:99). Fix: scope the rule toImageLayoutKind::Bracketedor name the field and both values in the error.- An untested invariant and two doc/wording fixes. (a)
helios/src/scheduler/policy.rs:343-350truncatesendback tospan.startwhen the computed end falls strictly inside a span, so any captured prefill capacity smaller than the envelope contributes no work for a span-bearing image request; the new bootstrap bound (server/config.rs:464-479) makes that unreachable when the captured capacity equalsprefill_chunk_size, but no test pins the relationship — one sub-envelope capacity case would. (b)helios/README.md:806regenerates the Gemma 4 fixture with"$SNAPSHOT", whose only prior definition is the Qwen3.8 command at:787-789pointing at a different checkpoint — useGEMMA4_SNAPSHOTor name the directory at:798-802. (c) The description's "decodes, resizes, normalizes, packs, and validates" overstates: the profile rescales by1/255only (gemma4.rs:192-196;frontend.py:124-127requiresdo_normalize: False,image_mean0,image_std1), ashelios/README.md:716correctly says — change to "rescales by 1/255".
Accepted as-is — do not re-raise
Gemma4ImageSettings.patch_size/pooling_kernel_sizestaying on the wire (helios/proto/runtime_core.proto(not opened),helios/src/frontend/images/mod.rs:332-341). The author's reasoning holds:PatchMergeImageSettings.patch_sizeis likewise pinned (patch_merge.rs:92), the caps are documented as wire-level defence in depth (gemma4.rs:26), and removing the fields pre-merge would churn downstream recipe tests. The residual ask is only the cross-reference in nit 4 and the table test in S3.- Leaving patch-width authoring to the recipe rather than deriving it inside
contract.py.ignition/preparation/contract.py:109-119now documents the key, so the earlier complaint (no authoring surface at all) is fixed, and the residual failure mode is one actionable load-time error, not a silent wrong result:server/config.rs:451-455prints "bracketed image layout patch width (1176) differs from image processor (768); re-export the core with vision.patch_features". - The fixture generator copying
pattern/digestverbatim fromtests/frontend/generate_glm_image_fixtures.py:18-25(not opened) (generate_gemma4_image_fixtures.py:17-24). Every generator intests/frontend/is deliberately standalone; revisit only if a third copy appears. - Two previously raised items are resolved and must not be re-raised: the duplicate bootstrap width check (now one
Bracketedbranch,server/config.rs:449-463) and reaching into packing for the width (nowVisionCapabilities::bracketed_patch_features(),model.rs:74-80). The earlierpacking.rsnit abouth % merge_side != 0 || w % merge_side != 0is withdrawn: it is not implied bytokens * patches_per_feature == patches(h=2, w=9, ppf=9 satisfies the identity but is not a 3×3 tiling), and the author's rebuttal is correct.
Checked and clean
- Additive wire format.
ImagePreparationKind::Gemma4 = 11appended bycontract_enum!without renumbering (helios/src/model/contract.rs:68(not opened)),ImageSettingstag 11,VisionCapacity.patch_featurestag 6 with#[serde(default)](helios/build.rs:53-56(not opened)), describe omitting 0 so legacy JSON is byte-identical (helios/src/runtime_core/describe.rs:466-468(not opened)), decode arm (protobuf.rs:168-172(not opened)), and a round-trip test (protobuf.rs:813-866(not opened)). - Legacy width fallback.
VisionCapabilities::bracketed_patch_features()maps0 → 1176(model.rs:72-80);validate()accepts 0 and rejects non-multiples of 3 (model.rs:82-102). - Envelope bounds at bootstrap, where they belong.
server/config.rs:464-487checks bothprefill_chunk_sizeandspan.max_tokens;max_image_envelope_tokens()returnsSomeonly forProfile::Gemma4(frontend/images/mod.rs:473-478), so no other core is newly rejected. - Load-path narrowing is disclosed and mount-tested.
square_merge_side(packing.rs:16-22) now rejects a non-square nonzeropatches_per_featureat core load;helios/src/model/tests.rs:1447-1451covers it.patches_per_feature == 0was already rejected earlier in validation (model.rs:88). - Packing guard is genuinely necessary.
bracketed()rejects grids not divisible by the derived merge side and any token/patch mismatch (packing.rsbracketed arm,:491-497); divisibility is not implied bytokens * patches_per_feature == patches. - Overflow guards.
checked_mul(gemma4.rs:48-51,61-64),try_fold(:157-162),check_batchbefore and after geometry (:152,:163). - Layout-owned spans validated at both ends.
layouts/bracketed.rs:57-65,86-93, including the image/feature counter cross-check, andvalidate_conditioned_inputs(model/prompt.rs:153-191) still enforces per-span feature ownership, so new spans cannot smuggle cross-span features. Envelopeextraction preserves MiniMax semantics (patch_merge.rs:10-136).- Mechanical call sites:
client/server/scheduler changes arepatch_features: 0struct fills (flare-cli/tests/unverified_payload.rs(not opened),helios/tests/deepseek_requests.rs(not opened),helios/src/server/{models,protocol/decode,request,runtime}.rs,helios/src/scheduler/*).
Open questions / could not establish
- Does any published
Bracketedcore declare a non-squarepatches_per_featureor omitpatch_features? Such a core would now fail to load. The manifests live inlocal-inference-lab/hyperflare-recipes, outside this repository; a sweep there settles the blast radius. - Was landing the profile ahead of its recipe approved by a maintainer? The author's stack-order reasoning is plausible, but only a maintainer can confirm, and the charter makes that approval the gate (S1).
- Should a prefix-cache endpoint restored mid-envelope fail the request or back off to the envelope boundary?
docs/TODO.txtrecords the audit;scheduler/checkpoints.rs(not opened) keeps published endpoints span-aligned today, so the in-process path is safe, but nothing pins it (nit 10a). - Verification limits. Read-only review: no build or test run, and no CI checks on the head commit. The live-checkpoint paths (
FLARE_GEMMA4_TEST_SNAPSHOT,.venv, cached HF snapshots) are outside CI by construction, and the cached-checkpoint pytest cases skip unless the snapshot is present. Serving-path timing and memory were not measured by the author either, and the description says so, so no performance claim is at issue. - Diff scope note. The head diff also carries unrelated base-branch churn (banner removal,
flare doctor,parallax, download rewrites,RebuildManifest→PreparationManifest) that landed onmainin the interim. It is not this PR's files and is not attributed to the author.