Review of PR #483 — Gemma 4 image preparation, Bracketed patch-width metadata, atomic spans
Lens: correctness and consequences — every caller, configuration, platform and persisted state the change touches; existing cores and artifacts must still load.
Rules applied:
- Charter line 12: "Keep the runtime small and model-agnostic … shouldn't accumulate per-model branches."
- Charter line 42: "Supported matrix & compatibility: … verify that existing data, artifacts, and exported cores still load."
AGENTS.md:431-444(not opened) (model core compatibility: additive protobuf must preserve existing behaviour; every engine version must load previous cores).docs/design-review.md(not opened) principles 3 (shared mechanisms, prepared metadata, no per-model policy flags), 10 (persist only consumed structural frontend settings in typed fields), 13 (core compatibility).
Reviewed at head 2b4a31e (base main 27716185), 36 files, +2269/−240.
Key findings
-
Should fix — opaque Gemma 4 load error (
helios/src/frontend/images/gemma4.rs:30-38). One condition with one message covers six distinct rejections:patch_size == 0/> 64,pooling_kernel_size == 0/> 16, theSUPPORTED_SOFT_TOKENSallowlist,pooling² != limits.patches_per_feature, and the newmax_soft_tokens · pooling² > limits.max_patches_per_image. The last two are the interesting ones because they compare settings against captured capacity: a core whose captured patch capacity is below its declared soft-token budget (e.g. capacities taken at 280 while the checkpoint declares 1120) fails atImageProcessor::loadwithinvalid Gemma 4 image settingsand no way to tell whether the settings or the capacity is wrong.helios/src/server/config.rs:449-484shows the actionable style this file should follow (it names both values). Fix: split into named errors naming the failing field/limit. -
Should fix —
Bracketedgains a load-time narrowing the description does not disclose (helios/src/frontend/images/packing.rs:26-32, used frompacking.rs:49-51andhelios/src/model/packing.rs:92-97).square_merge_sidereturnsErr("bracketed patches_per_feature must be a positive square")forisqrtfailures, andtensor_layoutis called fromPacking::newwhile the core is loading, so anyImageLayoutKind::Bracketedcore declaring a non-square (or zero)patches_per_featurenow fails to start. Onmain,tensor_layoutnever consultedpatches_per_featureforBracketed(fixed 2 × 1176 geometry) and such a core loaded and failed, if at all, per request inbracketed(). The PR body claims "existing cores … remain loadable and unchanged"; that is true of the wire format but not of this load path, which is exactly the check the charter (line 42) andAGENTS.md:431-444(not opened) require to be proven. Fix: disclose the narrowing in the description and add a mounting test for a square-but-unusual value (e.g. 16, which now loads and packs at the legacy 1176 width), or accept any square ratio only after a sweep of shipped cores.
Detail by finding
1. Gemma 4 load-time validation (should fix, diagnostics)
gemma4.rs:25-39 also runs Envelope::load (patch_merge.rs:20-31) for the marker checks, which does produce specific messages; only the settings-vs-capacity block is opaque. The capacity clause is new in this revision and is the one an operator is most likely to hit, because limits.max_patches_per_image comes from the prepared vision.patch_capacities (helios/src/server/config.rs:492-500), i.e. from how the core was exported, not from the checkpoint. Nothing in docs/runtime-core-design.md (not opened) or helios/model-contract.md (not opened) tells an exporter what max_patches_per_image must be for a given max_soft_tokens; an explicit error is the only feedback available.
2. Bracketed compatibility (should fix, description/coverage)
packing.rs:16-24bracketed_patch_features:vision.patch_featuresif nonzero, else the legacy1176. This part is genuinely backward compatible and is the right shape: the field is#[serde(default)](helios/build.rs:50-57,helios/src/model.rs:52-53) and protobuf tag 6 is additive (helios/proto/runtime_core.proto).packing.rs:26-32square_merge_side: the new hard requirement. I could not find any other validation that rejectspatches_per_feature == 0before this point;helios/src/model.rs:74-81requires patch capacities to be multiples ofpatches_per_feature, which does not exclude 0 for a core with no image tensors. So the narrowing plausibly covers zero as well as non-square ratios.- Everything else in the packing rework checks out:
tensor_layoutnow takes&VisionCapabilities, its two call sites (model/packing.rs:92-97at load and the upload/storage path) agree, and the derived stride (bracketed_patch_features) cannot disagree with the processor width onceserver::config::validate_loaded_image_processor(config.rs:443-490) has run: line 449 rejectsprocessor.patch_features() != vision.patch_featuresand 456-463 rejects aBracketedmismatch againstbracketed_patch_features(vision)with an actionable "re-export the core with vision.patch_features" message. That closes the failure mode I raised in my first review.
3. Former "profile accepts settings packing cannot represent" — resolved, recorded for completeness
gemma4.rs:54-56 derives the per-patch width as 3 · patch_size²; conditioned.rs:187 now uses self.processor.patch_features() instead of a per-profile literal; mod.rs:459-471 covers all 11 profiles; config.rs:449 forces the prepared vision.patch_features to equal it. Consequently a hypothetical patch_size = 14, pooling = 2 Gemma 4 core is now internally consistent (588 floats per patch everywhere) rather than silently misaligned, and the 16/3 geometry is pinned where it should be — in the exporter (ignition/preparation/frontend.py). The collapse also fixes a pre-existing main bug: the old _ => 588 arm matched Profile::PatchMerge, so MiniMax's 1176-float patches failed valid_processed (conditioned.rs:213) and materialize (conditioned.rs:249).
4. Atomic spans — correct scoping, one untested interaction
- Emission moved to
helios/src/frontend/images/layouts/bracketed.rs:52-88:flush_spanis gated onatomic_spans, validates that the run has an envelope marker on both sides (start == 0 || end >= len→ "bracketed image span is missing envelope markers"), and pushesstart-1 .. end+1. The inner loop also cross-checksimage/featurecounts againstprocessed.geometry(lines 89-93), so a span cannot be emitted for a phantom image. - The shared fallback in
helios/src/model/prompt.rsis deleted;Deepseek/DeepseekRowMajorstill write their own spans inlayouts/deepseek.rs, and for layouts withoutimage_tokens.spanthe branch is inert. No behaviour change for existing cores — verified. Scheduler::set_prefill_spans(helios/src/scheduler.rs:2022-2045) rejects non-monotonic spans, spans withend > prompt_tokens, spans longer thanprefill_chunk_size, and any span straddlingconsumed_tokens.server/runtime.rs:1458-1465turns that error into a failed request.validate_loaded_image_processor(config.rs:465-488) now boundsmax_image_envelope_tokensby bothprefill_chunk_sizeandspan.max_tokens, which converts what used to be a per-request failure into a load-time one — the right direction and worth calling out as a positive.
Nits
helios/src/frontend/images/gemma4.rs:13—SUPPORTED_SOFT_TOKENS = [70, 140, 280, 560, 1120]duplicates the allowlist inignition/preparation/frontend.py:132. Two copies of a value that must stay in lockstep; a drift turns an export into a load rejection with error #1 above as the only clue.helios/src/scheduler/policy.rs:337-351withhelios/src/scheduler.rs:805-817—prefill_work_throughtruncatesendtospan.startwhenever a span straddles the computed cut, soend.saturating_sub(start) == 0; planning drops those candidates (policy.rs:479-482and911-923). Because the load check forcesenvelope <= prefill_chunk_sizeandprefill_graphsrequires the catalog to containprefill_chunk_size(scheduler.rs:807), a request is still served by the largest graph, so I could not show starvation; but every captured non-terminal capacity below the envelope length is silently unusable for span-bearing image requests, and no test covers a catalog with such an entry. A scheduler test advertising a sub-envelope capacity would settle it.helios/src/scheduler.rs:2036-2037vsdocs/TODO.txt:331-336— a prefix-cache endpoint restored strictly inside a span fails the whole request.scheduler/checkpoints.rskeeps published endpoints span-aligned, so the in-process path is safe, but a host-store record restored with a mid-span endpoint still fails admission and nothing asserts the intended behaviour.
Verified as no longer a problem
ignition/preparation/runtime_core_pb2.pychurn: regenerated at matchinglibprotoc 36.1; the diff is descriptor-only, no generated-header version regression.- Wire compatibility:
ImageSettings.profiletag 11,GEMMA4_IMAGE_PREPARATION = 11,VisionCapacity.patch_featurestag 6 withserde(default); no existing tag or enum value moved,ImageLayoutKinduntouched. - HF parity is now CI-runnable:
tests/frontend/gemma4_images.jsonis read viainclude_str!incanonical_processor_pixels_positions_and_resize, and the snapshot/venv tests are#[ignore]with explicit assertions rather than silent early returns. - Resource bounds on the new path:
gemma4.rsuseschecked_add/checked_mulfor patch totals and buffer extents and callslimits.check_batchbefore and after geometry;check_input_extent/check_image_patchescover the resize inputs.
Open questions / not settled from the code
- Does any shipped or previously exported core declare
ImageLayoutKind::Bracketedwith apatches_per_featurethat is not a positive square (including 0)? If yes, finding 2 is a startup regression and should block. Only a sweep of recipe-produced cores can settle it; nothing in this PR does. - Should a prefix-cache match ending inside an atomic envelope fail the request, or should the scheduler back off to the envelope boundary? The TODO audit covers the design; no test pins the behaviour.
- Serving-path timing and memory for Gemma 4 images were not measured by the author; the evidence offered is unit-, fixture- and preparation-level, and end-to-end multimodal serving depends on the companion
hyperflare-recipesPR declaringvision.patch_features = 768.