Architecture scratchpad · NVIDIA/hyperflare-inference #483

Raw Markdown for agents: https://autobot.eidonix.com/p/b76a17e2-e2ca-404a-846c-be2fbcab11bd.md

#1 [high] [should fix] Bracketed patch geometry is a count-keyed model allowlist in shared packing

Lens B (architecture/scope). helios/src/frontend/images/packing.rs:16-22 (new bracketed_patch_geometry):

4 => Ok((2, 1176)),
9 => Ok((3, 768)),
_ => Err("unsupported bracketed patches_per_feature")

Used at packing.rs:39-42 (tensor_layout) and packing.rs:480-481,486,497 (bracketed). Why it matters: the patch vector width is 3*patch_size*patch_size (1176 = 321414 for the existing temporal patch-merge, 768 = 316*16 for Gemma 4), i.e. a property of the preparation profile's patch size, while the merge stride is sqrt(patches_per_feature). The table collapses two independent quantities into one lookup keyed on a bare count in shared upload packing. That is a model-identity allowlist expressed as arithmetic: patches_per_feature == 9 is "Gemma 4" here. AGENTS.md (architecture bullet, ~l.358-364) requires "Every member must have a meaning independent of model identity, and its consumers must implement shared behavior from actual data, geometry, and dependencies"; design-review.md principle 1 and 3 say the same (limit native specialization to cache storage/graph bindings; express differences through prepared layout metadata). Third copy of the same knowledge: helios/src/frontend/images/conditioned.rs:192 Profile::Gemma4(_) => 768, plus gemma4.rs patch_size, plus this table. Fix: declare the patch feature width (patch_size, or features-per-patch) in the prepared vision/frontend metadata and derive both merge_side (from patches_per_feature, e.g. isqrt with a divisibility check) and patch_width (from patch_size) from actual declared data, with one owner. At minimum, compute both from declared fields instead of a match on a count.

#2 [high] [should fix] Gemma4ImageSettings never validated against vision.patches_per_feature

helios/src/frontend/images/gemma4.rs:23-38 (Processor::load): validates patch_size != 0, <= 64, pooling_kernel_size != 0, <= 16, and max_soft_tokens membership, then stores limits. ImageLimits carries patches_per_feature (frontend/images/mod.rs:54) but it is never compared with pooling*pooling. max_patches() (l.48-50) and geometry() derive tokens/patches purely from pooling.

Consequence, checkable in code: a Gemma 4 core prepared with pooling 2 (patches_per_feature = 4) but patch_size 16 emits 768 floats per patch; bracketed_patch_geometry(4) returns patch_width 1176, so packing.rs:497 slices pixel_values.get(start*1176..end*1176) and returns "truncated vision pixels" at request time — a request-time failure instead of a load-time one, and Inputs::new (model/packing.rs:92-102) accepts the buffer because the table value is larger than the packed extent. Conversely pooling 4 would emit 3072 floats/patch and the table rejects the core at load with a misleading message. Both padded_grid and glm hardcode their merge (padded_grid.rs:31,186) and are cross-checked by validate_conditioned_inputs (model/prompt.rs:171); the new profile is the only one whose merge is data-driven and unchecked. Fix: reject in Processor::load unless pooling*pooling == limits.patches_per_feature and 3*patch_size*patch_size equals the packed feature width the layout will expect (once finding 1 gives the latter a declared owner).

#4 [high] Should fix: Ignition's contract helper cannot author vision.patch_features, so the new load-time error is the first a recipe sees

Lens B (architecture / layering). Verified in code.

ignition/preparation/contract.py:109-113:

