Review of PR #483 — conventions and duplication
Verdict: should-fix issues only. The proto/serde/describe/Python plumbing follows its per-profile precedents faithfully, and extracting patch_merge::Envelope for reuse by Gemma 4 is genuine de-duplication rather than churn. What departs from the repository's own precedent is (a) a numeric-metadata table standing in for model identity inside shared upload packing, (b) a third copy of a per-profile pixel width, (c) span assembly moved into the layout dispatcher instead of staying with the layout, and (d) a test that reimplements existing template-patching machinery.
Key findings
- The description's orthogonality claim is contradicted by the code. The PR says
Bracketedderives its stride and width "directly fromconfig.contract.vision.patches_per_feature" so that "ImageLayoutKindandImagePreparationKindremain orthogonal with no model-identity branching in upload packing". In factpatches_per_featurealone does not identify a patch width:helios/src/frontend/images/packing.rs:315-317,329shows DeepSeek already runningpatches_per_feature = 9with 588 floats per patch. So9 => (3, 768)(packing.rs:16-22) is a model-identity lookup wearing a geometry name. - The same width is now authored three times —
packing.rs:16-22/39-42,conditioned.rs:192,gemma4.rs:116— and one of them is a cache-validation predicate, so a divergence surfaces as a confusing runtime failure rather than a compile error. - Atomic spans are assembled outside the layout, from arithmetic on a value that exists for offset accounting (
prompt.rs:137-151vslayouts/bracketed.rs:77-81), and no fixture or test carries a Gemma 4ImageSpan(helios/tests/support/contracts/gemma4_frontend.jsonhas"image_tokens": null; the only span-bearing fixtures aredeepseek4.json:58(not opened) and the synthetic spans inprompt.rs:482-485,699). The PR's "exposes atomic image spans for multimodal prefill scheduling" claim therefore has no automated evidence in-tree — only the pixel/position parity tests the author ran against a local snapshot. gemma4.rs:236-330reimplements repository test infrastructure it could call, and does network I/O undercargo test.- Nits: pb2 generator downgrade, missing protobuf round-trip test for the new tag, a duplicated soft-token allowlist, and
Envelope's home now out of step with its doc comment.
Conventions (departures from precedent)
Should fix — packing.rs:16-22, 24-42: patches_per_feature table as a model allowlist in shared packing
fn bracketed_patch_geometry(patches_per_feature: usize) -> Result<(i64, usize)> {
match patches_per_feature {
4 => Ok((2, 1176)),
9 => Ok((3, 768)),
_ => Err("unsupported bracketed patches_per_feature".into()),
}
}
Why it matters:
docs/design-review.md:38-46requires that "input packing … stay shared; use prepared metadata and frontend assets to express model-dependent behavior", and:49-52states plainly that "Enums, callbacks, schema names, and metadata fields cannot serve as alternative model allowlists." Ausize → (merge, width)table is exactly a metadata field acting as an allowlist.docs/design-review.md:42-43also bars policy that "branch[es] on model or recipe identity or capability flags".- The file's own precedent derives widths from the prepared layout, not from a numeric key:
packing.rs:31-45dispatchestensor_layoutonImageLayoutKind;qwen()derives its width fromconfig.contract.frontend.image_layout(packing.rs:123-134: Moonvit/Step 588, Radio 768, Glm 1176);class_token()reads the declared feature width fromsuper::padded_grid::FEATURES(packing.rs:537).bracketed()previously hard-coded2/1176with an explicitpatches_per_feature != 4guard; the table generalises the hard-code rather than moving the authority to metadata. - Correctness risk beyond style: the key is ambiguous. DeepSeek uses 9 with width 588 (
packing.rs:315-317,329), so if any bracketed-style layout ever pairspatches_per_feature = 9with an interleaved width other than 768, this table silently rejects or mis-sizes it, and the error text ("unsupported bracketed patches_per_feature") points at the wrong thing.
Fix: take the per-layout patch feature width from prepared metadata — a declared patch width on the layout/vision contract, consumed the way class_token() consumes padded_grid::FEATURES — and keep the merge stride derived from patches_per_feature as now (packing.rs:486-488 already validates tokens * patches_per_feature == patches). The new test at packing.rs:574-585 would then assert the metadata path rather than preserve the table.
Should fix — model/prompt.rs:137-151: spans filled by the dispatcher, not by the layout
The new block populates prepared.data.spans from prepared.conditioned_inputs after the layout has returned:
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();
}
- Precedent for spans is the layout that builds the expansion:
helios/src/frontend/images/layouts/deepseek.rs:149pushesdata.spans.push(start + padding..start + block.len())immediately besidetokens.extend(block)and the matchingvision_token_indicesextension (:150-151), thenvalidate_prompt_data(model.rs:436-453) checks span length, boundary tokens and coverage. For Bracketed, the envelope is built inlayouts/bracketed.rs:70-91andconditioned_inputsis returned asvec![]— every layout does that (bracketed.rs:44,90,class_token.rs:66(not opened),deepseek.rs:165,glm.rs:85,mimo.rs:76,moonvit.rs:89(not opened),qwen.rs:110(not opened),radio.rs:82(not opened),step.rs:108(not opened)). After this PRconditioned_inputsis filled centrally (prompt.rs:130-133), so "the layout owns its prompt data" no longer holds for one field while it holds fortokens,vision_token_indicesandconditioning. - The span is re-derived rather than observed:
bracketed.rs:77-81setstoken_expansions[i].1 = geometry.tokens + 1for offset accounting, andprompt.rs:129-131turns that intostart..start + additional + 1. That currently equals the envelope length (tokens + 2: begin token, tokens, end token) but only by coincidence of howadditionalis defined; nothing ties it to the indices the layout actually emitted, andmodel.rs:421-423would reject a span longer thanprefill_chunk_sizeonly after the fact. - Untested:
config.contract.frontend.image_tokensin the in-tree Gemma 4 fixture isnull, and the profile matrix test (prompt.rs:445-461) declaresspanonly forDeepseekandDeepseekRowMajor(:481-487). So the branch that this PR adds for the Bracketed/Gemma 4 path never runs under test — the "atomic spans" half of the claimed result has no test in the repository. A test asserting the span for a Bracketed contract withimage_tokens.spanset (start token, end token,max_tokens) would settle it.
Fix: build the span in layouts/bracketed.rs from the same indices that build the envelope, as deepseek.rs:149 does, and add the missing contract fixture/test.
Duplication (existing helpers or mechanisms it repeats)
Should fix — pixel width authored three times: packing.rs:16-22,39-42; conditioned.rs:187-194; gemma4.rs:116
helios/src/frontend/images/conditioned.rs:187-194is a third per-profile width table (Qwen/MiMo 1536,Radio 768,Glm 1176,PaddedGrid => padded_grid::FEATURES, and the newProfile::Gemma4(_) => 768at:192,_ => 588).helios/src/frontend/images/gemma4.rs:116computes3 * self.patch_size * self.patch_sizefor the buffer it allocates.
Why it matters: valid_processed is the cache predicate — when it disagrees with the packer the cache path fails with "image preprocessing differs from its prompt geometry", which sends a reader to the wrong layer. conditioned.rs:191 already shows the better pattern by referencing padded_grid::FEATURES rather than repeating a number; packing.rs:24-45 is the declared layout authority. Three independent copies with no compile-time link is the duplication this repository otherwise avoids (compare padded_grid::FEATURES, step::MAX_VIEWS).
Fix: one shared width helper derived from the profile/layout metadata (the same source tensor_layout uses), called by conditioned.rs, bracketed() and gemma4::process.
Should fix — gemma4.rs:236-330 (checkpoint_tokens_expand_the_image_envelope) rebuilds the template fixture machinery
The test locates ../.venv/bin/python, shells out with an inline -c script importing ignition.preparation.frontend.downloaded_template_asset, writes the result to std::env::temp_dir().join(format!("gemma4-template-{}.jinja", std::process::id())), and deletes it only after Frontend::load succeeds (:299; the early return at :281-283 leaks it).
Existing mechanisms it duplicates:
crate::template_fixtures::template("gemma4", "chat_template.google")is the established accessor for exactly this asset, already used athelios/src/frontend/jinja/tests.rs:274,822,helios/tests/message_boundaries.rs:191 (not opened),222,260andhelios/tests/ordinary_tokens.rs:451(not opened). The patch file the new test points at (helios/tests/fixtures/templates/gemma4/chat_template.google.patch.json(not opened),gemma4.rs:259-260) is the input to that fixture pipeline.helios/tests/frontend/prepare_templates.py(the_annotatepass) already applies the patch; the inline Python re-applies it a third way (the Rustannotated_template_assetinignition/preparation/frontend.py:24-40is the second).- Convention on checkpoint variables is fine:
FLARE_GEMMA4_TEST_SNAPSHOTonly locates a snapshot, matchingFLARE_MINIMAX_M3_SNAPSHOTinbracketed.rs:106, so that part follows AGENTS.md's rule that a test variable must not change what the code under test does. The problem is the extra Python subprocess and Hub download inside acargo testunit test, which depends on a developer's.venvand network.
Fix: load the template through crate::template_fixtures::template("gemma4", "chat_template.google") and drop the subprocess and temp file; keep only the snapshot for the tokenizer.
Nits
ignition/preparation/runtime_core_pb2.py— the header and the_runtime_version.ValidateProtobufRuntimeVersion(..., 7, 36, 1, ...)tuple move from 7.36.2 to 7.36.1. A 7.36.1 gencode still loads under a 7.36.2-or-newer runtime (ValidateProtobufRuntimeVersiononly rejects an older runtime), so nothing breaks, but the checked-in binding now records a generator older than the one this repository pinned, anddocs/runtime-core-design.md:247-248says these bindings are generated byprotocfrom the schema. Regenerate with the pinned generator so the recorded version matches. (I did not re-openpyproject.toml(not opened) in this pass; confirm the pin value.)helios/src/runtime_core/protobuf.rs:167-171— the newGemma4arm mirrors thePatchMergearm at:162-166correctly, but there is no round-trip test for the new tag, while GLM and padded-grid each have one (protobuf.rs:726,:749, both namedserialized_*_selects_only_image_preparation). Addserialized_gemma4_profile_selects_only_image_preparationasserting the field-11 bytes and thatImageProcessor::loadaccepts them; it is the only automated evidence for the "additive, wire-compatible" claim, which today rests on a hand-run Python round trip.- Soft-token allowlist duplicated:
helios/src/frontend/images/gemma4.rs:11([70, 140, 280, 560, 1120]) andignition/preparation/frontend.py:123(not in (70, 140, 280, 560, 1120)). No neighbouring profile enumerates an allowlist —deepseek_row_major.rs:14validates a range ((4..=1024).contains(&max_tokens)) — so there is no precedent to follow here; keep one authority, or derive the set frompooling_kernel_size/max_soft_tokensbounds and at minimum note the coupling at both sites. patch_merge::Envelope(patch_merge.rs:10-81) is now shared by Gemma 4 and its doc comment says "shared by enveloped image layouts", but it still lives inpatch_merge. Either move it beside the layouts or trim the doc to say it currently serves patch-merge and Gemma 4, so the next enveloped layout does not import from an unrelated module.
Precedents that hold (nothing found)
helios/proto/runtime_core.proto:522,535— tag 11 andGemma4ImageSettingsmirrorPatchMergeImageSettingsfield-for-field; additive, no renumbering.helios/src/model/contract.rs:68—Gemma4 = 11appended, preserving existing wire ids (design-review principle 13).helios/src/frontend/images/mod.rs:260,287,334,355,389,862,877,897,918—ImageSettings::Gemma4,Gemma4ImageSettings(deny_unknown_fields, snake_case like its neighbours) and everyProfile::Gemma4arm mirror thePaddedGridarms.helios/src/runtime_core/describe.rs:442-443mirrors thePatchMergearm at:440-441.ignition/preparation/frontend.py:113-137mirrors theglmbranch at:138-153, including_expectedhandling of optional fields.gemma4.rsreusesresize::resize(uint8 antialiased bicubic) aspatch_merge/qwendo, rather than adding a resize kernel — correct reuse of the shared mechanism.- Extracting
patch_merge::Envelopeout ofpatch_merge::Processor(patch_merge.rs:10-131) removes duplication rather than adding it. helios/src/model/packing.rs:92-97— the one call-site update for the newtensor_layoutparameter matches the neighbouring validation style. (Minor: the newpatches_per_featureis a bare positional parameter inserted mid-signature in a shared function, while the siblingbracketed()readsconfigdirectly; threadingconfigas elsewhere in that file would read the same at both call sites.)
Open questions / what could not be verified
- Does any Gemma 4 contract fixture set
frontend.image_tokens.span? If not, the atomic-span path has no coverage and the fix for finding 3 should include the fixture. - Is
pyproject.toml(not opened)'s protobuf pin in fact>=7.36.2,<8? That decides whether the pb2 downgrade is cosmetic (as I judged) or a pin mismatch. - The HF parity tests depend on
FLARE_GEMMA4_TEST_SNAPSHOTand silentlyreturnwhen unset (gemma4.rs:238-244), so the "45 passed" figure is not reproduced by a plaincargo test; nothing in CI exercises the parity claims.