Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,11 @@

[ ] Guard or stride the 65,535 * 1024 (~64 MiB/uint8 row) gridDim.y ceiling
in ignition/components/state.py row kernels.

[ ] Qualify Gemma 4 vision end-to-end once the companion Gemma 4 vision recipe
is wired (declaring `vision.patch_features = 768` alongside the
`ImageLayoutKind::Bracketed` + `ImagePreparationKind::Gemma4` contract):
verify E2B, E4B, 26B-A4B, and 31B checkpoints through export and native
serving (Gemma 4 12B uses `gemma4_unified` and is outside this profile),
and audit prefix-cache behavior when a cached prefix ends inside an atomic
image envelope (partial-span cache hit).
19 changes: 14 additions & 5 deletions docs/runtime-core-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,17 @@ Two prepared-contract fields fail validation when absent or out of
range. `vision` (Protobuf message `VisionCapacity`, Rust type
`VisionCapabilities`) must decode to a well-formed value: a
text-only core encodes the explicit all-zero value (`feature_slots`,
`features_per_request`, `max_images`, and `patches_per_feature` of 0
with empty `patch_capacities`), and an absent or null `vision` fails
the contract decode (a null submessage raises `invalid type: null,
expected struct VisionCapabilities`). Every graph contract also carries
`features_per_request`, `max_images`, `patches_per_feature`, and
`patch_features` of 0 with empty `patch_capacities`), and an absent or null
`vision` fails the contract decode (a null submessage raises
`invalid type: null, expected struct VisionCapabilities`). For vision cores
using `ImageLayoutKind::Bracketed`, `patch_features` declares the per-patch
float width of `vision_pixel_values` (for example `768` for 16×16 RGB Gemma 4
patches); `0` defaults to the legacy temporal-merge width (`1176`) for existing
cores. At server bootstrap, Helios also verifies that the loaded image
processor's patch width, `patches_per_feature`, per-image patch budget, and
maximum bracketed envelope span agree with the prepared contract and
`prefill_chunk_size`. Every graph contract also carries
`embedding_tables`, whose entries index the core's embedding-table
catalog and are validated against the catalog size at core
validation: a core that ships no embedding-table resources must
Expand Down Expand Up @@ -227,7 +234,9 @@ remains request-controlled.
chat template, and optional image settings. Qwen image settings contain resize
area limits, learned-position geometry, and image/video token IDs. MiMo image
settings contain resize limits and channel normalization. DeepSeek's image profile
has fixed geometry validated by Ignition. Preparation reads and validates structural
has fixed geometry validated by Ignition. Gemma 4 image settings contain patch
and pooling geometry, the soft-token budget, and the validated envelope token
strings (`image_token`, `start_token`, `end_token`). Preparation reads and validates structural
checkpoint config files, then exports only these consumed fields. The only frontend
payload assets are `tokenizer.json` and the Jinja chat template; raw generation,
tokenizer, processor, and model configuration files are not included.
Expand Down
1 change: 1 addition & 0 deletions flare-cli/tests/unverified_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn publish_configured(
max_images: 4,
patches_per_feature: 3,
patch_capacities: vec![64, 128],
patch_features: 0,
}),
frontend: Some(runtime_wire::FrontendContract {
tools: Some(runtime_wire::ToolParser {
Expand Down
42 changes: 32 additions & 10 deletions helios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -729,19 +729,28 @@ The `images` feature adds `frontend::images::ImageProcessor` and PNG, JPEG,
static WebP, and non-animated GIF decoding; it also enables `frontend`. Typed core metadata
selects the preparation profile and token layout independently. Profiles cover
Qwen, MiMo, patch-merge, DeepSeek, DeepSeek row-major, Moonvit, Step, RADIO,
and GLM inputs.
GLM, padded-grid, and Gemma 4 inputs.
The Qwen processor uses an RGB8, bicubic-antialias profile with
16×16 patches, temporal duplication by two, spatial merge by two, a 48×48
learned position table, and fused normalization `(pixel - 127.5) / 127.5`.

`process` produces packed `pixel_values[N,1536]` float32, image grids `[1,H,W]`,
The Gemma 4 processor uses area-bounded RGB8 bicubic-antialias resize to
multiples of `patch_size * pooling_kernel_size` (48 px for 16×16 patches and
3×3 pooling), packs interleaved `(y, x, channel)` float32 patch vectors of width
`3 * patch_size²` (768) scaled by `1/255`, emits `[x, y]` patch coordinates, and
reuses the bracketed start/feature/end token envelope; when the prepared
contract declares `image_tokens.span`, the bracketed layout emits atomic spans
covering each envelope.

For Qwen, `process` produces packed `pixel_values[N,1536]` float32, image grids `[1,H,W]`,
vision positions `[N,2]` int64, interpolation indices `[N,4]` int64 and weights
`[N,4]` float32, and per-image cumulative patch offsets int32. Patch features
are ordered by channel, temporal copy, pixel row, and pixel column; patches
are ordered by 2×2 spatial merge blocks. `expand_prompt` consumes the rendered
chat token IDs, expands only control-token image placeholders, and returns
modality IDs and four unpadded position rows `[text,T,H,W]` plus the mRoPE delta.
The model scheduler can transpose the last three rows into `[tokens,3]`.
`[N,4]` float32, and per-image cumulative patch offsets int32 (other profiles
report their own per-patch width via `ImageProcessor::patch_features()`). Qwen
patch features are ordered by channel, temporal copy, pixel row, and pixel
column; patches are ordered by 2×2 spatial merge blocks. `expand_prompt`
consumes the rendered chat token IDs, expands only control-token image
placeholders, and returns modality IDs and four unpadded position rows
`[text,T,H,W]` plus the mRoPE delta. The model scheduler can transpose the last
three rows into `[tokens,3]`.

Prompt construction describes each image without building its tensors. The
description includes geometry, semantic identity, token dependency span, and
Expand Down Expand Up @@ -807,5 +816,18 @@ cargo run --manifest-path helios/Cargo.toml --features images,test-tools --offli
The qualifier accepts an optional third argument for writing mismatching
native tensor bytes. Fixtures contain fingerprints rather than the full
100 MiB largest patch tensor; the generator's `--binary-dir` records full
reference tensors for diagnosis. These checks qualify CPU preparation; vision
reference tensors for diagnosis.

Gemma 4 fixtures in `tests/frontend/gemma4_images.json` pin Transformers
`5.23.0`, PyTorch `2.14.1+cu132`, Torchvision `0.29.1+cu132`, and
`google/gemma-4-31B-it` at revision `842da3794eaa0b77d5f08bae87a17459d91ff475`
across 8 bit-exact SHA256 cases (`max_soft_tokens` 280 and 1120), regenerated
with:

```bash
.venv/bin/python tests/frontend/generate_gemma4_image_fixtures.py \
"$SNAPSHOT" tests/frontend/gemma4_images.json
```

These checks qualify CPU preparation; vision
graph execution and decoder consumption require separate model integration.
4 changes: 4 additions & 0 deletions helios/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ fn main() {
".flare.runtime.PersistentWorker.metrics_count",
"#[serde(default)]",
)
.field_attribute(
".flare.runtime.VisionCapacity.patch_features",
"#[serde(default)]",
)
.compile_protos(&["proto/runtime_core.proto"], &["proto"])
.expect("compile runtime core protobuf schema");
// The payload schema imports the execution schema and refers to the generated types
Expand Down
2 changes: 1 addition & 1 deletion helios/model-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ serving contract and replay path unchanged.
| `version` | Semantic contract version, 1, 2, or 3; exporters write 3 |
| `vocabulary` | Valid sampled token range and histogram/mask geometry |
| `input_vocabulary` | Valid input range, including declared nonsampled image sentinels |
| `vision` | Feature-slot and per-window feature capacities, patch-to-feature ratio, and captured patch capacities |
| `vision` | Feature-slot and per-window feature capacities, patch-to-feature ratio, captured patch capacities, and per-patch feature width (`patch_features`, where `0` defaults to the legacy `Bracketed` width `1176`) |
| `cache` | Logical page tokens, attention-history storage, and page-table views |
| `graphs` | Per-program operation, value bindings, persistent-state accesses, and resource dependencies |
| `frontend` | Independent parser and image implementation identifiers plus their syntax and layout data |
Expand Down
12 changes: 12 additions & 0 deletions helios/proto/runtime_core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ message VisionCapacity {
uint64 max_images = 2;
uint64 patches_per_feature = 3;
repeated uint64 patch_capacities = 4;
// Float32 elements per vision patch; zero inherits the layout's legacy width.
uint64 patch_features = 6;
}
enum HistoryKind {
HISTORY_UNSPECIFIED = 0;
Expand Down Expand Up @@ -484,6 +486,7 @@ enum ImagePreparationKind {
GLM_IMAGE_PREPARATION = 8;
PATCH_MERGE_IMAGE_PREPARATION = 9;
PADDED_GRID_IMAGE_PREPARATION = 10;
GEMMA4_IMAGE_PREPARATION = 11;
}
enum ImageLayoutKind {
IMAGE_LAYOUT_UNSPECIFIED = 0;
Expand Down Expand Up @@ -619,6 +622,7 @@ message ImageSettings {
Empty glm = 8;
PatchMergeImageSettings patch_merge = 9;
Empty padded_grid = 10;
Gemma4ImageSettings gemma4 = 11;
}
}
message PatchMergeImageSettings {
Expand All @@ -631,6 +635,14 @@ message PatchMergeImageSettings {
string start_token = 7;
string end_token = 8;
}
message Gemma4ImageSettings {
uint32 patch_size = 1;
uint32 pooling_kernel_size = 2;
uint32 max_soft_tokens = 3;
string image_token = 4;
string start_token = 5;
string end_token = 6;
}
message DeepseekRowMajorImageSettings {
uint64 min_pixels = 1;
uint64 max_tokens = 2;
Expand Down
26 changes: 14 additions & 12 deletions helios/src/frontend/images/conditioned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,7 @@ impl PreparedImageInput {

fn valid_processed(&self, images: &ProcessedImages) -> bool {
use super::Profile;
let pixel_width = match &self.processor.profile {
Profile::Qwen(profile) => profile.patches.pixel_width(),
Profile::MiMo(profile) => profile.pixel_width(),
Profile::PatchMerge(profile) => profile.patches.pixel_width(),
Profile::Radio => 768,
Profile::Glm => 1176,
Profile::PaddedGrid => super::padded_grid::FEATURES,
Profile::DeepSeek4
| Profile::DeepseekRowMajor(_)
| Profile::Moonvit
| Profile::Step => 588,
};
let pixel_width = self.processor.patch_features();
let patches = self.geometry.patches;
let interpolation = matches!(
self.processor.profile,
Expand Down Expand Up @@ -373,16 +362,29 @@ mod tests {
ImageSettings::Radio {},
ImageSettings::Glm {},
ImageSettings::PaddedGrid {},
ImageSettings::Gemma4(crate::frontend::images::Gemma4ImageSettings {
patch_size: 16,
pooling_kernel_size: 3,
max_soft_tokens: 280,
image_token: "<|image|>".into(),
start_token: "<|image>".into(),
end_token: "<image|>".into(),
}),
]
}

fn processor(settings: ImageSettings) -> Arc<ImageProcessor> {
let patches_per_feature = match &settings {
ImageSettings::Gemma4(gemma4) => gemma4.pooling_kernel_size * gemma4.pooling_kernel_size,
_ => 1,
};
Arc::new(
ImageProcessor::load(
settings,
ImageLimits {
max_patches_per_image: 65536,
max_total_patches: 65536,
patches_per_feature,
..Default::default()
},
)
Expand Down
Loading