def model_contract(*, vocabulary, input_vocabulary=None, vision=None, ...):
    return dict(version=3, vocabulary=vocabulary, ...
        vision={"feature_slots": 0, **(vision or dict(features_per_request=0, max_images=0,
               patches_per_feature=0, patch_capacities=[]))},

patch_features — the field this PR adds (helios/proto/runtime_core.proto:280-281) as the sole carrier of the Bracketed patch width — is absent from both the default dict and the documented shape. A recipe that passes the four historical vision keys gets patch_features = 0, which on the Rust side decodes as 0 (helios/build.rs:53-56 field attribute, model.rs:51-53) and therefore as the legacy 1176 width (packing.rs:16-24 bracketed_patch_features).

Then server::config::validate_loaded_image_processor (helios/src/server/config.rs:456-464) rejects it: "bracketed image layout patch width (1176) differs from image processor (768); re-export the core with vision.patch_features". server/config.rs:290-298 runs this inside Bootstrap::load, i.e. at flare run, after weights are selected — not at export and not at contract.model_contract time.

Why it matters: the PR's own story is that patch_features makes Bracketed model-agnostic, but the Ignition-side authoring surface never learned the field. The only discoverable mention of it is docs/TODO.txt (the companion-recipe line) and an error message. That is "solve the right problem in the right place" failing on the writer side: a recipe author has no default, no docstring, and no schema hint.

Fix: add patch_features=0 to the default vision dict in contract.py:112 (and note in the docstring that Bracketed vision cores must declare it), so the key exists in every exported contract and a Gemma 4 recipe only has to set 768.

Confirming non-regression that I did verify: a MiniMax Bracketed core keeps loading — processor.patch_features() for Profile::PatchMerge is 3*2*14*14 = 1176 (patch_merge.rs:124-126), vision.patch_features == 0 skips the first comparison, bracketed_patch_features yields 1176, and max_image_envelope_tokens() is None for PatchMerge (mod.rs:475-480) so the envelope bound does not apply.

#8 [high] Verification of previous findings at head 2b4a31e — blockers 1-3 and should-fixes 1-5 and 7 all fixed

Verified against the head commit (2b4a31e) and against main, lens B only.

  1. packing.rs model-identity table — fixed. bracketed_patch_geometry(4=>1176, 9=>768) is gone. Now packing.rs:16-24 bracketed_patch_features(vision) reads vision.patch_features with 0 -> 1176 legacy, and packing.rs:26-32 square_merge_side derives the stride from patches_per_feature.isqrt() with a square check. Untyped arithmetic, no model names. tensor_layout gained a &VisionCapabilities argument (packing.rs:34-39), threaded from its one caller model/packing.rs:92-97.

  2. gemma4::Processor::load contract check — fixed. gemma4.rs:25-52: pooling_area != Some(limits.patches_per_feature) and max_patches <= limits.max_patches_per_image are both rejected, plus patch_size/pooling/max_soft_tokens bounds. Tested negatively at gemma4.rs:219-264 (patches_per_feature 4 rejected, budget 2519 rejected, unsupported soft tokens rejected).

  3. Patch width unification — fixed. ImageProcessor::patch_features() (mod.rs:459-474) covers all 11 profiles; conditioned.rs:187 now calls it instead of its own match; PatchMerge derives 3*2*14*14 = 1176 (patch_merge.rs:124-126), PaddedGrid = padded_grid::FEATURES (mod.rs:465). Cross-profile test: packing.rs:690-826 asserts processor.patch_features() == tensor_layout(...).1 for 11 profile/layout pairs.

  4. Atomic spans moved into the layout — fixed, shape noted in entry #6. The prompt.rs:137-151 fallback block is gone; layouts/bracketed.rs:52-107 now emits spans. model/prompt.rs diff has no span-population logic left. Test prompt.rs:1171-1284 covers span-bearing (2 spans, len 262, marker ids), 64-aligned chunk too small (256 vs 262 rejected), and no-span MiniMax (empty spans).

  5. Envelope bound at load — fixed. server/config.rs:465-488 rejects max_image_envelope_tokens > prefill_chunk_size and > span.max_tokens; gemma4.rs:58-60 max_image_envelope_tokens() = max_soft_tokens + 2. Boundary test server/config.rs:985-1023: 1122 fits in 1152, fails at 1088; span.max_tokens 1121 fails, 1122 passes. Note this is a load-time check in Bootstrap::load (server/config.rs:290-298), which is the correct layer.

  6. runtime_core_pb2.py version — not a finding. main's own runtime_core_pb2.py:5,16 already declares 7.36.1 / 1; the PR's file declares the same. pyproject.toml:34 pins protobuf>=7.36.2, which bounds the runtime, not the generator's emitted header. My earlier concern was wrong; the diff is now descriptor-only plus the two new fields. Drop this.

  7. Ignition single-checkpoint pinning — fixed. 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 (image_token/boi_token/eoi_token), validated to encode as one token each against tokenizer.json, and cross-checked against optional config.json *_token_id. tests/preparation/test_frontend_gemma4.py covers E2B-sized towers, gemma4_unified rejection on all three surfaces, and three cached checkpoints.

  8. Docs — fixed. helios/README.md:706-717 lists Gemma 4 among profiles and describes the processor; docs/runtime-core-design.md:184-194 documents patch_features and the bootstrap cross-check; helios/model-contract.md:82 documents the field; docs/TODO.txt:330-337 tracks the recipe wiring, E2B/E4B/26B-A4B/31B qualification, and partial-span prefix-cache audit.

Note on the diff scope: the PR head diff also contains a large amount of unrelated main churn (banner removal, flare doctor, parallax, download rewrites, RebuildManifest->PreparationManifest). Those are base-branch commits between the old base and main; they are not this PR's changes (the pr_files list against the merge base shows only the 36 files in the orientation packet). Do not report them.

#9 [high] Research summary

Verdict: should-fix issues only. No blockers remain — every blocker and every should-fix from my previous review is fixed at head 2b4a31e, verified in code (scratchpad entry #8 has the per-finding citations).

Confirmed fixed: the patches_per_feature → width model-identity table is gone from shared packing (packing.rs:16-32 now reads vision.patch_features and derives the stride from isqrt); gemma4::Processor::load enforces pooling² == limits.patches_per_feature and the patch budget (gemma4.rs:25-52); ImageProcessor::patch_features() unifies all 11 profiles (mod.rs:459-474) with a cross-profile test (packing.rs:690-826); atomic spans moved out of prompt.rs into layouts/bracketed.rs:52-107 with span-bearing / small-chunk / no-span tests (prompt.rs:1171-1284); the envelope fits check runs at bootstrap (server/config.rs:465-488) with 64-aligned boundary tests; Ignition now asserts only consumed fields and reads envelope tokens from the tokenizer (frontend.py:114-173); docs and TODO.txt updated. My earlier protobuf-version concern was wrong — main itself declares 7.36.1, so that item is dropped.

Should fix (new, this lens):

Nit/evidence: the positive-square Bracketed narrowing is enforced at model load, not per request — correct place, but the description should say so.

I could not open the recipe manifests (they live in local-inference-lab/hyperflare-recipes), which is what would settle whether any published Bracketed core has a non-square patches_per_feature.

#10 [high] Report of 2026-11-25 (run at head 2b4a31e) — supersedes #3. Verdict: should-fix only, no blockers

Review of PR #483 — Gemma 4 image prep profile, bracketed patch-width metadata, atomic spans

Lens B: architecture & scope. Reviewed at head 2b4a31e against main 27716185. This supersedes scratchpad entry #3 (my 2026-11-24 report, written against the pre-rebase head). Do not report the unrelated churn visible in the raw head diff (banner removal, flare doctor, parallax, download rewrites, RebuildManifest→PreparationManifest); those are base-branch commits, not this PR's files.

Verdict: should-fix issues only. No blocking findings.

Everything from my previous review is fixed (verified in code, see entry #8)

Should fix

1. Ignition's contract helper cannot author the new field — ignition/preparation/contract.py:112. (entry #4) The default vision dict is dict(features_per_request=0, max_images=0, patches_per_feature=0, patch_capacities=[]) — no patch_features, the only carrier of the Bracketed patch width added by helio/proto/runtime_core.proto:280-281. A Gemma 4 recipe that fills in the historical four keys exports patch_features = 0, which bracketed_patch_features reads as the legacy 1176, and server/config.rs:456-464 then rejects it at flare run: "bracketed image layout patch width (1176) differs from image processor (768); re-export the core with vision.patch_features". The failure is at serve time, not export time, and the only authoring hint is that error plus a TODO.txt line. This is the "right problem, wrong layer" pattern on the writer side: the PR made Bracketed model-agnostic in Rust but left the Ignition surface that must declare the width unchanged. Fix: add patch_features=0 to the default dict 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-Gemma4 profiles (mod.rs:475-480).

2. atomic_spans: bool is derived contract state threaded into the layout — layouts/bracketed.rs:23, model/prompt.rs:52-65. (entry #6) The caller computes .image_tokens.as_ref().and_then(|layout| layout.span.as_ref()).is_some() and passes a bool down. layouts::deepseek needs no flag: it always populates data.spans (deepseek.rs:149) because validate_prompt_data already rejects non-empty spans when the contract declares no ImageSpan (model.rs:457-458). So the flag is not needed for correctness, only it also makes the "span is missing envelope markers" check (bracketed.rs:57-65) conditional on the flag. Fix: drop the parameter, populate spans unconditionally as Deepseek does, and let model.rs:457-458 be the gate — this returns prompt.rs to one line per layout.

3. The checked-in fixture pins pixels only; its model/token block is dead data — tests/frontend/gemma4_images.json, gemma4.rs:266-333. (entry #5) generate_gemma4_image_fixtures.py:81-86 writes processor, model, cases; the Rust consumer reads only cases. So the fixture pins no envelope or token behaviour, and the token-level parity lives entirely in #[ignore]d tests (gemma4.rs:375-451) plus test_frontend_gemma4.py:195-200, which pytest.skips without HF_HOME. On a clean CI node the charter's "more than a single checkpoint" requirement (#74) is shown by nothing but prose. 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 the processor settings round-trip through Gemma4ImageSettings); state in the description that the live runs are not run in CI.

Nit / evidence gap

4. The positive-square Bracketed narrowing is enforced at model load, not per request. (entry #7) square_merge_side is now called from tensor_layout (packing.rs:49-56), which Inputs::new (model/packing.rs:92-102) runs while validating any core whose graph binds 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 per "existing data, artifacts, and exported cores still load", but the description frames it as a load-path impact on MiniMax specifically; it should say load-time for any Bracketed core. Whether any published Bracketed core is affected cannot be settled here: the recipes live in local-inference-lab/hyperflare-recipes. Checking that repo's MiniMax vision vision.patches_per_feature would settle it.

Scope: does this belong here?

Yes. helios/src/frontend/images/ already owns nine preparation profiles; adding Gemma4 behind the existing ImageSettings enum (mod.rs:257-260, 389) is the established extension point, not a new mechanism. The proto addition is additive (runtime_core.proto:280-281, 449, 585, 598-606; contract.rs:68), decode is one arm (protobuf.rs:168-172), describe is one arm (describe.rs:451-453) and omits patch_features when 0 (describe.rs:465-468). The Envelope extraction from patch_merge::Processor (patch_merge.rs:10-31, 84-136) is genuine de-duplication with no behaviour change for MiniMax: token-uniqueness validation moved verbatim and expand_prompt delegates. No performance or memory claim is made, so the "#210 benchmarks" rule is not engaged — the description already states no serving-path timing was measured.

What I checked and found clean

Overflow guards in gemma4.rs (checked_mul for patch_features, try_fold for patch totals, pooling_area/max_patches as Option); VisionCapabilities::validate() now rejects non-multiples-of-3 widths and accepts 0 (model.rs:72-92); tensor_layout overflow-checks the Bracketed extent (packing.rs:52-54); the protobuf round-trip test (protobuf.rs:812-866) confirms tag 11 selects only image preparation; bracketed() rejects any grid not divisible by the derived merge side and any token/patch mismatch (packing.rs:494-517).

#5 [medium] Should fix: the checked-in Gemma 4 fixture pins pixels only; its model/token block is dead data, so envelope parity has no CI evidence

Lens B (evidence vs. claim, charter "Bring real evidence" + "New model recipes … must list supported checkpoints … and support more than a single checkpoint (#74)").

Verified: tests/frontend/generate_gemma4_image_fixtures.py:81-86 writes three top-level keys — processor, model (subset of vision_config/model_type/image_token_id/boi_token_id/eoi_token_id), cases. The consumer, helios/src/frontend/images/gemma4.rs:266-333, reads only fixture["cases"] (width/height/seed/max_soft_tokens/grid/tokens/patches/resized/pixels/positions). Nothing in the repository reads fixture["processor"] or fixture["model"] (grep for gemma4_images.json returns only gemma4.rs:270).

Consequences:

  1. The fixture does not pin envelope/token behaviour at all — envelope coverage now rests on patch_merge.rs::envelope_expands_image_placeholders_and_rejects_mismatches with a synthetic BPE tokenizer, which is a different tokenizer from the checkpoint's.
  2. The token-level checkpoint tests are #[ignore = "requires FLARE_GEMMA4_TEST_SNAPSHOT"] (gemma4.rs:375-447) and #[ignore = "requires .venv with transformers Gemma4ImageProcessor"] (gemma4.rs:450-451); the third-checkpoint evidence in tests/preparation/test_frontend_gemma4.py:187-200 pytest.skips when the snapshot is not in HF_HOME. So on a clean CI node "more than a single checkpoint" (#74) is still shown by nothing but prose.

Fix: consume the fixture's model block (assert the configured image_token/start_token/end_token ids match the recorded image_token_id/boi_token_id/eoi_token_id and that the processor settings round-trip through Gemma4ImageSettings), which is pure Rust and needs no checkpoint; and state in the description that the live runs are unrun-in-CI rather than counting them as passing.

#6 [medium] Should fix: the atomic_spans flag is a caller-derived projection of contract state, not layout state

Lens B (right place / smallest footprint). Verified.

helios/src/frontend/images/layouts/bracketed.rs:23 adds an atomic_spans: bool parameter to prepare_input, and model/prompt.rs:52-65 computes it by digging the flag out of the contract on the caller's side:

Some(ImageLayoutKind::Bracketed) => layouts::bracketed::prepare_input(
    frontend, processor, rendered, &images,
    config.contract.frontend.image_tokens.as_ref()
        .and_then(|layout| layout.span.as_ref()).is_some(),
)?,

The callee already receives everything needed to decide. processor.expand_prompt -> patch_merge::Envelope::expand (patch_merge.rs:33-81) produces the start/end marker ids; the layout has rendered, the expanded tokens, and images. What it does not have is the declared ImageSpan (start_token/end_token/max_tokens), which is config.contract.frontend.image_tokens.

Two smaller consequences worth naming, both visible in the code:

Fix: drop the parameter; populate spans unconditionally in the layout (the Deepseek pattern), and let validate_prompt_data's existing "image layout does not declare atomic spans" branch (model.rs:457-458) be the gate. That keeps layout state owned by the layout, removes the flag from the shared signature, and makes the marker-presence check unconditional.

Not a defect, just what to cite: with the flag removed, prompt.rs returns to one line per layout, which is the pre-PR shape (git show main:helios/src/model/prompt.rs:53-55 is a single-line call).

#7 [medium] Nit/evidence: the positive-square Bracketed narrowing is enforced at model load, not per request; description should say so

Lens B (compatibility with existing artifacts). Verified that this narrowing is real and check its blast radius.

helios/src/frontend/images/packing.rs:26-32 square_merge_side is now called from tensor_layout for every ImageLayoutKind::Bracketed pixel tensor (packing.rs:49-56), i.e. from model/packing.rs:92-102 while loading (validating) any core with a Bracketed vision graph. Before the PR, Bracketed did not inspect patches_per_feature here at all (main: (ImageLayoutKind::Bracketed, "vision_pixel_values") => (Float32, patches * 1176)).

Also packing.rs:503: || geometry.tokens.checked_mul(patches_per_feature) != Some(geometry.patches) replaces the old geometry.tokens != geometry.patches/4 || vision.patches_per_feature != 4.

So a core whose vision.patches_per_feature is not a perfect square — or a Bracketed core that declares, say, patches_per_feature = 2 — now fails at model load with "bracketed patches_per_feature must be a positive square" / "invalid bracketed image extent". The description discloses this ("Bracketed now requires a positive-square patches_per_feature"). What it does not disclose is that the check moved earlier: square_merge_side in tensor_layout runs during Inputs::new for any graph binding vision_pixel_values, so a Bracketed core that never serves an image request still fails to load. Under the charter's "Supported matrix & compatibility … verify that existing data, artifacts, and exported cores still load", that is the right place for it (fail at load), but the description should say load-time, not request-time.

I could not check whether any in-tree or published Bracketed core has a non-square patches_per_feature: the only Bracketed core in this repository is the MiniMax one exercised in layouts/bracketed.rs:124-200 and patch_merge.rs:143, which uses the default ImageLimits (patches_per_feature: 1 from mod.rs:65) — note 1 is a square (side 1) so it passes, but it also means the packing tests at packing.rs:600-690 are the only ones exercising a real square. Recipes live in local-inference-lab/hyperflare-recipes. Checking that repo's MiniiMax vision vision.patches_per_feature would settle it; I could not open it.

Not a finding on its own; record as a description-evidence gap for the compatibility statement.