Review of PR #483 — Gemma 4 image prep profile, bracketed 3×3 packing, atomic spans (lens B: architecture & scope)
Key findings
- The "orthogonal layout" claim does not hold in the code.
packing.rs:16-22derives the Bracketed patch width by matching onpatches_per_feature(4 -> (2, 1176),9 -> (3, 768)). Patch width is a patch-size property (3·14² = 1176 vs 3·16² = 768), not a merge-count property; the merge count only happens to correlate with it in the two models in tree today. This is a count-keyed model allowlist in the shared upload path, which is exactly what the charter's "keep the runtime small and model-agnostic … shouldn't accumulate per-model branches" line forbids. The description presents this as makingImageLayoutKindandImagePreparationKindorthogonal; in fact it makes the layout depend on a number that only a model profile knows. - The same constant is now encoded in three places:
packing.rs:16-22(9 → 768),conditioned.rs:192(Profile::Gemma4(_) => 768, for cache validation), andgemma4.rs:99(3 * patch_size * patch_size). Only the last one derives it; the other two are the literals that will silently drift ifpatch_sizeis ever anything but 16. - Gemma 4 settings are never reconciled with the vision contract.
gemma4.rs:23-44accepts anypatch_size ≤ 64andpooling_kernel_size ≤ 16(onlymax_soft_tokensis a closed set), sopooling²need not equallimits.patches_per_feature. The mismatch surfaces later as a generic per-request error (prompt.rs:171,packing.rs:488), not at load. - The span population in
prompt.rs:137-151is a shared-scheduler behaviour change, not a Gemma 4 detail.data.spansfeeds bothvalidate_prompt_data(model.rs:436-451) andset_prefill_spans(server/runtime.rs:1460(not opened) →scheduler.rs:1912-1936), i.e. it decides which prefill submissions are atomic. The description says existing cores "remain wire-compatible and unaffected"; that is only true if no existing core declares anImageSpanwith an envelope-expanding layout — nothing in the PR shows this, and the guardprepared.data.spans.is_empty()makes the new code fire for every such layout, not justGemma4. - Atomic spans can exceed the prefill chunk.
validate_prompt_datarejectss.len() > config.limits.prefill_chunk_size(model.rs:422) and the scheduler rejectss.end - s.start > capacity(scheduler.rs:1926). Amax_soft_tokens: 1120image expands to 1,122 tokens; nothing ingemma4::Processor::loadorgeometrychecks that against the chunk size, so the largest supported Gemma 4 image becomes an unreachable-input error discovered at admission. - Scope/charter evidence gap. The charter's "New model recipes, aliases, or formats … must list supported checkpoints … and support more than a single checkpoint (#74)" is not met by the evidence given: the parity run names one snapshot (
google/gemma-4-31B-it,842da379), whileignition/preparation/frontend.py:126-129pins the 31B-B shape (27 layers / 1152 hidden / 16 heads / head_dim 72 / 4304 FFN) and the repository already documents other variants (docs/api.md:749(not opened) links the 26B-A4B-it card;docs/model-development.md:79-81(not opened) covers e2b-e4b templates).
Scope: does this belong in the repository?
Where it belongs — mostly yes. Image preparation is Helios's job (it already owns nine other profiles under helios/src/frontend/images/), and adding a profile behind the existing ImageSettings enum (mod.rs:257-260, mod.rs:389) is the established extension point, not a new mechanism. The proto addition is additive (runtime_core.proto:386, :522, :535-542; contract.rs:68), the Rust encode/decode path is one match arm (protobuf.rs:167-171), and the describe output is one arm (describe.rs:442-444). Nothing here invents a parallel mechanism, which is the failure mode the charter's "solve the right problem in the right place" bullet is aimed at.
Should fix — single-checkpoint support. ignition/preparation/frontend.py:113-137:
_expected(model["vision_config"], {"model_type": "gemma4_vision", "patch_size": 16,
"pooling_kernel_size": 3, "num_hidden_layers": 27, "hidden_size": 1152,
"num_attention_heads": 16, "head_dim": 72, "intermediate_size": 4304}, ...)
The last five fields are one architecture variant, and the three token strings are literals (frontend.py:135-137) rather than values checked against the checkpoint's added tokens. Consequence: a Gemma 4 checkpoint with a different vision tower is rejected by preparation with a generic "unexpected … vision configuration" error even though its image preparation would be identical, and if a checkpoint used different image token spellings the mismatch only shows up later inside envelope expansion. Fix: assert only the fields the preprocessor actually consumes (patch_size, pooling_kernel_size, max_soft_tokens, rescale/normalize flags), take the three token strings from the tokenizer/config and assert they encode to single added tokens, and either show a second checkpoint in the evidence or narrow the PR's claim to one checkpoint.
Nit — per-model branch in the cache validator. conditioned.rs:192 adds Profile::Gemma4(_) => 768 to valid_processed. It follows the existing pattern (the whole function is a per-profile match), so it is not a new design violation, but it is the third copy of the 768 constant — see the next section.
Layering: is the approach right, and are there per-model special cases?
Should fix — patch geometry belongs in the contract, not in a match on a merge count. helios/src/frontend/images/packing.rs:16-22:
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()),
}
}
Used from tensor_layout (packing.rs:38-42) and bracketed (packing.rs:480-481). What is wrong: the width of one vision patch vector is 3 · patch_size², and patch_size is a property of the vision tower, not of the merge factor. The function therefore hard-codes "a model with 9 patches per feature uses 16×16 patches" — a model identity, expressed as a filter on a number that has nothing to do with patch size. A future 3×3-merge tower with 14×14 patches silently gets 768 and produces truncated/garbled pixels or a Dtype/minimum-size mismatch downstream; conversely a 2×2-merge tower with 16×16 patches gets 1176. Every other layout in tensor_layout (packing.rs:26-45) derives its width from a named constant; only Bracketed now infers it. Why it matters: this is precisely the "per-model branches in the runtime" pattern the charter calls out (read_charter, "Keep the runtime small and model-agnostic", citing #267/#334). Fix: carry the patch-tower width in the prepared contract — e.g. VisionCapabilities.patch_size (validated in model.rs:68-87 alongside patches_per_feature) — and compute merge_side = patches_per_feature.isqrt(), patch_width = 3 * patch_size * patch_size. That is one additive contract field, no model names, and it removes the duplication in gemma4.rs:99 and conditioned.rs:192.
Should fix — the profile never checks its pooling against the packing contract. helios/src/frontend/images/gemma4.rs:23-44 accepts pooling_kernel_size ∈ 1..=16 and derives tokens = patches / (pooling*pooling) (gemma4.rs:~99) and max_patches = max_soft_tokens * pooling² (gemma4.rs:50-52). Nothing compares pooling² with limits.patches_per_feature, which is what validate_conditioned_inputs (prompt.rs:171), validate_prompt_data's span checks (model.rs:436-451) and packing::bracketed (packing.rs:488) all use. A config whose pooling_kernel_size is 3 but whose contract says 4 prepares images that are then rejected per request with "conditioned input spans or features violate prompt geometry" (prompt.rs:174) — an error that names nothing useful. Why it matters: this is the one place where the profile and the packing contract must agree, and it is the one place not validated. Fix: in Processor::load, reject unless patch_size * patch_size * 3 fits the packing width and pooling_kernel_size * pooling_kernel_size == limits.patches_per_feature; likewise reject max_soft_tokens * pooling² > limits.max_patches_per_image.
Observation, not a defect — the closed set of soft tokens. gemma4.rs:11,28 restricts max_soft_tokens to [70, 140, 280, 560, 1120], repeated as a literal tuple in ignition/preparation/frontend.py:124. That is model-spec pinning rather than model branching, and the charter's "no magic defaults, pin everything" principle supports it; it is worth a comment citing the upstream field instead of a bare array, but I am not reporting it as a finding.
Compatibility with what exists
Should fix — the atomic-span change is wider than the description. 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 runs inside prepare_image_inputs for every layout that returns no spans and whose contract declares an ImageSpan. Two consumers change at once:
- validation —
validate_prompt_data(model.rs:436-451) previously required every scoped token to lie in a span and would reject a span-declaring layout with emptydata.spans; and - scheduling —
server/runtime.rs:1460(not opened) passesprompt.data.spanstoScheduler::set_prefill_spans(scheduler.rs:1912-1936), which makes each span an unsplittable prefill unit (see alsoscheduler/policy.rs:340(not opened),scheduler/checkpoints.rs:110-245(not opened)).
So the change silently converts "an image envelope is ordinary text for chunking" into "an image envelope must be prefilled in one submission" for any existing core with an atomic span. The PR description says "Existing cores and non-Gemma image profiles remain wire-compatible and unaffected", and its test evidence (model:: 53 passed, frontend::images 45 passed) contains no test that an existing bracketed core's prefill chunking is unchanged. This may be a no-op in practice — layouts/bracketed.rs:82-91 returns PromptData { vision_token_indices, ..Default::default() }, i.e. empty spans, so if any in-tree core wires Bracketed with a declared ImageSpan today it was previously rejected outright, which would make the new code a strict improvement — but the PR does not state which cores that is. Fix: state in the description which layouts newly get spans (grep the recipes/core manifests), and add a test that a non-Gemma bracketed core either keeps its old chunking or now succeeds where it used to fail, so the behaviour change is pinned.
Should fix — a 1,120-soft-token image cannot be prefilled atomically. validate_prompt_data rejects any span longer than the chunk (model.rs:420-423, message "prompt arrays violate prepared geometry"), and set_prefill_spans rejects s.end - s.start > capacity (scheduler.rs:1922-1930). Gemma 4's largest supported setting is max_soft_tokens: 1120 (gemma4.rs:11), and the envelope span is tokens + 2 (start and end tokens, gemma4.rs:236-300 test asserts start + 261 for a 260-token image). Nothing in gemma4::Processor::load/geometry (gemma4.rs:23-52, :54-...) checks max_soft_tokens + 2 <= prefill_chunk_size. If a core is prepared with a prefill chunk below ~1,122 tokens, every 1,120-token image is admitted by geometry and then fails at prompt validation with an error that names neither images nor spans. Fix: either reject the combination at load with a named error, or clamp max_soft_tokens to the largest supported value whose span fits the chunk — and add a test at the boundary. Only a test with a real prepared core settles the actual chunk size; I could not determine the values used by Gemma 4 cores because those recipes live in local-inference-lab/hyperflare-recipes.
Should fix (small, but a pinned-version rule) — protobuf gencode regenerated with an older compiler. ignition/preparation/runtime_core_pb2.py:5 changes # Protobuf Python Version: 7.36.2 to 7.36.1, and :16 changes the runtime-version check argument 2 to 1. The rest of the large +122/−120 diff is the re-serialized descriptor, expected from adding a field. The header downgrade means the file was produced by a different generator than the repository pins, which contradicts the charter's "Be explicit and pin everything … pin dependencies to exact versions or commits". Fix: regenerate with the pinned protoc/protobuf (7.36.2) so only the descriptor bytes change, or state the intended version bump in the PR.
Evidence and claims versus the description
- Parity evidence is real but narrower than claimed.
gemma4.rs:236-300(checkpoint_tokens_expand_the_image_envelope) andgemma4.rs:302-417(native_pixels_and_positions_match_the_checkpoint_processor) compare againsttransformers'Gemma4ImageProcessorfor91×37,10×3000,3000×10with exactf32equality — that part of the claim checks out. But all three parity cases (and the geometry table atgemma4.rs:200-209) use synthetic images ((x % 256) as u8rasters), and the tests return early when.venv/bin/pythonorFLARE_GEMMA4_TEST_SNAPSHOTis absent (gemma4.rs:238-256,:330-334), so in a normal CI run the parity assertions never execute. The PR description is honest about the synthetic inputs; it does not say the tests silently pass-by-skip without the environment. The charter's "Bring real evidence" bullet expects these to run somewhere observable — a CI job or a recorded transcript of the run would settle it. - Contradiction between description and code on orthogonality. "derived
Bracketedmerge stride and patch width directly fromconfig.contract.vision.patches_per_feature… soImageLayoutKindandImagePreparationKindremain orthogonal with no model-identity branching in upload packing" — the second half is the opposite of whatpacking.rs:16-22does; the4/9integers are the model identity, and this is the one place intensor_layoutthat branches on anything but the layout kind. - No measured performance or memory evidence, and none is claimed, so nothing here trips the "#210 benchmarks" rule; the change is a correctness/coverage addition. Worth saying explicitly in the description that no serving-path timing was measured, since a new preprocessor plus atomic spans does change scheduling granularity for image requests.
- Test-claim mismatch to check: the description says "45 passed" for
frontend::imagesand "53 passed" formodel::, butprompt.rs's new span logic has no test in the PR diff — the only new tests arepacking.rs:569-584(threetensor_layoutassertions) and the three ingemma4.rs. If 45/53 are pre-existing counts, then the span population path (prompt.rs:137-151) is entirely untested by this PR, which is also why the compatibility question above is unresolved.
Nits
packing.rs:569-584: the new test asserts the mapping (4 -> 1176,9 -> 768) rather than the property it wants (width tracks patch size), so it will keep passing through exactly the mistake finding 1 describes. A test written against a contract field would be a real guard.gemma4.rs:11andignition/preparation/frontend.py:124: the soft-token list[70, 140, 280, 560, 1120]is duplicated across languages with no shared citation; a comment naming the upstream field (image_processor.max_soft_tokens) in both places would keep them honest.
Open questions / what I could not establish
- Which existing cores declare an
ImageSpanwhile using an envelope-expanding layout? This decides whetherprompt.rs:137-151is a no-op for existing models or a scheduling change. The core manifests live inlocal-inference-lab/hyperflare-recipes, outside this repository, so I could not check. Those manifests, or a grep of prepared contracts inhelios/tests/, would settle it. - What
prefill_chunk_sizedo Gemma 4 cores get? Only a real prepared core (or the recipe) shows whether the 1,120-token span fits (model.rs:422,scheduler.rs:1926). - Does any second Gemma 4 checkpoint share the vision tower pinned at
frontend.py:126-129? The charter requires more than one checkpoint (#74); the description and evidence cover one. Runningprepare_frontend(..., image_profile="gemma4")against the 26B-A4B-it and e2b/e4b checkpoints named indocs/api.md:749(not opened) anddocs/model-development.md:79-81(not opened) would settle it.
What I checked and found clean
- Proto/contract additions are additive and backward compatible: new enum value 11 (
contract.rs:68,runtime_core.proto:386), new oneof field 11 (runtime_core.proto:522), new message (:535-542); decode (protobuf.rs:167-171), describe (describe.rs:442-444), JSON (mod.rs:334-341) and preparation (frontend.py:113-137) all keyed off the existingImageSettingsenum rather than a new mechanism. - The
patch_merge.rsrefactor ofProcessorintoEnvelope+Processor(patch_merge.rs:10-100) preserves the previous PatchMerge validation and expansion semantics, with the token-uniqueness checks moved verbatim intoEnvelope::load(patch_merge.rs:19-31);expand_promptdelegates (patch_merge.rs:94-100). No behavioural change for the Minimax path visible in this file. gemma4.rsgeometry/resize arithmetic is self-consistent (aspect-preserving, side multiplepatch_size * pooling, area boundmax_soft_tokens * pooling² * patch_size², int overflow guarded viachecked_mul/try_fold) and thetokens * pooling² == patchesinvariant holds by construction, so the only gap is the cross-check with the contract (finding 3).