Repository navigation
Add Gemma 4 image preparation, Bracketed patch-width metadata, and atomic spans - #483
rickybrent wants to merge 1 commit into
Conversation
|
A case file has been opened for 483 To opt out, include #autobot:ignore in the PR or any comment. |
Changes RequestedThe bones are good — the proto/contract additions are properly additive, the Blockers:
Should fix:
Nits:7 nits (churn in the staging.put rewrite, a table-only test, missing protobuf round-trip test, duplicated soft-token allowlist, and four prose items) To opt out of future reviews, put #autobot:ignore in your response. |
f2340e4 to
792522d
Compare
792522d to
2b4a31e
Compare
|
Thanks for the thorough review! The branch has been rebased onto
|
Autobot ReviewFull Review for Agents. Recommendation: Changes RequestedBlockers:None. Nothing on the served path is incorrect; the remaining items are one scope question, one authoring gap on the Python side, and cleanup. Should fix:
Nits:5 nits PR #483 — Add Gemma 4 image preparation, Bracketed patch-width metadata, and atomic spansHead Key findingsNo blockers. Every blocker and should-fix from the previous round is fixed and verified in code at this head: patch width comes from prepared metadata instead of a What remains: five should-fix items — one scope question needing an answer before merge, one authoring gap that hands the first Gemma 4 recipe author a serve-time error, one opaque load error, dead configuration knobs, and superseded test scaffolding — plus five nits, mostly documentation and duplicated test rows. Note on diff scope: the head diff also shows large unrelated base-branch churn (banner removal, Verified resolved this round — not re-litigated
BlockersNone. Should FixS1 — The profile lands ahead of the exporter that can use it, and no test mounts an existing
|
2b4a31e to
ab9a432
Compare
|
I updated
|
Autobot ReviewFull Review for Agents. Recommendation: Changes RequestedBlockers:None. Should fix:
Nits:10 nits Full report — no blockers; every round-3 should-fix is fixed and verified in code at To opt out, include #autobot:ignore in your post or comment. |
|
This is ready for maintainer review ( Two quick notes on the remaining bot items:
The other two items are pure bot errors/looping:
#autobot:ignore |
ab9a432 to
c3f3311
Compare
Gemma 4 sliding-window layers allow each image token to attend over `window ∩ (causal ∪ same-image-block)` (`sliding_window = 1024`), while global layers remain causal. Paged causal prefill attention alone cannot express bidirectional same-image attention, whereas a dense chunk-local SDPA overlay adds O(T^2) overhead to text-only chunks and breaks multi-turn prefix-cache boundaries. Because sliding prefill layers stage the active circular window + current chunk into a contiguous buffer via `PreparedWindowStaging` (or `stage_circular_kv` for BF16 KV), a sparse Triton overlay reading that staged buffer (shifting `positions` and `image_span_end` by each request's first staged position `max(0, start - window)`) handles arbitrary cached prefixes, wraparound, and KV-shared sliding layers, exits immediately on query tiles containing no image tokens, and stays a recipe-side `native_contract` Triton operator captured inside existing `prefill` graphs (introducing no Helios `GraphOperation` family or runtime operation contract). This PR stacks on `local-inference-lab#16` (`recipes/gemma4-sliding-window-kv`) and `local-inference-lab#14` (`recipes/gemma4-vision-encoder`) and requires companion core PR `NVIDIA/hyperflare-inference#483` (`core/gemma4-image-frontend`) for native Gemma 4 image preprocessing, 3x3 bracketed packing (`patch_features = 768`), and atomic image spans. Changes: - hyperflare_recipes/components/image_sliding_attention.py: add `compute_image_sliding_spans` (O(T) pure-tensor reverse-cummin span calculation shared across all sliding layers) and `PreparedImageSlidingAttention` (`flare.image_sliding_attention` recipe-side `native_contract` Triton operator accepting both FP8 E4M3 and BF16 paged/staged K/V caches, optional unbound `k_cache`/`v_cache`, overwriting only image rows in place and exiting early on text-only tiles). - hyperflare_recipes/recipes/gemma4/{vision_state,config,weights, contract,attention,decoder,bootstrap,recipe}.py: wire `VisionInputs`, `PreparedVisionGeneration` (5 vision graphs for capacities 630..10080), `VisionParameters(separable_encoder=True)` on `Gemma4Parameters`, `VISION["patch_features"] = 768` matching `#483`, BF16 vision tower loading (with `--language-model-only` and `--image-concurrency` opt-out), vision feature injection after text embedding scaling, per-prefill staged span offset calculation in `PreparedDecoder`, and `PreparedImageSlidingAttention` over the staged output in `PreparedAttention`. Include `"vision"` in the compilation identity hash. - tests/components/test_image_sliding_attention_cuda.py: add 8 SM120 CUDA tests covering FP8 and BF16 paged/staged circular-window parity across early, pre-wrap, 1,500-token wraparound, 1,120-token window-clipped images, poisoned 0x7F ring slots, multi-request heterogeneous starts, and CUDA graph capture/replay with text-only early exit. - tests/frontend/test_gemma4_images.py: add 3 frontend metadata and atomic-token validation tests against `ignition.preparation.frontend`. Claimed result: Exported Gemma 4 31B NVFP4 TP1 cores serve single-image, multi-image (up to 4 images), long-prefix (>2K wraparound) image, multi-turn prefix-cached image, and concurrent 2-request image workloads accurately on a single 96 GiB SM120 GPU with 1,540,096 KV tokens and 148 VMM-aliased GPU shared snapshot slots (`--max-concurrency 4 --image-concurrency 2`, 62 graphs). Existing exported cores embed their compiled graphs and remain wire-compatible (not re-served in this validation). Supporting evidence and limitations: - Unit & CUDA tests (SM120 RTX PRO 6000 Blackwell, GPU 1, base `60411f1` + `local-inference-lab#16` + `local-inference-lab#14`, paired with Core PR `#483` `c3f3311f`): - `tests/components/test_image_sliding_attention_cuda.py`: 8 passed (including BF16 cache parity). - `tests/frontend/test_gemma4_images.py`: 3 passed. - `tests/recipes/test_gemma4.py -k "not test_model_sizes_select_canonical_chat_templates"`: 46 passed, 5 skipped. - End-to-end multimodal serving evidence from pre-split combined `gemma-4-31b-nvfp4` TP1 package `gb202-tp1-202611230337` (`feb712de`, combining `local-inference-lab#14` + `local-inference-lab#15` + `local-inference-lab#16` + PR 4): 7/7 multimodal checks passed, 60.7 GiB KV / 1,540,096 KV tokens / 148 shared snapshot slots. Design-Signed-Off-By: Antigravity (Gemini); design-review=8fdd Signed-off-by: Ricky Brent <ricky@rickybrent.com>
PreparedStateTransfer.prepare() launches `_copy_rows` with grid `(capacity, cdiv(row_bytes, 4096), 1)`. On CUDA devices, `gridDim.y` is capped at 65,535, so continuation rows larger than 256 MiB - 4 KiB (for example, circular sliding-window KV rows of ~405 MiB / 103,683 tiles in FP8 KV or ~810 MiB / 207,363 tiles in BF16 KV on 60-layer Gemma 4 31B TP1 models in companion PR `local-inference-lab/hyperflare-recipes#16`) fail kernel launch with `RuntimeError: Triton Error [CUDA]: invalid argument` during graph warmup and maintenance transfers. Changes: - ignition/components/state_transfer.py: - define named constants `_COPY_BLOCK = 4096`, `_PAGE_BLOCK = 1024`, and `_MAX_GRID_Y = 65_535` (with a single authoritative comment documenting CUDA's 65,535 `gridDim.y` ceiling and 256 MiB - 4 KiB striding threshold), removing duplicated inline block literals; - keep `row = tl.program_id(0)` in `_copy_rows` and stride byte tiles across `tl.program_id(1)` by `tl.num_programs(1) * BLOCK` up to `ROW_BYTES`, preserving direct `_copy_rows[(rows, tiles)](*args)` callers (such as `local-inference-lab/hyperflare-recipes@60411f1:tests/components/test_state_transfer.py`); - cap `PreparedStateTransfer.prepare()`'s `gridDim.y` at `min(tiles, _MAX_GRID_Y)`, so rows up to 256 MiB - 4 KiB (including 128 MiB through 256 MiB - 4 KiB rows such as Gemma 4 31B TP2's 202.5 MiB rows) keep identical single-iteration launch geometry; - reject `pool.layout.row_bytes > (1 << 31) - 1 - _MAX_GRID_Y * _COPY_BLOCK` (1,879,052,287 B, ~1.75 GiB) in `PreparedStateTransfer.__init__` so Triton's signed 32-bit `offset += step` loop induction cannot wrap around `INT32_MAX` (verified in Triton TTIR `scf.for ... : i32` and generated PTX `add.s32` / `setp.lt.s32`); - note on `_copy_pages` that `args[12]` is per-page byte size (one physical KV page), not `row_bytes`. - docs/TODO.txt: record a follow-up item for the 65,535 * 1024 (~64 MiB/uint8 row) `gridDim.y` ceiling in `ignition/components/state.py` row kernels. - tests/components/test_state_transfer.py: add ungated `FakeTensorMode` unit test verifying `PreparedStateTransfer` rejects the first 256-aligned `row_bytes` above `INT32_MAX - 65_535 * 4096` (`1,879,052,288` B) without requiring a CUDA device or `FLARE_RUN_CUDA_TESTS=1`. - tests/components/test_state_transfer_copy_rows_cuda.py: add CUDA-gated tests (using production `_COPY_BLOCK = 4096`, a shared expected-row oracle, and a shared `_replay_and_verify` helper that snapshots the source row before replay and asserts it remains unchanged) covering direct `(row, tile)` launches (`grid_y` in `[8, 3]`, with a deliberately non-tile-aligned excluded span) and parametrized `PreparedStateTransfer.prepare()` + `validate()` + `apply()` across `("total_tiles", "expected_y")` in `[(8, 8), (65_535, 65_535), (_MAX_GRID_Y + 2, 65_535)]` (`32 KiB`, exact `256 MiB - 4 KiB` boundary, and `256 MiB + 4 KiB / 268.4 MB`) with hard-coded independent excluded byte spans and 3 freshly dirtied CUDA graph replays. Claimed result: Continuation rows larger than 256 MiB - 4 KiB copy, reset, and replay inside CUDA graphs without exceeding CUDA's 65,535 `gridDim.y` ceiling — verified at 256 MiB + 4 KiB (65,537 tiles) in unit tests, ~405 MiB (103,683 tiles) in packaged FP8-KV downstream runtimes, and ~810 MiB (207,363 tiles) in end-to-end BF16-KV serving; larger rows between ~810 MiB and the ~1.75 GiB (`1,879,052,287` B) strided-copy offset guard follow from the same capped launch geometry (reasoning, not executed). All continuation rows up to 256 MiB - 4 KiB keep identical launch geometry and behavior; direct `(row, tile)` callers that launch one program per tile keep identical behavior, while callers that launch fewer Y programs than tiles now copy the whole row instead of only the first `grid_y * 4,096` bytes. Existing exported cores are unaffected by construction (reasoning, not an export/reload measurement): this change touches only preparation-time launch geometry in `PreparedStateTransfer.prepare()`, a preparation-time `row_bytes` bound in `PreparedStateTransfer.__init__`, and the `_copy_rows` Triton kernel body, not Helios runtime loading, core wire format, or already-exported graph binaries. Supporting evidence and limitations: - Pre-fix failure on both SM120 (RTX PRO 6000 Blackwell) and SM121 (NVIDIA GB10, aarch64 DGX Spark): launching `_copy_rows[(1, 65_537)]` on a 256 MiB + 4 KiB (268.4 MB) row raises `RuntimeError: Triton Error [CUDA]: invalid argument`. - SM120 (RTX PRO 6000 Blackwell, x86-64 Linux, on `v0.4.0` `5adb27f2`, this commit): - Ungated CPU-only (`CUDA_VISIBLE_DEVICES=0 pytest -v tests/components/test_state_transfer.py tests/components/test_state_transfer_copy_rows_cuda.py tests/preparation/test_core_boundary.py`): 5 passed (strided-copy offset guard + 4 boundary checks), 5 skipped (GPU cases) in 2.85s. - Gated full (`CUDA_HOME=/opt/cuda CUDA_VISIBLE_DEVICES=0 FLARE_RUN_CUDA_TESTS=1 pytest -v tests/components/test_state_transfer.py tests/components/test_state_transfer_copy_rows_cuda.py tests/preparation/test_core_boundary.py tests/preparation/test_source_identity.py`, after rebuilding `flare-heliopause` on `v0.4.0` `5adb27f2`): 21 passed in 4.73s. - External backward-compatibility check (`CUDA_VISIBLE_DEVICES=1 FLARE_RUN_CUDA_TESTS=1 pytest -v tests/components/test_state_transfer.py` against untouched `local-inference-lab/hyperflare-recipes@60411f1`): 7 passed in 3.18s. - SM121 (NVIDIA GB10, aarch64 DGX Spark, PyTorch `2.14.1+cu132`, on `v0.4.0` `5adb27f2`, this commit): - Ungated CPU-only (`pytest -v tests/components/test_state_transfer.py tests/components/test_state_transfer_copy_rows_cuda.py tests/preparation/test_core_boundary.py`): 5 passed, 5 skipped in 4.63s. - Gated (`CUDA_VISIBLE_DEVICES=0 FLARE_RUN_CUDA_TESTS=1 pytest -v tests/components/test_state_transfer.py tests/components/test_state_transfer_copy_rows_cuda.py tests/preparation/test_core_boundary.py`): 10 passed in 21.23s (1 ungated offset guard + 5 CUDA cases + 4 boundary checks). - External (`CUDA_VISIBLE_DEVICES=0 FLARE_RUN_CUDA_TESTS=1 pytest -v hyperflare-recipes/tests/components/test_state_transfer.py`): 7 passed in 3.79s. - End-to-end ~810 MiB BF16-KV serving (SM120x1 RTX PRO 6000 Blackwell, x86-64 Linux, `google/gemma-4-31B-it@842da379` BF16 TP1, `--max-concurrency 4`, 57 graphs, `--kv-cache-dtype bf16`, MTP enabled): exported and served with core stack `NVIDIA/hyperflare-inference@v0.4.0` (`5adb27f2`) + this PR NVIDIA#484 (`rickybrent/hyperflare-inference@core/state-transfer-large-rows` `6463aa58`, whose `_copy_rows` kernel and launch geometry are unchanged by this commit's tightened 1.75 GiB preparation guard) + `rickybrent/hyperflare-inference@core/gemma4-image-frontend` (`c3f3311f`, PR NVIDIA#483 image frontend, unused during text-only checks) and recipe stack `local-inference-lab/hyperflare-recipes@main` (`60411f1`) + `rickybrent/hyperflare-recipes@recipes/gemma4-sliding-window-kv` (`eb7ac17`, PR NVIDIA#16 circular sliding-window KV) + `rickybrent/hyperflare-recipes@recipes/gemma4-bf16-kv` (`39a61a7`, adds `--kv-cache-dtype bf16`, ~810 MiB / 207,363-tile continuation rows). Passed 4,082-token wraparound snapshot/restore (`cached_tokens=4050`) and 53K / 163.8K needle checks (401,408 KV tokens / 38 snapshot slots). - Packaged FP8-KV downstream runtimes: both packaged cores were exported from `rickybrent/hyperflare-inference@gemma4-export` (`53eabcad`, 32,768-tile cap — four iterations per program at ~405 MiB; the shipped 65,535 cap is covered by the 65,537-tile test case) + `rickybrent/hyperflare-recipes@recipes/gemma4-integration` (`08bf07a`), with ~405 MiB (103,683-tile) circular sliding-window continuation rows: - `rickybrent/Gemma-4-31B-IT-NVFP4-HYPERFLARE-TP1-gb202` (SM120, core `gb202-tp1-202611240119`, ~405 MiB continuation rows). - `rickybrent/Gemma-4-31B-IT-NVFP4-HYPERFLARE-TP1-gb10` (SM121, core `gb10-tp1-202611240340`, ~405 MiB continuation rows; 68.5 GiB cache, 1,742,848 KV tokens, 168 snapshot slots; 7/7 vision and 42.8K / 128.4K / 171.1K exact needle checks). - Limitations: SM103 and Windows were not executed on hardware; rows between ~810 MiB and the ~1.75 GiB strided-copy offset guard were not executed; `test_source_identity.py` ran on SM120 only (where `flare-heliopause` was rebuilt for `v0.4.0` `5adb27f2`); and no base-export/branch-reload test was run for existing exported cores. Design-Signed-Off-By: Antigravity (Gemini); design-review=15f3 Signed-off-by: Ricky Brent <ricky@rickybrent.com>
…484) PreparedStateTransfer.prepare() launches `_copy_rows` with grid `(capacity, cdiv(row_bytes, 4096), 1)`. On CUDA devices, `gridDim.y` is capped at 65,535, so continuation rows larger than 256 MiB - 4 KiB (for example, circular sliding-window KV rows of ~405 MiB / 103,683 tiles in FP8 KV or ~810 MiB / 207,363 tiles in BF16 KV on 60-layer Gemma 4 31B TP1 models in companion PR `local-inference-lab/hyperflare-recipes#16`) fail kernel launch with `RuntimeError: Triton Error [CUDA]: invalid argument` during graph warmup and maintenance transfers. Changes: - ignition/components/state_transfer.py: - define named constants `_COPY_BLOCK = 4096`, `_PAGE_BLOCK = 1024`, and `_MAX_GRID_Y = 65_535` (with a single authoritative comment documenting CUDA's 65,535 `gridDim.y` ceiling and 256 MiB - 4 KiB striding threshold), removing duplicated inline block literals; - keep `row = tl.program_id(0)` in `_copy_rows` and stride byte tiles across `tl.program_id(1)` by `tl.num_programs(1) * BLOCK` up to `ROW_BYTES`, preserving direct `_copy_rows[(rows, tiles)](*args)` callers (such as `local-inference-lab/hyperflare-recipes@60411f1:tests/components/test_state_transfer.py`); - cap `PreparedStateTransfer.prepare()`'s `gridDim.y` at `min(tiles, _MAX_GRID_Y)`, so rows up to 256 MiB - 4 KiB (including 128 MiB through 256 MiB - 4 KiB rows such as Gemma 4 31B TP2's 202.5 MiB rows) keep identical single-iteration launch geometry; - reject `pool.layout.row_bytes > (1 << 31) - 1 - _MAX_GRID_Y * _COPY_BLOCK` (1,879,052,287 B, ~1.75 GiB) in `PreparedStateTransfer.__init__` so Triton's signed 32-bit `offset += step` loop induction cannot wrap around `INT32_MAX` (verified in Triton TTIR `scf.for ... : i32` and generated PTX `add.s32` / `setp.lt.s32`); - note on `_copy_pages` that `args[12]` is per-page byte size (one physical KV page), not `row_bytes`. - docs/TODO.txt: record a follow-up item for the 65,535 * 1024 (~64 MiB/uint8 row) `gridDim.y` ceiling in `ignition/components/state.py` row kernels. - tests/components/test_state_transfer.py: add ungated `FakeTensorMode` unit test verifying `PreparedStateTransfer` rejects the first 256-aligned `row_bytes` above `INT32_MAX - 65_535 * 4096` (`1,879,052,288` B) without requiring a CUDA device or `FLARE_RUN_CUDA_TESTS=1`. - tests/components/test_state_transfer_copy_rows_cuda.py: add CUDA-gated tests (using production `_COPY_BLOCK = 4096`, a shared expected-row oracle, and a shared `_replay_and_verify` helper that snapshots the source row before replay and asserts it remains unchanged) covering direct `(row, tile)` launches (`grid_y` in `[8, 3]`, with a deliberately non-tile-aligned excluded span) and parametrized `PreparedStateTransfer.prepare()` + `validate()` + `apply()` across `("total_tiles", "expected_y")` in `[(8, 8), (65_535, 65_535), (_MAX_GRID_Y + 2, 65_535)]` (`32 KiB`, exact `256 MiB - 4 KiB` boundary, and `256 MiB + 4 KiB / 268.4 MB`) with hard-coded independent excluded byte spans and 3 freshly dirtied CUDA graph replays. Claimed result: Continuation rows larger than 256 MiB - 4 KiB copy, reset, and replay inside CUDA graphs without exceeding CUDA's 65,535 `gridDim.y` ceiling — verified at 256 MiB + 4 KiB (65,537 tiles) in unit tests, ~405 MiB (103,683 tiles) in packaged FP8-KV downstream runtimes, and ~810 MiB (207,363 tiles) in end-to-end BF16-KV serving; larger rows between ~810 MiB and the ~1.75 GiB (`1,879,052,287` B) strided-copy offset guard follow from the same capped launch geometry (reasoning, not executed). All continuation rows up to 256 MiB - 4 KiB keep identical launch geometry and behavior; direct `(row, tile)` callers that launch one program per tile keep identical behavior, while callers that launch fewer Y programs than tiles now copy the whole row instead of only the first `grid_y * 4,096` bytes. Existing exported cores are unaffected by construction (reasoning, not an export/reload measurement): this change touches only preparation-time launch geometry in `PreparedStateTransfer.prepare()`, a preparation-time `row_bytes` bound in `PreparedStateTransfer.__init__`, and the `_copy_rows` Triton kernel body, not Helios runtime loading, core wire format, or already-exported graph binaries. Supporting evidence and limitations: - Pre-fix failure on both SM120 (RTX PRO 6000 Blackwell) and SM121 (NVIDIA GB10, aarch64 DGX Spark): launching `_copy_rows[(1, 65_537)]` on a 256 MiB + 4 KiB (268.4 MB) row raises `RuntimeError: Triton Error [CUDA]: invalid argument`. - SM120 (RTX PRO 6000 Blackwell, x86-64 Linux, on `v0.4.0` `5adb27f2`, this commit): - Ungated CPU-only (`CUDA_VISIBLE_DEVICES=0 pytest -v tests/components/test_state_transfer.py tests/components/test_state_transfer_copy_rows_cuda.py tests/preparation/test_core_boundary.py`): 5 passed (strided-copy offset guard + 4 boundary checks), 5 skipped (GPU cases) in 2.85s. - Gated full (`CUDA_HOME=/opt/cuda CUDA_VISIBLE_DEVICES=0 FLARE_RUN_CUDA_TESTS=1 pytest -v tests/components/test_state_transfer.py tests/components/test_state_transfer_copy_rows_cuda.py tests/preparation/test_core_boundary.py tests/preparation/test_source_identity.py`, after rebuilding `flare-heliopause` on `v0.4.0` `5adb27f2`): 21 passed in 4.73s. - External backward-compatibility check (`CUDA_VISIBLE_DEVICES=1 FLARE_RUN_CUDA_TESTS=1 pytest -v tests/components/test_state_transfer.py` against untouched `local-inference-lab/hyperflare-recipes@60411f1`): 7 passed in 3.18s. - SM121 (NVIDIA GB10, aarch64 DGX Spark, PyTorch `2.14.1+cu132`, on `v0.4.0` `5adb27f2`, this commit): - Ungated CPU-only (`pytest -v tests/components/test_state_transfer.py tests/components/test_state_transfer_copy_rows_cuda.py tests/preparation/test_core_boundary.py`): 5 passed, 5 skipped in 4.63s. - Gated (`CUDA_VISIBLE_DEVICES=0 FLARE_RUN_CUDA_TESTS=1 pytest -v tests/components/test_state_transfer.py tests/components/test_state_transfer_copy_rows_cuda.py tests/preparation/test_core_boundary.py`): 10 passed in 21.23s (1 ungated offset guard + 5 CUDA cases + 4 boundary checks). - External (`CUDA_VISIBLE_DEVICES=0 FLARE_RUN_CUDA_TESTS=1 pytest -v hyperflare-recipes/tests/components/test_state_transfer.py`): 7 passed in 3.79s. - End-to-end ~810 MiB BF16-KV serving (SM120x1 RTX PRO 6000 Blackwell, x86-64 Linux, `google/gemma-4-31B-it@842da379` BF16 TP1, `--max-concurrency 4`, 57 graphs, `--kv-cache-dtype bf16`, MTP enabled): exported and served with core stack `NVIDIA/hyperflare-inference@v0.4.0` (`5adb27f2`) + this PR #484 (`rickybrent/hyperflare-inference@core/state-transfer-large-rows` `6463aa58`, whose `_copy_rows` kernel and launch geometry are unchanged by this commit's tightened 1.75 GiB preparation guard) + `rickybrent/hyperflare-inference@core/gemma4-image-frontend` (`c3f3311f`, PR #483 image frontend, unused during text-only checks) and recipe stack `local-inference-lab/hyperflare-recipes@main` (`60411f1`) + `rickybrent/hyperflare-recipes@recipes/gemma4-sliding-window-kv` (`eb7ac17`, PR #16 circular sliding-window KV) + `rickybrent/hyperflare-recipes@recipes/gemma4-bf16-kv` (`39a61a7`, adds `--kv-cache-dtype bf16`, ~810 MiB / 207,363-tile continuation rows). Passed 4,082-token wraparound snapshot/restore (`cached_tokens=4050`) and 53K / 163.8K needle checks (401,408 KV tokens / 38 snapshot slots). - Packaged FP8-KV downstream runtimes: both packaged cores were exported from `rickybrent/hyperflare-inference@gemma4-export` (`53eabcad`, 32,768-tile cap — four iterations per program at ~405 MiB; the shipped 65,535 cap is covered by the 65,537-tile test case) + `rickybrent/hyperflare-recipes@recipes/gemma4-integration` (`08bf07a`), with ~405 MiB (103,683-tile) circular sliding-window continuation rows: - `rickybrent/Gemma-4-31B-IT-NVFP4-HYPERFLARE-TP1-gb202` (SM120, core `gb202-tp1-202611240119`, ~405 MiB continuation rows). - `rickybrent/Gemma-4-31B-IT-NVFP4-HYPERFLARE-TP1-gb10` (SM121, core `gb10-tp1-202611240340`, ~405 MiB continuation rows; 68.5 GiB cache, 1,742,848 KV tokens, 168 snapshot slots; 7/7 vision and 42.8K / 128.4K / 171.1K exact needle checks). - Limitations: SM103 and Windows were not executed on hardware; rows between ~810 MiB and the ~1.75 GiB strided-copy offset guard were not executed; `test_source_identity.py` ran on SM120 only (where `flare-heliopause` was rebuilt for `v0.4.0` `5adb27f2`); and no base-export/branch-reload test was run for existing exported cores. Design-Signed-Off-By: Antigravity (Gemini); design-review=15f3 Signed-off-by: Ricky Brent <ricky@rickybrent.com>
c3f3311 to
4f42d94
Compare
…omic spans
Gemma 4 multimodal checkpoints preprocess images into aspect-preserving 16x16
interleaved RGB patches (768 f32 elements/patch), 2D (x, y) patch coordinates,
3x3 spatial pooling (patches_per_feature = 9, up to 1120 soft tokens), and an
atomic image envelope (start_token, repeated image_token features, end_token).
Previously, Helios had no Gemma 4 image preparation profile,
ImageLayoutKind::Bracketed hardcoded 2x2 merge and 1176 floats/patch, and
Bracketed layouts did not emit atomic image spans.
Changes:
- Wire & contract metadata:
- Add additive ImageSettings.profile tag 11 (Gemma4ImageSettings) and
ImagePreparationKind::Gemma4 (tag 11), plus VisionCapacity.patch_features
(tag 6, serde default 0) and VisionCapabilities::bracketed_patch_features()
to declare per-patch float width in prepared metadata rather than
hardcoding a model-identity table in shared packing.
- Default vision["patch_features"] = 0 in ignition/preparation/contract.py
and document that Bracketed vision recipes with non-1176 widths set it.
- Regenerate ignition/preparation/runtime_core_pb2.py matching main
(Protobuf Python Version: 7.36.1, descriptor-only diff).
- Document the new profile, fixture provenance, patch_features field, and
Bracketed atomic spans in helios/README.md, docs/runtime-core-design.md,
helios/model-contract.md, and docs/TODO.txt.
- Native image preparation & packing:
- Implement helios/src/frontend/images/gemma4.rs (area-bounded uint8
antialiased bicubic resize matching torchvision, 1/255 scaling, interleaved
(y, x, channel) patches, (x, y) positions, shared patch_merge::Envelope,
and per-condition load errors naming failing fields and bounds).
- Derive Bracketed merge stride from square patches_per_feature and patch
width from vision.bracketed_patch_features() (0 defaults to legacy MiniMax
width 1176, which uses 2x temporal duplication: 3 * 2 * 14^2 = 1176).
- Unify per-profile patch widths via ImageProcessor::patch_features()
(delegating Qwen/MiMo/PatchMerge to their dynamic pixel_width() helpers),
fixing conditioned.rs cache validation across all profiles, and add
load-time consistency checks in gemma4::Processor::load and server::config
(single actionable Bracketed patch-width check, patches_per_feature,
per-image patch budget, and max envelope <= prefill_chunk_size and
span.max_tokens).
- Move atomic span emission into layouts/bracketed.rs when image_tokens.span
is declared, removing the fallback in model/prompt.rs.
- Preparation & tests:
- Tighten ignition/preparation/frontend.py to accept any gemma4/gemma4_vision
checkpoint (E2B/E4B/26B-A4B/31B while rejecting gemma4_unified 12B) and
validate envelope tokens from tokenizer_config.json against tokenizer.json
and optional config.json IDs.
- Add checked-in HF reference fixture generator and
tests/frontend/gemma4_images.json (8 bit-exact SHA-256 cases across
max_soft_tokens=280 and 1120), unconditional Rust Envelope::expand /
Bracketed span / legacy Bracketed Inputs::new core-load / cross-profile
width / bootstrap validation tests, #[ignore] checkpoint envelope test, and
tests/preparation/test_frontend_gemma4.py (including fixture provenance
validation).
Verified on origin/main (v0.5.0, 0a8c20f):
- helios frontend::images: 48 passed, 0 failed, 1 ignored
- helios ignored checkpoint envelope test (google/gemma-4-31B-it@842da379): 1 passed
- helios model:: (57 passed, 0 failed), runtime_core::protobuf (29 passed),
server::config (3 passed), flare-cli --test unverified_payload (7 passed)
- helios integration tests --no-run & flare-cli --tests check: passed
- upstream-core pytest (after rebuilding flare-heliopause; core_boundary,
source_identity, frontend_gemma4 incl. fixture provenance and cached
gemma-4-31B-it, Gemma-4-31B-IT-NVFP4, and gemma-4-E2B-it): 23 passed, 0 skipped
- external hyperflare-recipes tests/frontend/test_gemma4_images.py: 3 passed, 0 skipped
Design-Signed-Off-By: Antigravity (Gemini); design-review=2e5b
Signed-off-by: Ricky Brent <ricky@rickybrent.com>
4f42d94 to
445c665
Compare
Gemma 4 sliding-window layers allow each image token to attend over `window ∩ (causal ∪ same-image-block)` (`sliding_window = 1024`), while global layers remain causal. Paged causal prefill attention alone cannot express bidirectional same-image attention, whereas a dense chunk-local SDPA overlay adds O(T^2) overhead to text-only chunks and breaks multi-turn prefix-cache boundaries. Because sliding prefill layers stage the active circular window + current chunk into a contiguous buffer via `PreparedWindowStaging` (or `stage_circular_kv` for BF16 KV), a sparse Triton overlay reading that staged buffer (shifting `positions` and `image_span_end` by each request's first staged position `max(0, start - window)`) handles arbitrary cached prefixes, wraparound, and KV-shared sliding layers, exits immediately on query tiles containing no image tokens, and stays a recipe-side `native_contract` Triton operator captured inside existing `prefill` graphs (introducing no Helios `GraphOperation` family or runtime operation contract). This PR stacks on `local-inference-lab#16` (`recipes/gemma4-sliding-window-kv`) and `local-inference-lab#14` (`recipes/gemma4-vision-encoder`) and requires companion core PR `NVIDIA/hyperflare-inference#483` (`core/gemma4-image-frontend`) for native Gemma 4 image preprocessing, 3x3 bracketed packing (`patch_features = 768`), and atomic image spans. Changes: - hyperflare_recipes/components/image_sliding_attention.py: add `compute_image_sliding_spans` (O(T) pure-tensor reverse-cummin span calculation shared across all sliding layers) and `PreparedImageSlidingAttention` (`flare.image_sliding_attention` recipe-side `native_contract` Triton operator accepting both FP8 E4M3 and BF16 paged/staged K/V caches, optional unbound `k_cache`/`v_cache`, overwriting only image rows in place and exiting early on text-only tiles). - hyperflare_recipes/recipes/gemma4/{vision_state,config,weights, contract,attention,decoder,bootstrap,recipe}.py: wire `VisionInputs`, `PreparedVisionGeneration` (5 vision graphs for capacities 630..10080), `VisionParameters(separable_encoder=True)` on `Gemma4Parameters`, `VISION["patch_features"] = 768` matching `#483`, BF16 vision tower loading (with `--language-model-only` and `--image-concurrency` opt-out), vision feature injection after text embedding scaling, per-prefill staged span offset calculation in `PreparedDecoder`, and `PreparedImageSlidingAttention` over the staged output in `PreparedAttention`. Include `"vision"` in the compilation identity hash. - tests/components/test_image_sliding_attention_cuda.py: add 8 SM120 CUDA tests covering FP8 and BF16 paged/staged circular-window parity across early, pre-wrap, 1,500-token wraparound, 1,120-token window-clipped images, poisoned 0x7F ring slots, multi-request heterogeneous starts, and CUDA graph capture/replay with text-only early exit. - tests/frontend/test_gemma4_images.py: add 3 frontend metadata and atomic-token validation tests against `ignition.preparation.frontend`. Claimed result: Exported Gemma 4 31B NVFP4 TP1 cores serve single-image, multi-image (up to 4 images), long-prefix (>2K wraparound) image, multi-turn prefix-cached image, and concurrent 2-request image workloads accurately on a single 96 GiB SM120 GPU with 1,540,096 KV tokens and 148 VMM-aliased GPU shared snapshot slots (`--max-concurrency 4 --image-concurrency 2`, 62 graphs). Existing exported cores embed their compiled graphs and remain wire-compatible (not re-served in this validation). Supporting evidence and limitations: - Unit & CUDA tests (SM120 RTX PRO 6000 Blackwell, GPU 1, base `60411f1` + `local-inference-lab#16` + `local-inference-lab#14`, paired with Core PR `#483` `c3f3311f`): - `tests/components/test_image_sliding_attention_cuda.py`: 8 passed (including BF16 cache parity). - `tests/frontend/test_gemma4_images.py`: 3 passed. - `tests/recipes/test_gemma4.py -k "not test_model_sizes_select_canonical_chat_templates"`: 46 passed, 5 skipped. - End-to-end multimodal serving evidence from pre-split combined `gemma-4-31b-nvfp4` TP1 package `gb202-tp1-202611230337` (`feb712de`, combining `local-inference-lab#14` + `local-inference-lab#15` + `local-inference-lab#16` + PR 4): 7/7 multimodal checks passed, 60.7 GiB KV / 1,540,096 KV tokens / 148 shared snapshot slots. Design-Signed-Off-By: Antigravity (Gemini); design-review=6fcc Signed-off-by: Ricky Brent <ricky@rickybrent.com>
Why
Gemma 4 multimodal checkpoints preprocess images into aspect-preserving 16×16 interleaved RGB patches (
768f32 elements per patch), 2D(x, y)patch coordinates, 3×3 spatial pooling (patches_per_feature = 9, up to1,120soft tokens per image), and an atomic image envelope (start_token, repeatedimage_tokenfeatures,end_token). Previously, Helios had no Gemma 4 image preparation profile,ImageLayoutKind::Bracketedhardcoded 2×2 merge (patches_per_feature = 4) and 1,176 floats/patch, andBracketedlayouts did not emit atomic image spans when declared byImageTokenLayout.span. Without this, Gemma 4 multimodal cores cannot prepare or load native image processing,Bracketedvision uploads cannot pack 3×3 / 768-float patches, and a span-declaringBracketedimage fails per-request atvalidate_prompt_data(or hits per-request chunk-size rejections rather than failing at load when the maximum image envelope exceedsprefill_chunk_sizeorspan.max_tokens).What changed
helios/proto/runtime_core.proto,helios/build.rs,ignition/preparation/runtime_core_pb2.py,ignition/preparation/contract.py,helios/src/model.rs,helios/src/model/contract.rs,helios/src/runtime_core/{describe,protobuf}.rs,docs/runtime-core-design.md,helios/README.md,helios/model-contract.md,docs/TODO.txt):ImageSettings.profiletag 11 (Gemma4ImageSettings),ImagePreparationKind::Gemma4(tag 11),VisionCapacity.patch_features(tag 6,#[serde(default)],0= legacyBracketedwidth1176), andVisionCapabilities::bracketed_patch_features().vision["patch_features"] = 0inignition/preparation/contract.pyand documented thatBracketedvision recipes with non-1176 patch widths set it.ignition/preparation/runtime_core_pb2.pymatchingorigin/main(Protobuf Python Version: 7.36.1, pure descriptor-only diff).VisionCapabilities::validate()to allow0(legacy default) and reject nonzero widths that are not positive multiples of 3, and added a protobuf round-trip test verifying serialized Gemma 4 settings select only image preparation.Bracketedpacking, and load-time validation (helios/src/frontend/images/{gemma4,mod,conditioned,packing,patch_merge}.rs,helios/src/model/packing.rs,helios/src/server/config.rs):helios/src/frontend/images/gemma4.rs(area-bounded uint8 antialiased bicubic resize matching PyTorch/torchvision,1/255scaling, interleaved(y, x, channel)16×16 patches,(x, y)patch coordinates, sharedpatch_merge::Envelopeexpansion, and per-condition load errors naming failing fields and bounds).patches_per_feature -> widthlookup table inpacking.rs:Bracketednow reads per-patch float width viaVisionCapabilities::bracketed_patch_features()(0defaults to legacy MiniMax temporal-merge width3 * 2 * 14² = 1176, which cannot be derived from3 * patch_size²alone because MiniMax duplicates frames temporally) and derives merge stride from any positive squarepatches_per_feature.ImageProcessor::patch_features()(fixingconditioned.rscache validation across all profiles, includingPaddedGrid = 1200andPatchMerge = 1176) and added cross-profile consistency test coverage.gemma4::Processor::loadverifiespooling_kernel_size² == limits.patches_per_featureandmax_soft_tokens * pooling_kernel_size² <= limits.max_patches_per_image, andserver::config::validate_loaded_image_processorchecksprocessor.patch_features()againstvision.bracketed_patch_features()(single actionable re-export error for anyBracketedmismatch) or nonzerovision.patch_featuresfor other layouts, plusmax_image_envelope_tokens <= prefill_chunk_sizeand<= image_tokens.span.max_tokens.helios/src/frontend/images/layouts/bracketed.rs,helios/src/model/prompt.rs):layouts::bracketed::prepare_input(matchinglayouts::deepseek), gated onimage_tokens.span.is_some()and validating prompt bounds on both ends; deleted the fallback block inmodel/prompt.rs.ignition/preparation/frontend.py,tests/frontend/generate_gemma4_image_fixtures.py,tests/frontend/gemma4_images.json,tests/preparation/test_frontend_gemma4.py,helios/src/model/tests.rs):ignition/preparation/frontend.pyto accept anymodel_type: "gemma4"/vision_config.model_type: "gemma4_vision"checkpoint (E2B,E4B,26B-A4B,31B) while rejectinggemma4_unified(12B), and to validateimage_token,boi_token, andeoi_tokenfromtokenizer_config.jsonagainsttokenizer.jsonand optionalconfig.jsontoken IDs (failing closed iftokenizer_configorsnapshotis omitted).tests/frontend/generate_gemma4_image_fixtures.pyandtests/frontend/gemma4_images.json(8 bit-exact SHA-256 cases acrossmax_soft_tokens = 280and1120) verified unconditionally under plaincargo test(with itsprocessorandmodelprovenance blocks verified intests/preparation/test_frontend_gemma4.py), added unconditional pure-RustEnvelope::expand,Bracketedspan-bearing contract, and legacyBracketedInputs::newcore-load tests, and kept the live-tokenizer envelope test#[ignore]with explicit assertions.Claimed result
Helios natively decodes, resizes, normalizes, packs, and validates Gemma 4 images with bit-exact SHA-256 pixel, resize, and
(x, y)position parity against Hugging Face'sGemma4ImageProcessor, enforces patch-width and atomic-span invariants at load time, and emits atomic spans from theBracketedlayout.Load-path impact on existing cores: MiniMax (
Bracketed+PatchMerge) and all non-Bracketedupstream cores remain loadable and unchanged (missingpatch_featuresdecodes as0, which preserves the legacy1176width forBracketed— covered bylegacy_bracketed_core_omitting_patch_features_loads_and_stages_1176_wide_pixelsthroughInputs::new; the envelope bound check applies only to profiles exposingmax_image_envelope_tokens, i.e., Gemma 4; among existing span-declaring layouts in-tree,Deepseek/DeepseekRowMajorcontinue emitting their owndata.spans). Narrowings:Bracketednow requires a positive-squarepatches_per_feature, and any Gemma 4 core prepared before this change (withpatch_features == 0) is rejected at load with an actionable error (bracketed image layout patch width (1176) differs from image processor (768); re-export the core with vision.patch_features).Supporting evidence and limitations
Verified on
origin/main(v0.5.00a8c20f4, commit445c6658):cargo test --offline --locked --manifest-path helios/Cargo.toml --features runtime-core,server,test-tools --lib frontend::images: 48 passed, 0 failed, 1 ignored (includes unconditional 8-case HF SHA-256 fixture parity acrossmax_soft_tokens=280and1120, S1/S3 load rejections, 11-profile width consistency,Bracketedbehavioral packing, pure-RustEnvelope::expand, and upstream70e0f4a8'spatch_merge_materializes_and_caches_with_exact_pixel_width).tokenizer.jsonandtokenizer_config.jsonfromgoogle/gemma-4-31B-itat842da3794eaa0b77d5f08bae87a17459d91ff475):FLARE_GEMMA4_TEST_SNAPSHOT=/path/to/gemma-4-31B-it-snapshot cargo test --offline --locked --manifest-path helios/Cargo.toml --features runtime-core,server,test-tools --lib -- --ignored --exact frontend::images::gemma4::tests::checkpoint_tokens_expand_the_image_envelope: 1 passed, 0 failed.cargo test --offline --locked --manifest-path helios/Cargo.toml --features runtime-core,server,test-tools --lib model::: 57 passed, 0 failed (includinglegacy_bracketed_core_omitting_patch_features_loads_and_stages_1176_wide_pixelsthroughInputs::newand span/chunk-size rejections).cargo test --offline --locked --manifest-path helios/Cargo.toml --features runtime-core,server,test-tools --lib runtime_core::protobuf: 29 passed, 0 failed (including Gemma 4 profile round-trip).cargo test --offline --locked --manifest-path helios/Cargo.toml --features runtime-core,server,test-tools --lib server::config: 3 passed, 0 failed (bootstrappatch_features, 64-alignedprefill_chunk_size, andspan.max_tokensboundary checks).cargo test --offline --locked --manifest-path flare-cli/Cargo.toml --test unverified_payload: 7 passed, 0 failed.cargo test --offline --locked --manifest-path helios/Cargo.toml --features runtime-core,server,test-tools --tests --no-runandcargo check --offline --locked --manifest-path flare-cli/Cargo.toml --tests: passed.flare-heliopause(uv pip install --offline --python .venv/bin/python --no-deps --reinstall ./heliopause) and ranHF_HUB_CACHE=... CUDA_VISIBLE_DEVICES="" .venv/bin/pytest -v tests/preparation/test_core_boundary.py tests/preparation/test_source_identity.py tests/preparation/test_frontend_gemma4.py: 23 passed, 0 skipped in 2.89s (validating synthetic E2B-sized towers,gemma4_unified12B rejection, bad envelope tokens, checked-ingemma4_images.jsonprovenance blocks, plus local cached checkpoints; cached checkpoint cases are not part of CI).hyperflare-recipes(recipes/gemma4-vision-wiringd15e059,HF_HUB_CACHE=... .venv/bin/pytest -v tests/frontend/test_gemma4_images.py): 3 passed, 0 skipped.local-inference-lab/hyperflare-recipes, this core profile lands ahead of its companion Gemma 4 vision recipe PR (recipes/gemma4-vision-wiring, which declaresvision.patch_features = 768), tracked indocs/TODO.txtalongside E2B/E4B/26B-A4B serving qualification and partial-span prefix-cache audit.Branch logistics
NVIDIA/hyperflare-inferencerickybrent:core/gemma4-image-frontend(445c6658) targetingmain(0a8c20f4,v0.5.0).Discord: ran.cossack