From 445c665824d0486b816371f3414b91068574b193 Mon Sep 17 00:00:00 2001 From: Ricky Brent Date: Sun, 22 Nov 2026 21:57:22 -0800 Subject: [PATCH] Add Gemma 4 image preparation, Bracketed patch-width metadata, and atomic 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, 0a8c20f4): - 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 --- docs/TODO.txt | 8 + docs/runtime-core-design.md | 19 +- flare-cli/tests/unverified_payload.rs | 1 + helios/README.md | 42 +- helios/build.rs | 4 + helios/model-contract.md | 2 +- helios/proto/runtime_core.proto | 12 + helios/src/frontend/images/conditioned.rs | 26 +- helios/src/frontend/images/gemma4.rs | 504 ++++++++++++++++++ .../src/frontend/images/layouts/bracketed.rs | 24 +- helios/src/frontend/images/mod.rs | 42 ++ helios/src/frontend/images/packing.rs | 281 +++++++++- helios/src/frontend/images/patch_merge.rs | 188 +++++-- helios/src/model.rs | 15 + helios/src/model/contract.rs | 2 +- helios/src/model/packing.rs | 1 + helios/src/model/prompt.rs | 127 ++++- helios/src/model/tests.rs | 178 +++++++ helios/src/runtime_core/describe.rs | 12 +- helios/src/runtime_core/protobuf.rs | 60 +++ helios/src/scheduler/boundary_tests.rs | 1 + helios/src/scheduler/cache_memory.rs | 1 + helios/src/scheduler/tests.rs | 4 + helios/src/scheduler/vision_window_tests.rs | 1 + helios/src/server/config.rs | 144 ++++- helios/src/server/models.rs | 2 + helios/src/server/protocol/decode.rs | 1 + helios/src/server/request.rs | 3 +- helios/src/server/request/tml_tests.rs | 1 + helios/src/server/runtime.rs | 2 + helios/src/server/runtime/phase_tests.rs | 7 + helios/tests/deepseek_requests.rs | 1 + ignition/preparation/contract.py | 8 +- ignition/preparation/frontend.py | 76 ++- ignition/preparation/runtime_core_pb2.py | 346 ++++++------ tests/frontend/gemma4_images.json | 256 +++++++++ .../generate_gemma4_image_fixtures.py | 94 ++++ tests/preparation/test_frontend_gemma4.py | 257 +++++++++ 38 files changed, 2493 insertions(+), 260 deletions(-) create mode 100644 helios/src/frontend/images/gemma4.rs create mode 100644 tests/frontend/gemma4_images.json create mode 100644 tests/frontend/generate_gemma4_image_fixtures.py create mode 100644 tests/preparation/test_frontend_gemma4.py diff --git a/docs/TODO.txt b/docs/TODO.txt index e975fce8c..cec864328 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -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). diff --git a/docs/runtime-core-design.md b/docs/runtime-core-design.md index 2b2c86c35..21567656e 100644 --- a/docs/runtime-core-design.md +++ b/docs/runtime-core-design.md @@ -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 @@ -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. diff --git a/flare-cli/tests/unverified_payload.rs b/flare-cli/tests/unverified_payload.rs index b64f43bbf..e7a73a0fa 100644 --- a/flare-cli/tests/unverified_payload.rs +++ b/flare-cli/tests/unverified_payload.rs @@ -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 { diff --git a/helios/README.md b/helios/README.md index b10957132..ca1aca79f 100644 --- a/helios/README.md +++ b/helios/README.md @@ -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 @@ -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. diff --git a/helios/build.rs b/helios/build.rs index 047460407..898717700 100644 --- a/helios/build.rs +++ b/helios/build.rs @@ -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 diff --git a/helios/model-contract.md b/helios/model-contract.md index 3c24c8216..9d60db330 100644 --- a/helios/model-contract.md +++ b/helios/model-contract.md @@ -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 | diff --git a/helios/proto/runtime_core.proto b/helios/proto/runtime_core.proto index 48b4be621..b09bbfa06 100644 --- a/helios/proto/runtime_core.proto +++ b/helios/proto/runtime_core.proto @@ -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; @@ -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; @@ -619,6 +622,7 @@ message ImageSettings { Empty glm = 8; PatchMergeImageSettings patch_merge = 9; Empty padded_grid = 10; + Gemma4ImageSettings gemma4 = 11; } } message PatchMergeImageSettings { @@ -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; diff --git a/helios/src/frontend/images/conditioned.rs b/helios/src/frontend/images/conditioned.rs index 41a2ed467..202a821da 100644 --- a/helios/src/frontend/images/conditioned.rs +++ b/helios/src/frontend/images/conditioned.rs @@ -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, @@ -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: "".into(), + }), ] } fn processor(settings: ImageSettings) -> Arc { + 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() }, ) diff --git a/helios/src/frontend/images/gemma4.rs b/helios/src/frontend/images/gemma4.rs new file mode 100644 index 000000000..8addc8027 --- /dev/null +++ b/helios/src/frontend/images/gemma4.rs @@ -0,0 +1,504 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2026 Flare community contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +//! Gemma 4 area-bounded resize, interleaved RGB patch packing, and envelopes. + +use super::patch_merge::Envelope; +use super::*; + +// Discrete budgets from Hugging Face's `image_processor.max_soft_tokens` +// (validated here as wire-level defense-in-depth alongside Ignition's checkpoint gate). +const SUPPORTED_SOFT_TOKENS: [usize; 5] = [70, 140, 280, 560, 1120]; + +#[derive(Clone)] +pub(super) struct Processor { + limits: ImageLimits, + patch_size: usize, + pooling: usize, + max_soft_tokens: usize, + envelope: Envelope, +} + +impl Processor { + pub(super) fn load(settings: Gemma4ImageSettings, limits: ImageLimits) -> Result { + // Defensive wire caps prevent pathological patch/pooling allocations from malformed payloads. + if settings.patch_size == 0 || settings.patch_size > 64 { + return Err(format!( + "Gemma 4 patch_size ({}) must be in 1..=64", + settings.patch_size + ) + .into()); + } + if settings.pooling_kernel_size == 0 || settings.pooling_kernel_size > 16 { + return Err(format!( + "Gemma 4 pooling_kernel_size ({}) must be in 1..=16", + settings.pooling_kernel_size + ) + .into()); + } + if !SUPPORTED_SOFT_TOKENS.contains(&settings.max_soft_tokens) { + return Err(format!( + "unsupported Gemma 4 max_soft_tokens ({}); expected one of {:?}", + settings.max_soft_tokens, SUPPORTED_SOFT_TOKENS + ) + .into()); + } + let pooling_area = settings + .pooling_kernel_size + .checked_mul(settings.pooling_kernel_size) + .ok_or("Gemma 4 pooling area overflow")?; + if pooling_area != limits.patches_per_feature { + return Err(format!( + "Gemma 4 pooling area ({}x{} = {pooling_area}) differs from prepared patches_per_feature ({})", + settings.pooling_kernel_size, + settings.pooling_kernel_size, + limits.patches_per_feature + ) + .into()); + } + let max_patches = settings + .max_soft_tokens + .checked_mul(pooling_area) + .ok_or("Gemma 4 max patch budget overflow")?; + if max_patches > limits.max_patches_per_image { + return Err(format!( + "Gemma 4 max patch budget ({} * {pooling_area} = {max_patches}) exceeds prepared max_patches_per_image ({})", + settings.max_soft_tokens, limits.max_patches_per_image + ) + .into()); + } + let envelope = Envelope::load( + settings.image_token, + settings.start_token, + settings.end_token, + )?; + Ok(Self { + limits, + patch_size: settings.patch_size, + pooling: settings.pooling_kernel_size, + max_soft_tokens: settings.max_soft_tokens, + envelope, + }) + } + + pub(super) fn patch_features(&self) -> usize { + 3 * self.patch_size * self.patch_size + } + + pub(super) fn max_envelope_tokens(&self) -> usize { + self.max_soft_tokens + 2 + } + + fn side_multiple(&self) -> usize { + self.patch_size * self.pooling + } + + fn max_patches(&self) -> usize { + self.max_soft_tokens * self.pooling * self.pooling + } + + pub(super) fn geometry(&self, width: usize, height: usize) -> Result { + check_input_extent(self.limits, width, height)?; + let patches_per_image = self.max_patches(); + let side = self.side_multiple(); + let target_pixels = (patches_per_image * self.patch_size * self.patch_size) as f64; + let source_pixels = (width as f64) * (height as f64); + let factor = (target_pixels / source_pixels).sqrt(); + let ideal_height = factor * height as f64; + let ideal_width = factor * width as f64; + let mut target_height = (ideal_height / side as f64).floor() as usize * side; + let mut target_width = (ideal_width / side as f64).floor() as usize * side; + if target_height == 0 && target_width == 0 { + return Err(Error::frontend(FrontendError::Input(Failure::new( + "image resizes below one Gemma 4 patch group", + )))); + } + if target_height == 0 { + target_height = side; + target_width = (width / height).min(self.max_soft_tokens) * side; + } else if target_width == 0 { + target_width = side; + target_height = (height / width).min(self.max_soft_tokens) * side; + } + if target_height * target_width > target_pixels as usize { + return Err(Error::frontend(FrontendError::Input(Failure::new( + "Gemma 4 resize exceeds the soft-token budget", + )))); + } + let grid_h = target_height / self.patch_size; + let grid_w = target_width / self.patch_size; + let patches = grid_h * grid_w; + check_image_patches(self.limits, patches)?; + Ok(ImageGeometry { + height: target_height, + width: target_width, + grid_thw: [1, grid_h as i64, grid_w as i64], + patches, + tokens: patches / (self.pooling * self.pooling), + }) + } + + pub(super) fn resized_rgb(&self, image: &RgbImage) -> Result<(ImageGeometry, Vec)> { + let geometry = self.geometry(image.width, image.height)?; + Ok(( + geometry, + resize::resize(image, geometry.width, geometry.height), + )) + } + + pub(super) fn process(&self, images: &[RgbImage]) -> Result { + self.limits.check_batch(images.len(), 0)?; + let geometry: Vec<_> = images + .iter() + .map(|image| self.geometry(image.width, image.height)) + .collect::>()?; + let total: usize = geometry + .iter() + .try_fold(0usize, |sum, image| sum.checked_add(image.patches)) + .ok_or_else(|| { + Error::frontend(FrontendError::Input(Failure::new("patch count overflow"))) + })?; + self.limits.check_batch(images.len(), total)?; + let patch_features = self.patch_features(); + let mut result = ProcessedImages { + pixel_values: Vec::with_capacity(total.checked_mul(patch_features).ok_or( + Error::frontend(FrontendError::Input(Failure::new( + "patch buffer extent overflow", + ))), + )?), + geometry, + position_ids: Vec::with_capacity(total), + interpolation_indices: Vec::new(), + interpolation_weights: Vec::new(), + cu_seqlens: vec![0], + }; + result.reserve_outputs(total, patch_features, false, images.len(), images.len() + 1)?; + for (image, geometry) in images.iter().zip(&result.geometry) { + let pixels = resize::resize(image, geometry.width, geometry.height); + let grid_h = geometry.height / self.patch_size; + let grid_w = geometry.width / self.patch_size; + // Gemma 4 patch vectors interleave RGB per pixel: (y, x, channel). + for row in 0..grid_h { + for column in 0..grid_w { + result.position_ids.push([column as i64, row as i64]); + for y in 0..self.patch_size { + for x in 0..self.patch_size { + let offset = ((row * self.patch_size + y) * geometry.width + + column * self.patch_size + + x) + * 3; + for channel in 0..3 { + result + .pixel_values + .push(pixels[offset + channel] as f32 * (1.0 / 255.0)); + } + } + } + } + } + result + .cu_seqlens + .push(result.cu_seqlens.last().unwrap() + geometry.patches as i32); + } + Ok(result) + } + + pub(super) fn expand_prompt( + &self, + frontend: &Frontend, + prompt_token_ids: &[u32], + images: &ProcessedImages, + ) -> Result { + self.envelope.expand(frontend, prompt_token_ids, images) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::frontend::{Asset, FrontendAssets, images::ImageSettings}; + use sha2::{Digest, Sha256}; + use std::path::PathBuf; + + fn processor_with_budget(max_soft_tokens: usize) -> ImageProcessor { + let max_patches = max_soft_tokens * 9; + ImageProcessor::load( + ImageSettings::Gemma4(Gemma4ImageSettings { + patch_size: 16, + pooling_kernel_size: 3, + max_soft_tokens, + image_token: "<|image|>".into(), + start_token: "<|image>".into(), + end_token: "".into(), + }), + ImageLimits { + max_patches_per_image: max_patches, + max_total_patches: max_patches * 4, + patches_per_feature: 9, + ..ImageLimits::default() + }, + ) + .unwrap() + } + + fn processor() -> ImageProcessor { + processor_with_budget(280) + } + + #[test] + fn load_validates_pooling_and_patch_budget_limits() { + let settings = Gemma4ImageSettings { + patch_size: 16, + pooling_kernel_size: 3, + max_soft_tokens: 280, + image_token: "<|image|>".into(), + start_token: "<|image>".into(), + end_token: "".into(), + }; + let pooling_err = ImageProcessor::load( + ImageSettings::Gemma4(settings.clone()), + ImageLimits { + patches_per_feature: 4, + max_patches_per_image: 2520, + ..ImageLimits::default() + }, + ) + .err() + .unwrap() + .to_string(); + assert!( + pooling_err.contains("patches_per_feature") + && pooling_err.contains("9") + && pooling_err.contains("4"), + "{pooling_err}" + ); + let budget_err = ImageProcessor::load( + ImageSettings::Gemma4(settings.clone()), + ImageLimits { + patches_per_feature: 9, + max_patches_per_image: 2519, + ..ImageLimits::default() + }, + ) + .err() + .unwrap() + .to_string(); + assert!( + budget_err.contains("max_patches_per_image") + && budget_err.contains("2520") + && budget_err.contains("2519"), + "{budget_err}" + ); + let soft_err = ImageProcessor::load( + ImageSettings::Gemma4(Gemma4ImageSettings { + max_soft_tokens: 200, + ..settings + }), + ImageLimits { + patches_per_feature: 9, + max_patches_per_image: 2520, + ..ImageLimits::default() + }, + ) + .err() + .unwrap() + .to_string(); + assert!( + soft_err.contains("max_soft_tokens") && soft_err.contains("200"), + "{soft_err}" + ); + } + + #[test] + fn canonical_processor_pixels_positions_and_resize() { + use serde_json::{Value, json}; + let fixture: Value = + serde_json::from_str(include_str!("../../../../tests/frontend/gemma4_images.json")) + .unwrap(); + let hash = |bytes: &[u8]| format!("{:x}", Sha256::digest(bytes)); + for case in fixture["cases"].as_array().unwrap() { + let width = case["width"].as_u64().unwrap() as usize; + let height = case["height"].as_u64().unwrap() as usize; + let seed = case["seed"].as_u64().unwrap() as usize; + let max_soft_tokens = case["max_soft_tokens"].as_u64().unwrap() as usize; + let processor = processor_with_budget(max_soft_tokens); + let pixels: Vec = (0..height) + .flat_map(|y| { + (0..width).flat_map(move |x| { + [(x * 7 + seed * 31) as u8, (y * 11) as u8, (x + y * 3) as u8] + }) + }) + .collect(); + let image = RgbImage::new(width, height, pixels).unwrap(); + let (geometry, resized) = processor.resized_rgb(&image).unwrap(); + assert_eq!( + json!(geometry.grid_thw), + case["grid"], + "{width}x{height}@{max_soft_tokens}" + ); + assert_eq!( + geometry.tokens as u64, + case["tokens"].as_u64().unwrap(), + "{width}x{height}@{max_soft_tokens}" + ); + assert_eq!( + geometry.patches as u64, + case["patches"].as_u64().unwrap(), + "{width}x{height}@{max_soft_tokens}" + ); + assert_eq!( + hash(&resized), + case["resized"], + "resize {width}x{height}@{max_soft_tokens}" + ); + let processed = processor.process(&[image]).unwrap(); + let pixels: Vec = processed + .pixel_values + .iter() + .flat_map(|v| v.to_le_bytes()) + .collect(); + assert_eq!( + hash(&pixels), + case["pixels"], + "pixels {width}x{height}@{max_soft_tokens}" + ); + let positions: Vec = processed + .position_ids + .iter() + .flatten() + .flat_map(|v| v.to_le_bytes()) + .collect(); + assert_eq!( + hash(&positions), + case["positions"], + "positions {width}x{height}@{max_soft_tokens}" + ); + assert_eq!(processed.cu_seqlens, [0, geometry.patches as i32]); + assert!(processed.interpolation_indices.is_empty()); + } + } + + #[test] + fn geometry_matches_the_hugging_face_processor() { + let processor = processor(); + for (width, height, grid, tokens) in [ + (1, 1, [1, 48, 48], 256), + (672, 672, [1, 48, 48], 256), + (1008, 672, [1, 39, 60], 260), + (91, 37, [1, 30, 78], 260), + (1920, 1080, [1, 36, 66], 264), + (100, 3000, [1, 273, 9], 273), + (3000, 100, [1, 9, 273], 273), + (10, 3000, [1, 840, 3], 280), + (3000, 10, [1, 3, 840], 280), + ] { + let geometry = processor.geometry(width, height).unwrap(); + assert_eq!(geometry.grid_thw, grid, "{width}x{height}"); + assert_eq!(geometry.tokens, tokens, "{width}x{height}"); + assert_eq!(geometry.tokens * 9, geometry.patches, "{width}x{height}"); + } + } + + #[test] + fn pixels_interleave_rgb_and_positions_are_xy() { + let processor = processor(); + let pixels: Vec = (0..37 * 91 * 3).map(|x| (x % 256) as u8).collect(); + let image = RgbImage::new(91, 37, pixels).unwrap(); + let processed = processor.process(&[image]).unwrap(); + let geometry = processed.geometry[0]; + assert_eq!(geometry.grid_thw, [1, 30, 78]); + assert_eq!(processed.pixel_values.len(), geometry.patches * 3 * 16 * 16); + assert_eq!(processed.position_ids[0], [0, 0]); + assert_eq!(processed.position_ids[1], [1, 0]); + assert_eq!( + processed.position_ids[geometry.grid_thw[2] as usize], + [0, 1] + ); + assert_eq!(processed.cu_seqlens, [0, geometry.patches as i32]); + } + + #[test] + #[ignore = "requires FLARE_GEMMA4_TEST_SNAPSHOT"] + fn checkpoint_tokens_expand_the_image_envelope() { + let snapshot = PathBuf::from( + std::env::var_os("FLARE_GEMMA4_TEST_SNAPSHOT") + .expect("FLARE_GEMMA4_TEST_SNAPSHOT must be set"), + ); + assert!( + snapshot.join("tokenizer.json").is_file(), + "missing tokenizer.json under {}", + snapshot.display() + ); + let asset = |name: &str| { + let path = snapshot.join(name); + Asset { + sha256: format!("{:x}", Sha256::digest(std::fs::read(&path).unwrap())), + path, + range: None, + } + }; + // Frontend::load requires a chat template asset for PromptEncoder::Jinja (frontend/mod.rs). + struct TempFile(PathBuf); + impl Drop for TempFile { + fn drop(&mut self) { + let _ = std::fs::remove_file(&self.0); + } + } + let template = TempFile( + std::env::temp_dir().join(format!("gemma4-template-{}.jinja", std::process::id())), + ); + let template_bytes = b"{% mark %}{{ messages[0].content }}"; + std::fs::write(&template.0, template_bytes).unwrap(); + let chat_template = Asset { + sha256: format!("{:x}", Sha256::digest(template_bytes)), + path: template.0.clone(), + range: None, + }; + let frontend = Frontend::load( + FrontendAssets { + tokenizer: asset("tokenizer.json"), + tokens: crate::frontend::test_support::tokens(&asset("tokenizer_config.json")) + .unwrap(), + chat_template: Some(chat_template), + }, + Default::default(), + ) + .unwrap(); + drop(template); + let processed = ProcessedImages { + geometry: vec![ImageGeometry { + height: 480, + width: 1248, + grid_thw: [1, 30, 78], + patches: 2340, + tokens: 260, + }], + cu_seqlens: vec![0, 2340], + ..Default::default() + }; + let prompt_ids = frontend.encode("Look <|image|> now", false).unwrap(); + let expanded = processor() + .expand_prompt(&frontend, &prompt_ids, &processed) + .unwrap(); + let boi = frontend.encode("<|image>", false).unwrap()[0]; + let image = frontend.encode("<|image|>", false).unwrap()[0]; + let eoi = frontend.encode("", false).unwrap()[0]; + let start = expanded.token_ids.iter().position(|id| *id == boi).unwrap(); + assert_eq!(expanded.token_ids[start], boi); + assert_eq!(expanded.token_ids[start + 261], eoi); + assert!( + expanded.token_ids[start + 1..start + 261] + .iter() + .all(|id| *id == image) + ); + assert!( + expanded.mm_token_type_ids[start + 1..start + 261] + .iter() + .all(|kind| *kind == 1) + ); + assert_eq!(expanded.mm_token_type_ids[start], 0); + assert_eq!(expanded.mm_token_type_ids[start + 261], 0); + } +} diff --git a/helios/src/frontend/images/layouts/bracketed.rs b/helios/src/frontend/images/layouts/bracketed.rs index 2c208037e..3902f79d7 100644 --- a/helios/src/frontend/images/layouts/bracketed.rs +++ b/helios/src/frontend/images/layouts/bracketed.rs @@ -20,6 +20,7 @@ pub(crate) fn prepare_input( processor: Option<&ImageProcessor>, rendered: &RenderedPrompt, images: &[ImageDescription], + atomic_spans: bool, ) -> Result { if images.is_empty() { if let Some(processor) = processor { @@ -48,11 +49,25 @@ pub(crate) fn prepare_input( let processed = processor.describe_inputs(images)?; let expanded = processor.expand_prompt(frontend, &rendered.token_ids, &processed)?; let mut conditioning = Vec::new(); + let mut spans = Vec::new(); let mut image = 0; let mut feature = 0; + let mut run_start = None; let mut indices = Vec::with_capacity(expanded.token_ids.len()); + let mut flush_span = |start: usize, end: usize| -> Result<()> { + if atomic_spans { + if start == 0 || end >= expanded.token_ids.len() { + return Err("bracketed image feature run is outside the expanded prompt".into()); + } + spans.push(start - 1..end + 1); + } + Ok(()) + }; for (position, kind) in expanded.mm_token_type_ids.iter().enumerate() { if *kind == 0 { + if let Some(start) = run_start.take() { + flush_span(start, position)?; + } indices.push(-1); continue; } @@ -62,11 +77,15 @@ pub(crate) fn prepare_input( position: position as u64, identity: source.identity, }); + run_start = Some(position); image += 1; } indices.push(feature); feature += 1; } + if let Some(start) = run_start.take() { + flush_span(start, expanded.mm_token_type_ids.len())?; + } if image != images.len() || feature as usize != processed.geometry.iter().map(|g| g.tokens).sum::() { @@ -84,6 +103,7 @@ pub(crate) fn prepare_input( tokens: expanded.token_ids, data: PromptData { vision_token_indices: indices, + spans, ..Default::default() }, conditioning, @@ -152,7 +172,7 @@ mod tests { RgbImage::new(672, 672, vec![255; 672 * 672 * 3]).unwrap(), ]; let images = images.iter().map(|image| processor.describe_image(image).unwrap()).collect::>(); - let prepared = prepare_input(&frontend, Some(&processor), &rendered, &images).unwrap(); + let prepared = prepare_input(&frontend, Some(&processor), &rendered, &images, false).unwrap(); assert_eq!( prepared.tokens.iter().filter(|id| **id == 200025).count(), 580 @@ -176,6 +196,6 @@ mod tests { assert_eq!(prepared.tokens[p + count], end); assert!(prepared.tokens[p..p + count].iter().all(|id| *id == 200025)); } - assert!(prepare_input(&frontend, Some(&processor), &rendered, &[]).is_err()); + assert!(prepare_input(&frontend, Some(&processor), &rendered, &[], false).is_err()); } } diff --git a/helios/src/frontend/images/mod.rs b/helios/src/frontend/images/mod.rs index 03925031e..242d6324e 100644 --- a/helios/src/frontend/images/mod.rs +++ b/helios/src/frontend/images/mod.rs @@ -14,6 +14,7 @@ mod deepseek_row_major; pub(crate) mod layouts; mod mimo; mod glm; +mod gemma4; mod moonvit; mod orientation; mod conditioned; @@ -299,6 +300,7 @@ pub enum ImageSettings { Radio {}, Glm {}, PaddedGrid {}, + Gemma4(Gemma4ImageSettings), } /// The text that stands for an image in a RADIO prompt. @@ -325,6 +327,7 @@ impl ImageSettings { Self::Radio {} => ImagePreparationKind::Radio, Self::Glm {} => ImagePreparationKind::Glm, Self::PaddedGrid {} => ImagePreparationKind::PaddedGrid, + Self::Gemma4(_) => ImagePreparationKind::Gemma4, } } } @@ -369,6 +372,17 @@ pub struct PatchMergeImageSettings { pub end_token: String, } +#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Gemma4ImageSettings { + pub patch_size: usize, + pub pooling_kernel_size: usize, + pub max_soft_tokens: usize, + pub image_token: String, + pub start_token: String, + pub end_token: String, +} + #[derive(Clone)] enum Profile { Qwen(qwen::QwenProcessor), @@ -381,6 +395,7 @@ enum Profile { Radio, Glm, PaddedGrid, + Gemma4(gemma4::Processor), } impl ImageProcessor { @@ -414,6 +429,7 @@ impl ImageProcessor { ImageSettings::Radio {} => Profile::Radio, ImageSettings::Glm {} => Profile::Glm, ImageSettings::PaddedGrid {} => Profile::PaddedGrid, + ImageSettings::Gemma4(settings) => Profile::Gemma4(gemma4::Processor::load(settings, limits)?), ImageSettings::Mimo(settings) => Profile::MiMo(mimo::load(&settings, limits)?), ImageSettings::PatchMerge(settings) => Profile::PatchMerge(patch_merge::Processor::load(settings, limits)?), ImageSettings::Qwen(settings) => { @@ -483,6 +499,28 @@ impl ImageProcessor { self.limits } + pub(crate) fn patch_features(&self) -> usize { + match &self.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 => padded_grid::FEATURES, + Profile::Gemma4(processor) => processor.patch_features(), + Profile::DeepSeek4 | Profile::DeepseekRowMajor(_) | Profile::Moonvit | Profile::Step => { + 588 + } + } + } + + pub(crate) fn max_image_envelope_tokens(&self) -> Option { + match &self.profile { + Profile::Gemma4(processor) => Some(processor.max_envelope_tokens()), + _ => None, + } + } + pub(crate) fn check_batch(&self, images: usize, patches: usize) -> Result<()> { self.limits.check_batch(images, patches) } @@ -886,6 +924,7 @@ impl ImageProcessor { Profile::Radio => radio::geometry(self.limits, width, height), Profile::Glm => glm::geometry(self.limits, width, height), Profile::PaddedGrid => padded_grid::geometry(self.limits, width, height), + Profile::Gemma4(profile) => profile.geometry(width, height), } } pub fn resized_rgb(&self, image: &RgbImage) -> Result<(ImageGeometry, Vec)> { @@ -900,6 +939,7 @@ impl ImageProcessor { Profile::Radio => Err("RADIO resizing produces float32 pixels; use process".into()), Profile::Glm => glm::resized_rgb(self.limits, image), Profile::PaddedGrid => Err("padded-grid preparation pads with values outside RGB8; use process".into()), + Profile::Gemma4(profile) => profile.resized_rgb(image), } } pub fn process(&self, images: &[RgbImage]) -> Result { @@ -919,6 +959,7 @@ impl ImageProcessor { Profile::Radio => radio::process(self.limits, images), Profile::Glm => glm::process(self.limits, images), Profile::PaddedGrid => padded_grid::process(self.limits, images), + Profile::Gemma4(profile) => profile.process(images), } } pub fn expand_prompt( @@ -939,6 +980,7 @@ impl ImageProcessor { Profile::Radio => Err("RADIO image expansion requires its model contract".into()), Profile::Glm => Err("GLM image expansion requires its prepared layout".into()), Profile::PaddedGrid => Err("padded-grid image expansion requires its prepared layout".into()), + Profile::Gemma4(profile) => profile.expand_prompt(frontend, prompt_token_ids, images), } } } diff --git a/helios/src/frontend/images/packing.rs b/helios/src/frontend/images/packing.rs index 827e55ca0..425e2c2d1 100644 --- a/helios/src/frontend/images/packing.rs +++ b/helios/src/frontend/images/packing.rs @@ -9,12 +9,21 @@ use super::ProcessedImages; use crate::{ Result, execution::Dtype, - model::{ModelConfig, contract::ImageLayoutKind, inputs::UploadBatch}, + model::{ModelConfig, VisionCapabilities, contract::ImageLayoutKind, inputs::UploadBatch}, scheduler::RequestHandle, }; +fn square_merge_side(patches_per_feature: usize) -> Result { + let side = patches_per_feature.isqrt(); + if side == 0 || side * side != patches_per_feature { + return Err("bracketed patches_per_feature must be a positive square".into()); + } + Ok(side as i64) +} + pub(crate) fn tensor_layout( kind: ImageLayoutKind, + vision: &VisionCapabilities, name: &str, patches: usize, ) -> Result<(Dtype, usize)> { @@ -27,7 +36,14 @@ pub(crate) fn tensor_layout( ImageLayoutKind::Deepseek | ImageLayoutKind::DeepseekRowMajor | ImageLayoutKind::Moonvit | ImageLayoutKind::Step, "vision_pixel_values", ) => (Float32, patches * 588), - (ImageLayoutKind::Bracketed, "vision_pixel_values") => (Float32, patches * 1176), + (ImageLayoutKind::Bracketed, "vision_pixel_values") => { + square_merge_side(vision.patches_per_feature)?; + let width = vision.bracketed_patch_features(); + let elements = patches + .checked_mul(width) + .ok_or("vision pixel buffer extent overflows")?; + (Float32, elements) + } (ImageLayoutKind::Radio, "vision_pixel_values") => (Float32, patches * 768), (ImageLayoutKind::Glm, "vision_pixel_values") => (Float32, patches * 1176), (ImageLayoutKind::ClassToken, "vision_pixel_values") => (Float32, patches * 1200), @@ -465,19 +481,24 @@ fn step( } fn bracketed(config: &ModelConfig, handle: RequestHandle, images: &ProcessedImages, image: usize, destination_feature_offset: usize) -> Result { + let patches_per_feature = config.contract.vision.patches_per_feature; + let merge_side = square_merge_side(patches_per_feature)?; + let patch_width = config.contract.vision.bracketed_patch_features(); let geometry = images.geometry.get(image).ok_or("missing scheduled image")?; let start: usize = images.geometry[..image].iter().map(|g| g.patches).sum(); let end = start + geometry.patches; let [t, h, w] = geometry.grid_thw; - if t != 1 || h <= 0 || w <= 0 || h%2 != 0 || w%2 != 0 + if t != 1 || h <= 0 || w <= 0 || h % merge_side != 0 || w % merge_side != 0 || (h as usize).checked_mul(w as usize) != Some(geometry.patches) - || geometry.tokens != geometry.patches/4 || config.contract.vision.patches_per_feature != 4 + || geometry.tokens.checked_mul(patches_per_feature) != Some(geometry.patches) || geometry.patches > *config.contract.vision.patch_capacities.last().ok_or("missing vision capacities")? || handle.slot as usize >= config.limits.max_active || handle.generation == 0 || handle.generation > i64::MAX as u64 { - return Err("invalid temporal patch-merge image extent".into()); + return Err("invalid bracketed image extent".into()); } + let pixel_start = start.checked_mul(patch_width).ok_or("vision pixel offset overflows")?; + let pixel_end = end.checked_mul(patch_width).ok_or("vision pixel offset overflows")?; let mut staging = UploadBatch::default(); - staging.put("vision_pixel_values", 0, images.pixel_values.get(start*1176..end*1176).ok_or("truncated vision pixels")?.iter().copied().flat_map(f32::to_le_bytes)); + staging.put("vision_pixel_values", 0, images.pixel_values.get(pixel_start..pixel_end).ok_or("truncated vision pixels")?.iter().copied().flat_map(f32::to_le_bytes)); staging.i64("vision_position_ids", 0, images.position_ids.get(start..end).ok_or("truncated vision positions")?.iter().flatten().copied()); staging.i32("vision_cu_seqlens", 0, [0, geometry.patches as i32]); staging.i32("vision_num_patches", 0, [geometry.patches as i32]); @@ -544,3 +565,251 @@ fn class_token( staging.i32("vision_feature_offset", 0, [destination_feature_offset as i32]); Ok(staging) } + +#[cfg(test)] +mod tests { + use super::*; + use crate::frontend::images::{ + DeepseekRowMajorImageSettings, Gemma4ImageSettings, ImageGeometry, ImageLimits, + ImageProcessor, ImageSettings, MimoImageSettings, PatchMergeImageSettings, + QwenImageSettings, + }; + + fn bracketed_config(patches_per_feature: usize, patch_features: usize) -> ModelConfig { + let mut config = crate::frontend::test_support::model_config( + crate::model::testing::metadata(), + ); + config.contract.frontend.image_layout = Some(ImageLayoutKind::Bracketed); + config.contract.vision = VisionCapabilities { + feature_slots: 1, + features_per_request: 1024, + max_images: 4, + patches_per_feature, + patch_capacities: vec![9 * 1024], + patch_features, + }; + config + } + + #[test] + fn bracketed_packs_3x3_metadata_widths_and_rejects_invalid_extents() { + let handle = RequestHandle { + slot: 0, + generation: 1, + }; + for width in [768usize, 588] { + let config = bracketed_config(9, width); + assert_eq!( + tensor_layout( + ImageLayoutKind::Bracketed, + &config.contract.vision, + "vision_pixel_values", + 18, + ) + .unwrap(), + (Dtype::Float32, 18 * width), + ); + let images = ProcessedImages { + pixel_values: (0..18 * width).map(|i| i as f32).collect(), + geometry: vec![ImageGeometry { + height: 48, + width: 96, + grid_thw: [1, 3, 6], + patches: 18, + tokens: 2, + }], + position_ids: (0..18).map(|i| [i as i64 % 6, i as i64 / 6]).collect(), + interpolation_indices: vec![], + interpolation_weights: vec![], + cu_seqlens: vec![0, 18], + }; + let batch = bracketed(&config, handle, &images, 0, 5).unwrap(); + let uploads = batch.uploads(); + let pixels = uploads + .iter() + .find(|entry| entry.buffer == "vision_pixel_values") + .unwrap(); + assert_eq!(pixels.bytes.len(), 18 * width * 4); + let truncated = ProcessedImages { + pixel_values: vec![0.0; 18 * width - 1], + ..images.clone() + }; + assert!(bracketed(&config, handle, &truncated, 0, 0).is_err()); + let odd_grid = ProcessedImages { + geometry: vec![ImageGeometry { + height: 64, + width: 64, + grid_thw: [1, 4, 4], + patches: 16, + tokens: 2, + }], + ..images + }; + assert!(bracketed(&config, handle, &odd_grid, 0, 0).is_err()); + } + let legacy = bracketed_config(4, 0); + assert_eq!( + tensor_layout( + ImageLayoutKind::Bracketed, + &legacy.contract.vision, + "vision_pixel_values", + 16, + ) + .unwrap(), + (Dtype::Float32, 16 * 1176), + ); + let non_square = bracketed_config(3, 768); + assert!( + tensor_layout( + ImageLayoutKind::Bracketed, + &non_square.contract.vision, + "vision_pixel_values", + 9, + ) + .is_err() + ); + // Non-Bracketed layouts with non-square patches_per_feature remain unaffected. + assert_eq!( + tensor_layout( + ImageLayoutKind::Deepseek, + &non_square.contract.vision, + "vision_pixel_values", + 9, + ) + .unwrap(), + (Dtype::Float32, 9 * 588), + ); + } + + #[test] + fn processor_patch_features_match_tensor_layout_for_every_profile() { + let cases: Vec<(ImageSettings, ImageLimits, ImageLayoutKind, usize, usize)> = vec![ + ( + ImageSettings::Qwen(QwenImageSettings { + min_pixels: 3136, + max_pixels: 1_000_000, + position_side: 48, + image_token_id: 1, + video_token_id: 2, + }), + ImageLimits::default(), + ImageLayoutKind::Qwen, + 4, + 0, + ), + ( + ImageSettings::Mimo(MimoImageSettings { + min_pixels: 3136, + max_pixels: 1_000_000, + image_mean: [0.5; 3], + image_std: [0.5; 3], + }), + ImageLimits::default(), + ImageLayoutKind::Mimo, + 4, + 0, + ), + ( + ImageSettings::Deepseek4 {}, + ImageLimits::default(), + ImageLayoutKind::Deepseek, + 9, + 0, + ), + ( + ImageSettings::DeepseekRowMajor(DeepseekRowMajorImageSettings { + min_pixels: 3136, + max_tokens: 1024, + max_width_height_ratio: None, + }), + ImageLimits::default(), + ImageLayoutKind::DeepseekRowMajor, + 9, + 0, + ), + ( + ImageSettings::Moonvit {}, + ImageLimits::default(), + ImageLayoutKind::Moonvit, + 4, + 0, + ), + ( + ImageSettings::Step {}, + ImageLimits::default(), + ImageLayoutKind::Step, + 4, + 0, + ), + ( + ImageSettings::Radio {}, + ImageLimits::default(), + ImageLayoutKind::Radio, + 4, + 0, + ), + ( + ImageSettings::Glm {}, + ImageLimits::default(), + ImageLayoutKind::Glm, + 4, + 0, + ), + ( + ImageSettings::PatchMerge(PatchMergeImageSettings { + patch_size: 14, + min_pixels: 3136, + max_pixels: 451_584, + image_mean: [0.5; 3], + image_std: [0.5; 3], + image_token: "image".into(), + start_token: "start".into(), + end_token: "end".into(), + }), + ImageLimits::default(), + ImageLayoutKind::Bracketed, + 4, + 0, + ), + ( + ImageSettings::PaddedGrid {}, + ImageLimits::default(), + ImageLayoutKind::ClassToken, + 4, + 0, + ), + ( + ImageSettings::Gemma4(Gemma4ImageSettings { + patch_size: 16, + pooling_kernel_size: 3, + max_soft_tokens: 280, + image_token: "<|image|>".into(), + start_token: "<|image>".into(), + end_token: "".into(), + }), + ImageLimits { + patches_per_feature: 9, + ..ImageLimits::default() + }, + ImageLayoutKind::Bracketed, + 9, + 768, + ), + ]; + for (settings, limits, layout, patches_per_feature, patch_features) in cases { + let processor = ImageProcessor::load(settings, limits).unwrap(); + let vision = VisionCapabilities { + feature_slots: 1, + features_per_request: 1024, + max_images: 4, + patches_per_feature, + patch_capacities: vec![patches_per_feature * 16], + patch_features, + }; + let (dtype, width) = + tensor_layout(layout, &vision, "vision_pixel_values", 1).unwrap(); + assert_eq!(dtype, Dtype::Float32); + assert_eq!(processor.patch_features(), width, "{layout:?}"); + } + } +} diff --git a/helios/src/frontend/images/patch_merge.rs b/helios/src/frontend/images/patch_merge.rs index fa9c6d034..a3639523c 100644 --- a/helios/src/frontend/images/patch_merge.rs +++ b/helios/src/frontend/images/patch_merge.rs @@ -7,56 +7,30 @@ use super::*; +/// Start/feature/end token envelope (`image_token`, `start_token`, `end_token`) +/// shared by `PatchMerge` and `Gemma4` image preparation profiles. #[derive(Clone)] -pub(super) struct Processor { - pub(super) patches: patches::PatchProcessor, +pub(super) struct Envelope { image_token: String, start_token: String, end_token: String, } -impl Processor { - pub(super) fn load(settings: PatchMergeImageSettings, limits: ImageLimits) -> Result { - if settings.patch_size != 14 - || settings.min_pixels == 0 - || settings.max_pixels < settings.min_pixels - || settings.image_mean.iter().any(|x| !x.is_finite()) - || settings - .image_std - .iter() - .any(|x| !x.is_finite() || *x <= 0.) - || [ - &settings.image_token, - &settings.start_token, - &settings.end_token, - ] +impl Envelope { + pub(super) fn load(image_token: String, start_token: String, end_token: String) -> Result { + if [&image_token, &start_token, &end_token] .iter() .any(|s| s.is_empty()) - || settings.image_token == settings.start_token - || settings.image_token == settings.end_token - || settings.start_token == settings.end_token + || image_token == start_token + || image_token == end_token + || start_token == end_token { - return Err("invalid temporal patch-merge image settings".into()); + return Err("invalid image envelope tokens".into()); } - Ok(Self { - patches: patches::PatchProcessor { - limits, - patch_size: settings.patch_size, - min_pixels: settings.min_pixels, - max_pixels: settings.max_pixels, - normalization: patches::Normalization::ScaledChannel { - mean: settings.image_mean, - std: settings.image_std, - }, - resize: resize::resize, - }, - image_token: settings.image_token, - start_token: settings.start_token, - end_token: settings.end_token, - }) + Ok(Self { image_token, start_token, end_token }) } - pub(super) fn expand_prompt( + pub(super) fn expand( &self, frontend: &Frontend, prompt_token_ids: &[u32], @@ -107,6 +81,56 @@ impl Processor { } } +#[derive(Clone)] +pub(super) struct Processor { + pub(super) patches: patches::PatchProcessor, + envelope: Envelope, +} + +impl Processor { + pub(super) fn load(settings: PatchMergeImageSettings, limits: ImageLimits) -> Result { + if settings.patch_size != 14 + || settings.min_pixels == 0 + || settings.max_pixels < settings.min_pixels + || settings.image_mean.iter().any(|x| !x.is_finite()) + || settings + .image_std + .iter() + .any(|x| !x.is_finite() || *x <= 0.) + { + return Err("invalid temporal patch-merge image settings".into()); + } + let envelope = Envelope::load( + settings.image_token, + settings.start_token, + settings.end_token, + )?; + Ok(Self { + patches: patches::PatchProcessor { + limits, + patch_size: settings.patch_size, + min_pixels: settings.min_pixels, + max_pixels: settings.max_pixels, + normalization: patches::Normalization::ScaledChannel { + mean: settings.image_mean, + std: settings.image_std, + }, + resize: resize::resize, + }, + envelope, + }) + } + + pub(super) fn expand_prompt( + &self, + frontend: &Frontend, + prompt_token_ids: &[u32], + images: &ProcessedImages, + ) -> Result { + self.envelope.expand(frontend, prompt_token_ids, images) + } +} + #[cfg(test)] mod tests { use super::*; @@ -187,4 +211,92 @@ sys.stdout.buffer.write(result['pixel_values'].contiguous().numpy().tobytes()) assert_eq!(*a, b, "pixel {i}"); } } + + #[test] + fn envelope_expands_image_placeholders_and_rejects_mismatches() { + use crate::frontend::{Asset, FrontendAssets}; + use sha2::{Digest, Sha256}; + static SERIAL: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + let root = std::env::temp_dir().join(format!( + "flare-envelope-{}-{}", + std::process::id(), + SERIAL.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + )); + std::fs::create_dir_all(&root).unwrap(); + let vocab: tokenizers::models::bpe::Vocab = (0..128) + .map(|id| ((id as u8 as char).to_string(), id)) + .collect(); + let model = tokenizers::models::bpe::BPE::builder() + .vocab_and_merges(vocab, vec![]) + .build() + .unwrap(); + let mut tokenizer = tokenizers::Tokenizer::new(model); + tokenizer + .add_special_tokens( + [ + "<|image|>", + "<|image>", + "", + "]<]image[>[", + "]<]start of image[>[", + "]<]end of image[>[", + ] + .map(|text| tokenizers::AddedToken::from(text, true)), + ) + .unwrap(); + let asset = |name: &str, bytes: &[u8]| { + let path = root.join(name); + std::fs::write(&path, bytes).unwrap(); + Asset { + range: None, + path, + sha256: format!("{:x}", Sha256::digest(bytes)), + } + }; + let frontend = Frontend::load( + FrontendAssets { + tokenizer: asset("tokenizer.json", tokenizer.to_string(false).unwrap().as_bytes()), + tokens: Default::default(), + chat_template: Some(asset( + "chat_template.jinja", + b"{% mark %}{{ messages[0].content }}", + )), + }, + Default::default(), + ) + .unwrap(); + std::fs::remove_dir_all(&root).unwrap(); + + for (image_tok, start_tok, end_tok) in [ + ("<|image|>", "<|image>", ""), + ("]<]image[>[", "]<]start of image[>[", "]<]end of image[>["), + ] { + let envelope = Envelope::load(image_tok.into(), start_tok.into(), end_tok.into()).unwrap(); + let prompt = format!("A {image_tok} B {image_tok} C"); + let prompt_ids = frontend.encode(&prompt, false).unwrap(); + let processed = ProcessedImages { + geometry: vec![ + ImageGeometry { height: 48, width: 48, grid_thw: [1, 3, 3], patches: 9, tokens: 2 }, + ImageGeometry { height: 48, width: 48, grid_thw: [1, 3, 3], patches: 9, tokens: 3 }, + ], + ..Default::default() + }; + let expanded = envelope.expand(&frontend, &prompt_ids, &processed).unwrap(); + let img_id = frontend.encode(image_tok, false).unwrap()[0]; + let start_id = frontend.encode(start_tok, false).unwrap()[0]; + let end_id = frontend.encode(end_tok, false).unwrap()[0]; + assert_eq!(expanded.token_ids.iter().filter(|id| **id == img_id).count(), 5); + assert_eq!(expanded.token_ids.iter().filter(|id| **id == start_id).count(), 2); + assert_eq!(expanded.token_ids.iter().filter(|id| **id == end_id).count(), 2); + assert_eq!(expanded.mm_token_type_ids.iter().filter(|kind| **kind == 1).count(), 5); + // Placeholder count mismatch fails cleanly. + assert!(envelope.expand(&frontend, &prompt_ids, &ProcessedImages::default()).is_err()); + } + + // Duplicate or empty tokens fail load; multi-token marker fails expand. + assert!(Envelope::load("".into(), "<|image>".into(), "".into()).is_err()); + assert!(Envelope::load("<|image|>".into(), "<|image|>".into(), "".into()).is_err()); + let bad = Envelope::load("ab".into(), "<|image>".into(), "".into()).unwrap(); + assert!(bad.expand(&frontend, &[], &ProcessedImages::default()).is_err()); + } } diff --git a/helios/src/model.rs b/helios/src/model.rs index 21465c6bd..283a4de40 100644 --- a/helios/src/model.rs +++ b/helios/src/model.rs @@ -50,6 +50,9 @@ pub struct VisionCapabilities { pub max_images: usize, pub patches_per_feature: usize, pub patch_capacities: Vec, + /// Float32 elements per vision patch; zero inherits the layout's legacy width. + #[cfg_attr(any(feature = "frontend", feature = "runtime-core"), serde(default))] + pub patch_features: usize, } impl VisionCapabilities { @@ -60,6 +63,7 @@ impl VisionCapabilities { max_images: 0, patches_per_feature: 0, patch_capacities: Vec::new(), + patch_features: 0, } } @@ -67,6 +71,16 @@ impl VisionCapabilities { self.max_images > 0 } + /// Per-patch float width for `ImageLayoutKind::Bracketed`; `0` inherits the legacy + /// temporal-merge width (`3 * 2 * 14² = 1176`). + pub fn bracketed_patch_features(&self) -> usize { + if self.patch_features != 0 { + self.patch_features + } else { + 1176 + } + } + pub fn validate(&self) -> Result<()> { if self == &Self::disabled() { return Ok(()); @@ -74,6 +88,7 @@ impl VisionCapabilities { if self.feature_slots == 0 || self.feature_slots > crate::execution::REQUEST_LANES || self.patches_per_feature == 0 + || !self.patch_features.is_multiple_of(3) || self.max_images == 0 || self.features_per_request == 0 || self.patch_capacities.is_empty() diff --git a/helios/src/model/contract.rs b/helios/src/model/contract.rs index 24c19155c..a3c021621 100644 --- a/helios/src/model/contract.rs +++ b/helios/src/model/contract.rs @@ -66,7 +66,7 @@ contract_enum!(InputIndexing { Scalar = 1, SubmissionRow = 2, RequestRow = 3, Pa contract_enum!(StateAccessKind { Read = 1, Write = 2, ReadWrite = 3 }); contract_enum!(ToolParserKind { QwenCoder = 1, GlmArgumentTags = 2, Dsml = 3, Xtml = 4, MiniMaxXml = 5, GemmaCall = 6, Atem = 7, TmlJson = 8 }); contract_enum!(ReasoningParserKind { ThinkTags = 1, XtmlThink = 2, MmThink = 3, ChannelThought = 4, RecipientHeaders = 5, ContentHeaders = 6 }); -contract_enum!(ImagePreparationKind { Qwen = 1, Mimo = 2, Deepseek = 3, Moonvit = 4, Step = 5, Radio = 6, DeepseekRowMajor = 7, Glm = 8, PatchMerge = 9, PaddedGrid = 10 }); +contract_enum!(ImagePreparationKind { Qwen = 1, Mimo = 2, Deepseek = 3, Moonvit = 4, Step = 5, Radio = 6, DeepseekRowMajor = 7, Glm = 8, PatchMerge = 9, PaddedGrid = 10, Gemma4 = 11 }); contract_enum!(ImageLayoutKind { Qwen = 1, Mimo = 2, Deepseek = 3, Moonvit = 4, Step = 5, Radio = 6, DeepseekRowMajor = 7, Glm = 8, Bracketed = 9, ClassToken = 10 }); contract_enum!(GraphOperation { Init = 1, Restore = 2, Snapshot = 3, Prefill = 4, Decode = 5, Resume = 6, Vision = 7, Speculative = 8, Mixed = 9, ScoredPrefill = 12, TerminalPrefill = 14 }); diff --git a/helios/src/model/packing.rs b/helios/src/model/packing.rs index 217909f76..077ea22a7 100644 --- a/helios/src/model/packing.rs +++ b/helios/src/model/packing.rs @@ -81,6 +81,7 @@ impl Inputs { .ok_or("image tensor has no prepared layout")?; let (dtype, minimum) = crate::frontend::images::packing::tensor_layout( layout, + &config.contract.vision, &binding.tensor, graph.token_capacity, )?; diff --git a/helios/src/model/prompt.rs b/helios/src/model/prompt.rs index 377fc0945..db7dc3120 100644 --- a/helios/src/model/prompt.rs +++ b/helios/src/model/prompt.rs @@ -51,7 +51,17 @@ pub fn prepare_image_inputs( } let mut prepared = match config.contract.frontend.image_layout { Some(ImageLayoutKind::Bracketed) => crate::frontend::images::layouts::bracketed::prepare_input( - frontend, processor, rendered, &images, + frontend, + processor, + rendered, + &images, + config + .contract + .frontend + .image_tokens + .as_ref() + .and_then(|layout| layout.span.as_ref()) + .is_some(), )?, Some(ImageLayoutKind::Glm) => crate::frontend::images::layouts::glm::prepare_input( frontend, processor, rendered, &images, @@ -406,6 +416,7 @@ mod tests { "<|deepseek_image|>", "<|media_pad|>", "<|media_begin|>", "<|media_content|>", "<|media_end|>", "", "", "", "", "", "", "", "", "", + "<|image|>", "<|image>", "", "<|start|>", "<|message|>", "<|eom|>", "<|eot|>", ].map(|text| tokenizers::AddedToken::from(text, true))).unwrap(); let asset = |name: &str, bytes: &[u8]| { @@ -455,6 +466,7 @@ mod tests { config.contract.vision = crate::model::VisionCapabilities { feature_slots: 4, features_per_request: geometry.tokens, max_images: 1, patches_per_feature: merge, patch_capacities: vec![geometry.patches], + patch_features: 0, }; let syntax = &mut config.contract.frontend; syntax.image_layout = Some(layout); @@ -1155,4 +1167,117 @@ mod tests { assert_eq!(actual, expected, "{ranges:?}"); } } + + #[test] + fn bracketed_layout_emits_atomic_spans_only_when_contract_declares_them() { + use crate::frontend::images::{Gemma4ImageSettings, ImageLimits, ImageSettings}; + use crate::model::contract::{ImageSpan, ImageTokenLayout}; + let frontend = image_frontend(); + let token = |text: &str| frontend.encode(text, false).unwrap()[0]; + let image_token = token("<|image|>"); + let start_token = token("<|image>"); + let end_token = token(""); + let processor = ImageProcessor::load( + ImageSettings::Gemma4(Gemma4ImageSettings { + patch_size: 16, + pooling_kernel_size: 3, + max_soft_tokens: 280, + image_token: "<|image|>".into(), + start_token: "<|image>".into(), + end_token: "".into(), + }), + ImageLimits { + max_patches_per_image: 2520, + max_total_patches: 5040, + patches_per_feature: 9, + ..ImageLimits::default() + }, + ) + .unwrap(); + let image = RgbImage::new(91, 37, vec![128; 91 * 37 * 3]).unwrap(); + // 91x37 under max_soft_tokens=280 resizes to 260 soft tokens (262-token envelope). + let text = "Compare <|image|> and <|image|>".to_string(); + let rendered = RenderedPrompt { + token_ids: frontend.encode(&text, false).unwrap(), + message_boundaries: vec![], + text, + image_sources: vec![], + image_checkpoint_hints: vec![], + ordinary: vec![], + }; + let mut config = super::super::tests::config(); + config.limits.max_sequence_tokens = 4096; + config.limits.prefill_chunk_size = 512; + config.contract.vocabulary = 1000; + config.contract.input_vocabulary = 1000; + config.contract.vision = crate::model::VisionCapabilities { + feature_slots: 4, + features_per_request: 560, + max_images: 2, + patches_per_feature: 9, + patch_capacities: vec![2520, 5040], + patch_features: 768, + }; + config.contract.frontend.image_layout = Some(ImageLayoutKind::Bracketed); + config.contract.frontend.position_dimensions = 0; + config.contract.frontend.rejected_tokens.clear(); + config.contract.frontend.image_tokens = Some(ImageTokenLayout { + feature_token: image_token, + span: Some(ImageSpan { + start_token, + end_token, + max_tokens: 282, + interior_tokens: vec![], + unscoped_tokens: vec![], + }), + }); + + let prepared = prepare_input( + &config, + &frontend, + Some(&processor), + &rendered, + vec![image.clone(), image.clone()], + ) + .unwrap(); + assert_eq!(prepared.data.spans.len(), 2); + for (span, input) in prepared.data.spans.iter().zip(&prepared.conditioned_inputs) { + assert_eq!(span, &input.token_span); + assert_eq!(span.len(), 262); + assert_eq!(prepared.tokens[span.start], start_token); + assert_eq!(prepared.tokens[span.end - 1], end_token); + assert!( + prepared.tokens[span.start + 1..span.end - 1] + .iter() + .all(|id| *id == image_token) + ); + } + + // A valid 64-aligned chunk size smaller than the 262-token span is rejected. + let mut small_chunk = config.clone(); + small_chunk.limits.prefill_chunk_size = 256; + assert!( + prepare_input( + &small_chunk, + &frontend, + Some(&processor), + &rendered, + vec![image.clone(), image.clone()], + ) + .is_err() + ); + + // Without declared atomic spans (e.g. MiniMax), Bracketed leaves data.spans empty. + let mut no_spans = config; + no_spans.contract.frontend.image_tokens.as_mut().unwrap().span = None; + let prepared = prepare_input( + &no_spans, + &frontend, + Some(&processor), + &rendered, + vec![image.clone(), image], + ) + .unwrap(); + assert!(prepared.data.spans.is_empty()); + } } diff --git a/helios/src/model/tests.rs b/helios/src/model/tests.rs index 2f9189c5c..296779520 100644 --- a/helios/src/model/tests.rs +++ b/helios/src/model/tests.rs @@ -1594,6 +1594,184 @@ fn vision_upload_selects_source_image_independently_of_destination_feature_offse } } +#[cfg(feature = "images")] +#[test] +fn legacy_bracketed_core_omitting_patch_features_loads_and_stages_1176_wide_pixels() { + use crate::execution::{BufferDescriptor, Dtype, GraphDescriptor, GraphKind, InputBinding, SamplingMode}; + use crate::frontend::images::{ImageGeometry, ProcessedImages}; + use crate::model::contract::{ + GraphContract, GraphOperation, ImageLayoutKind, ImagePreparationKind, ImageTokenLayout, + InputIndexing, PreparedContract, ValueBinding, ValueSource, + }; + + let base_config = config(); + let mut base_manifest = manifest(&base_config); + let mut contract = base_config.contract.clone(); + contract.vision = VisionCapabilities { + feature_slots: 1, + features_per_request: 4, + max_images: 1, + patches_per_feature: 4, + patch_capacities: vec![16], + patch_features: 0, + }; + contract.frontend.image_layout = Some(ImageLayoutKind::Bracketed); + contract.frontend.image_preparation = Some(ImagePreparationKind::PatchMerge); + contract.frontend.image_tokens = Some(ImageTokenLayout { + feature_token: 42, + span: None, + }); + let scalar_binding = |name: &str, source: ValueSource, tensor: &str| ValueBinding { + buffer: name.into(), + source, + indexing: InputIndexing::Scalar, + value_offset: 0, + padding: 0, + tensor: tensor.into(), + parameter: String::new(), + }; + contract.graphs.push(GraphContract { + graph: "vision-1-16".into(), + kind: GraphOperation::Vision, + state_rows_per_request: 1, + inputs: vec![ + scalar_binding("vision_slot", ValueSource::RequestSlot, ""), + scalar_binding("vision_generation", ValueSource::RequestGeneration, ""), + scalar_binding("vision_feature_slot", ValueSource::ImageFeatureSlot, ""), + scalar_binding("vision_pixel_values", ValueSource::ImageTensor, "vision_pixel_values"), + scalar_binding("vision_position_ids", ValueSource::ImageTensor, "vision_position_ids"), + scalar_binding("vision_cu_seqlens", ValueSource::ImageTensor, "vision_cu_seqlens"), + scalar_binding("vision_num_patches", ValueSource::ImageTensor, "vision_num_patches"), + scalar_binding("vision_num_features", ValueSource::ImageTensor, "vision_num_features"), + scalar_binding("vision_feature_offset", ValueSource::ImageTensor, "vision_feature_offset"), + ], + state: vec![], + pending_token: None, + draft_cursor: None, + tuned_bindings: vec![], + embedding_tables: vec![], + }); + + // Simulate a legacy core JSON that predates `vision.patch_features`. + let mut json = serde_json::to_value(&contract).unwrap(); + json["vision"].as_object_mut().unwrap().remove("patch_features"); + let decoded: PreparedContract = serde_json::from_value(json).unwrap(); + assert_eq!(decoded.vision.patch_features, 0); + + let mut legacy_config = base_config; + legacy_config.contract = decoded; + + let build_manifest = |pixel_width: usize| { + let mut m = base_manifest.clone(); + let mut address = m + .buffers + .iter() + .map(|b| (b.address + b.nbytes).next_multiple_of(8)) + .max() + .unwrap_or(0x10000); + let mut host = m.input_frame_bytes; + let frame_offset = m.graphs[0].input_bindings[0].clone(); + let seq_offset = m.graphs[0].input_bindings[1].clone(); + let mut bindings = vec![frame_offset, seq_offset]; + for (name, dtype, shape) in [ + ("vision_slot", Dtype::Int64, vec![1]), + ("vision_generation", Dtype::Int64, vec![1]), + ("vision_feature_slot", Dtype::Int32, vec![1]), + ("vision_pixel_values", Dtype::Float32, vec![16, pixel_width]), + ("vision_position_ids", Dtype::Int64, vec![16, 2]), + ("vision_cu_seqlens", Dtype::Int32, vec![2]), + ("vision_num_patches", Dtype::Int32, vec![1]), + ("vision_num_features", Dtype::Int32, vec![1]), + ("vision_feature_offset", Dtype::Int32, vec![1]), + ] { + let nbytes = shape.iter().product::() * dtype.size(); + let mut stride = 1; + let mut strides: Vec<_> = shape + .iter() + .rev() + .map(|n| { + let s = stride; + stride *= n; + s + }) + .collect(); + strides.reverse(); + m.buffers.push(BufferDescriptor { + name: name.into(), + address, + nbytes, + dtype, + shape, + strides, + }); + bindings.push(InputBinding { + buffer_name: name.into(), + host_offset: host, + nbytes, + }); + address += nbytes.next_multiple_of(8); + host += nbytes.next_multiple_of(8); + } + m.input_frame_bytes = host; + m.graphs.push(GraphDescriptor { + name: "vision-1-16".into(), + kind: GraphKind::Vision, + sampling_mode: SamplingMode::General, + handle: 1, + batch_capacity: 1, + token_capacity: 16, + prefill_capacity: 0, + packed_token_capacity: 0, + draft_tokens: 0, + confidence_width: 0, + estimated_duration_ns: 1000, + input_bindings: bindings, + tuned_bindings: vec![], + }); + m + }; + + // Legacy 1176-wide Bracketed core loads cleanly through Inputs::new and stages 16 * 1176 floats. + let legacy_manifest = build_manifest(1176); + assert!(Inputs::new(&legacy_config, &legacy_manifest).is_ok()); + let images = ProcessedImages { + pixel_values: (0..16 * 1176).map(|i| i as f32).collect(), + geometry: vec![ImageGeometry { + height: 56, + width: 56, + grid_thw: [1, 4, 4], + patches: 16, + tokens: 4, + }], + position_ids: (0..16).map(|i| [i % 4, i / 4]).collect(), + interpolation_indices: vec![], + interpolation_weights: vec![], + cu_seqlens: vec![0, 16], + }; + let staged = crate::frontend::images::packing::prepare( + &legacy_config, + crate::scheduler::RequestHandle { slot: 0, generation: 1 }, + &images, + 0, + 0, + ) + .unwrap(); + let pixels = staged + .uploads() + .into_iter() + .find(|u| u.buffer == "vision_pixel_values") + .unwrap(); + assert_eq!(pixels.bytes.len(), 16 * 1176 * 4); + + // Undersized 768-wide buffer or non-square patches_per_feature is rejected at Inputs::new. + assert!(Inputs::new(&legacy_config, &build_manifest(768)).is_err()); + let mut non_square = legacy_config; + non_square.contract.vision.patches_per_feature = 3; + non_square.contract.vision.patch_capacities = vec![15]; + base_manifest = build_manifest(1176); + assert!(Inputs::new(&non_square, &base_manifest).is_err()); +} + fn grammar_packing_fixture() -> ( ModelConfig, crate::execution::ExecutionManifest, diff --git a/helios/src/runtime_core/describe.rs b/helios/src/runtime_core/describe.rs index 6177ac380..75b30b335 100644 --- a/helios/src/runtime_core/describe.rs +++ b/helios/src/runtime_core/describe.rs @@ -446,11 +446,13 @@ pub(super) fn vision_json( Profile::Radio(_) => json!({"profile": "radio"}), Profile::PatchMerge(c) => json!({"profile": "patch_merge", "patch_size": c.patch_size, "min_pixels": c.min_pixels, "max_pixels": c.max_pixels}), + Profile::Gemma4(c) => json!({"profile": "gemma4", "patch_size": c.patch_size, + "pooling_kernel_size": c.pooling_kernel_size, "max_soft_tokens": c.max_soft_tokens}), Profile::Glm(_) => json!({"profile": "glm"}), Profile::PaddedGrid(_) => json!({"profile": "padded_grid"}), } }); - json!({ + let mut value = json!({ "feature_slots": vision.feature_slots, "max_image_tokens_per_prompt": context_tokens, "max_images": context_tokens, @@ -458,7 +460,11 @@ pub(super) fn vision_json( "patches_per_feature": vision.patches_per_feature, "patch_capacities": vision.patch_capacities, "image": profile, - }) + }); + if vision.patch_features != 0 { + value["patch_features"] = json!(vision.patch_features); + } + value } fn engram_json(engram: &wire::Engram) -> Value { @@ -1149,6 +1155,7 @@ mod tests { max_images: 0, patches_per_feature: 0, patch_capacities: vec![], + patch_features: 0, }; assert_eq!( vision_json(Some(&disabled), &settings, Some(131072)), @@ -1160,6 +1167,7 @@ mod tests { max_images: 4096, patches_per_feature: 9, patch_capacities: vec![3456], + patch_features: 0, }; let value = vision_json(Some(&enabled), &settings, Some(131072)); assert_eq!(value["max_image_tokens_per_prompt"], 131072); diff --git a/helios/src/runtime_core/protobuf.rs b/helios/src/runtime_core/protobuf.rs index e675938b3..fa061072b 100644 --- a/helios/src/runtime_core/protobuf.rs +++ b/helios/src/runtime_core/protobuf.rs @@ -190,6 +190,11 @@ pub(super) fn frontend_settings(value: wire::FrontendSettings) -> Result serde_json::json!({"gemma4": { + "patch_size": config.patch_size, "pooling_kernel_size": config.pooling_kernel_size, + "max_soft_tokens": config.max_soft_tokens, + "image_token": config.image_token, "start_token": config.start_token, "end_token": config.end_token, + }}), Profile::DeepseekRowMajor(config) => serde_json::json!({"deepseek_row_major": { "min_pixels": config.min_pixels, "max_tokens": config.max_tokens, "max_width_height_ratio": config.max_width_height_ratio, @@ -829,6 +834,61 @@ mod tests { } } + #[test] + fn serialized_gemma4_profile_selects_only_image_preparation() { + // Field 11 adds the Gemma 4 profile without changing any preceding profile tag. + let encoded = wire::FrontendSettings { + tokenizer: Some(wire::TokenizerSettings::default()), + image: Some(wire::ImageSettings { + profile: Some(wire::image_settings::Profile::Gemma4( + wire::Gemma4ImageSettings { + patch_size: 16, + pooling_kernel_size: 3, + max_soft_tokens: 280, + image_token: "<|image|>".into(), + start_token: "<|image>".into(), + end_token: "".into(), + }, + )), + }), + eos_token_ids: vec![1], + ..Default::default() + } + .encode_to_vec(); + let decoded = wire::FrontendSettings::decode(encoded.as_slice()).unwrap(); + let json = frontend_settings(decoded).unwrap(); + assert_eq!( + json["image"], + serde_json::json!({"gemma4": { + "patch_size": 16, + "pooling_kernel_size": 3, + "max_soft_tokens": 280, + "image_token": "<|image|>", + "start_token": "<|image>", + "end_token": "", + }}) + ); + assert_eq!(json["prompt_encoder"], 0); + #[cfg(feature = "server")] + { + let frontend: crate::frontend::FrontendSettings = serde_json::from_value(json).unwrap(); + let settings = frontend.image.unwrap(); + assert_eq!( + settings.preparation_kind(), + crate::model::contract::ImagePreparationKind::Gemma4 + ); + let processor = crate::frontend::images::ImageProcessor::load( + settings, + crate::frontend::images::ImageLimits { + patches_per_feature: 9, + ..Default::default() + }, + ) + .unwrap(); + assert_eq!(processor.geometry(672, 672).unwrap().tokens, 256); + } + } + #[test] fn prompt_encoder_round_trip_preserves_explicit_image_token_and_rejects_unknown_encoder() { for encoder in [1, 2, 3] { diff --git a/helios/src/scheduler/boundary_tests.rs b/helios/src/scheduler/boundary_tests.rs index a97ab3813..5b68a463a 100644 --- a/helios/src/scheduler/boundary_tests.rs +++ b/helios/src/scheduler/boundary_tests.rs @@ -63,6 +63,7 @@ fn scheduler_with_concurrency(snapshots: u32, mtp: bool, page_tokens: usize, act max_images: 4, patches_per_feature: 4, patch_capacities: vec![256, 1024, 4096, 16384], + patch_features: 0, }, draft_pages_per_request: 1, completion_inputs: vec![], diff --git a/helios/src/scheduler/cache_memory.rs b/helios/src/scheduler/cache_memory.rs index 503930bc9..eab9c1e73 100644 --- a/helios/src/scheduler/cache_memory.rs +++ b/helios/src/scheduler/cache_memory.rs @@ -1557,6 +1557,7 @@ mod tests { max_images: 4, patches_per_feature: 4, patch_capacities: vec![256, 1024, 4096, 16384], + patch_features: 0, }, draft_pages_per_request: 1, completion_inputs: vec![], diff --git a/helios/src/scheduler/tests.rs b/helios/src/scheduler/tests.rs index da16005de..e77497f91 100644 --- a/helios/src/scheduler/tests.rs +++ b/helios/src/scheduler/tests.rs @@ -141,6 +141,7 @@ fn scheduler_with_geometry(active: usize, pages: u32, snapshots: u32, page_token max_images: 4, patches_per_feature: 4, patch_capacities: vec![256, 1024, 4096, 16384], + patch_features: 0, }, draft_pages_per_request: 1, completion_inputs: vec![], @@ -575,6 +576,7 @@ fn configured_prefill_chunks_and_tails_preserve_alignment_and_live_page_extents( max_images: 4, patches_per_feature: 4, patch_capacities: vec![256, 1024, 4096, 16384], + patch_features: 0, }, draft_pages_per_request: 1, completion_inputs: vec![], @@ -655,6 +657,7 @@ fn invalid_prefill_limits_reject_before_request_resources_are_created() { max_images: 4, patches_per_feature: 4, patch_capacities: vec![256, 1024, 4096, 16384], + patch_features: 0, }, draft_pages_per_request: 1, completion_inputs: vec![], @@ -2360,6 +2363,7 @@ fn declared_model_capabilities_drive_state_slots_and_vision_buckets() { max_images: 2, patches_per_feature: 2, patch_capacities: vec![8, 32], + patch_features: 0, }, draft_pages_per_request: 1, completion_inputs: vec![], diff --git a/helios/src/scheduler/vision_window_tests.rs b/helios/src/scheduler/vision_window_tests.rs index 22f19ef66..70a4aa2b4 100644 --- a/helios/src/scheduler/vision_window_tests.rs +++ b/helios/src/scheduler/vision_window_tests.rs @@ -40,6 +40,7 @@ fn scheduler_with_resources( max_images: 4, patches_per_feature: 4, patch_capacities: vec![256, 1024, 4096, 16_384], + patch_features: 0, }, draft_pages_per_request: 1, completion_inputs: vec![], diff --git a/helios/src/server/config.rs b/helios/src/server/config.rs index c52069118..7727b4cdc 100644 --- a/helios/src/server/config.rs +++ b/helios/src/server/config.rs @@ -276,12 +276,14 @@ impl Bootstrap { return Err("image preparation identifier differs from its settings".into()); } let images = if model.contract.vision.enabled() { - Some(ImageProcessor::load( + let processor = ImageProcessor::load( frontend_settings .image .ok_or("vision requires prepared image settings")?, image_limits(&model.contract.vision, model.limits.max_sequence_tokens)?, - )?) + )?; + validate_loaded_image_processor(&model, &processor)?; + Some(processor) } else { if frontend_settings.image.is_some() { return Err("text-only model must not declare image settings".into()); @@ -426,6 +428,54 @@ impl ServerConfig { } } +pub(crate) fn validate_loaded_image_processor( + model: &ModelConfig, + processor: &ImageProcessor, +) -> Result<()> { + let vision = &model.contract.vision; + let width = processor.patch_features(); + if model.contract.frontend.image_layout == Some(crate::model::contract::ImageLayoutKind::Bracketed) { + let expected = vision.bracketed_patch_features(); + if width != expected { + return Err(format!( + "bracketed image layout patch width ({expected}) differs from image processor ({width}); re-export the core with vision.patch_features" + ) + .into()); + } + } else if vision.patch_features != 0 && width != vision.patch_features { + return Err(format!( + "image preparation patch width ({width}) differs from prepared vision.patch_features ({})", + vision.patch_features + ) + .into()); + } + if let (Some(span), Some(max_envelope)) = ( + model + .contract + .frontend + .image_tokens + .as_ref() + .and_then(|layout| layout.span.as_ref()), + processor.max_image_envelope_tokens(), + ) { + if max_envelope > model.limits.prefill_chunk_size { + return Err(format!( + "maximum image envelope ({max_envelope} tokens) exceeds prefill_chunk_size ({})", + model.limits.prefill_chunk_size + ) + .into()); + } + if max_envelope > span.max_tokens { + return Err(format!( + "maximum image envelope ({max_envelope} tokens) exceeds declared span max_tokens ({})", + span.max_tokens + ) + .into()); + } + } + Ok(()) +} + pub(crate) fn image_limits(vision: &crate::model::VisionCapabilities, context_tokens: usize) -> Result { ImageLimits::for_vision(vision, context_tokens) } @@ -449,6 +499,7 @@ mod tests { max_images: 4, patches_per_feature: merge, patch_capacities: vec![graph_patches], + patch_features: 0, }; vision.validate().unwrap(); let limits = image_limits(&vision, features * 3).unwrap(); @@ -884,4 +935,93 @@ mod tests { "{error}" ); } + + #[test] + fn loaded_gemma4_image_processor_validates_patch_width_and_envelope_chunk_bounds() { + use crate::{ + frontend::images::Gemma4ImageSettings, + model::contract::{ImageLayoutKind, ImageSpan, ImageTokenLayout}, + }; + + let make_model = |patch_features: usize, prefill_chunk_size: usize, span_max: usize| { + let mut model = + crate::frontend::test_support::model_config(crate::model::testing::metadata()); + model.limits.prefill_chunk_size = prefill_chunk_size; + model.limits.max_sequence_tokens = 8192; + model.limits.validate_prefill().unwrap(); + model.contract.vision = VisionCapabilities { + feature_slots: 1, + features_per_request: 1120, + max_images: 4, + patches_per_feature: 9, + patch_capacities: vec![10_080], + patch_features, + }; + model.contract.vision.validate().unwrap(); + model.contract.frontend.image_layout = Some(ImageLayoutKind::Bracketed); + model.contract.frontend.image_tokens = Some(ImageTokenLayout { + feature_token: 258_880, + span: Some(ImageSpan { + start_token: 255_999, + end_token: 258_882, + max_tokens: span_max, + interior_tokens: vec![], + unscoped_tokens: vec![], + }), + }); + model + }; + let load_gemma4 = |max_soft_tokens: usize| { + ImageProcessor::load( + ImageSettings::Gemma4(Gemma4ImageSettings { + patch_size: 16, + pooling_kernel_size: 3, + max_soft_tokens, + image_token: "<|image|>".into(), + start_token: "<|image>".into(), + end_token: "".into(), + }), + ImageLimits { + patches_per_feature: 9, + max_patches_per_image: 10_080, + max_total_patches: 10_080, + ..ImageLimits::default() + }, + ) + .unwrap() + }; + + let proc_1120 = load_gemma4(1120); + // Valid 64-aligned chunk boundaries around max_envelope = 1122: 1088 fails, 1152 passes. + assert!(validate_loaded_image_processor(&make_model(768, 1152, 1122), &proc_1120).is_ok()); + assert!( + validate_loaded_image_processor(&make_model(768, 1088, 1122), &proc_1120) + .unwrap_err() + .to_string() + .contains("prefill_chunk_size") + ); + // Exact span.max_tokens boundary: 1121 fails, 1122 passes. + assert!( + validate_loaded_image_processor(&make_model(768, 1152, 1121), &proc_1120) + .unwrap_err() + .to_string() + .contains("span max_tokens") + ); + // Missing patch_features (legacy 0 -> 1176) gives an actionable re-export error. + let legacy_err = validate_loaded_image_processor(&make_model(0, 1152, 1122), &proc_1120) + .unwrap_err() + .to_string(); + assert!(legacy_err.contains("re-export"), "{legacy_err}"); + // Explicit mismatched patch_features reports both actual and expected widths. + let mismatch_err = + validate_loaded_image_processor(&make_model(588, 1152, 1122), &proc_1120) + .unwrap_err() + .to_string(); + assert!(mismatch_err.contains("768") && mismatch_err.contains("588"), "{mismatch_err}"); + + let proc_280 = load_gemma4(280); + // Valid 64-aligned chunk boundaries around max_envelope = 282: 256 fails, 320 passes. + assert!(validate_loaded_image_processor(&make_model(768, 320, 282), &proc_280).is_ok()); + assert!(validate_loaded_image_processor(&make_model(768, 256, 282), &proc_280).is_err()); + } } diff --git a/helios/src/server/models.rs b/helios/src/server/models.rs index 998f67135..4fe97f891 100644 --- a/helios/src/server/models.rs +++ b/helios/src/server/models.rs @@ -397,6 +397,7 @@ mod tests { features_per_request: 256, patches_per_feature: 4, patch_capacities: vec![1024], + patch_features: 0, }; let vision = ModelCatalog::new(&model, &[], None).card; assert_eq!(vision["max_model_len"], 4096); @@ -481,6 +482,7 @@ mod tests { features_per_request: 256, patches_per_feature: 4, patch_capacities: vec![1024], + patch_features: 0, }; } model.contract.frontend.tools = tools.then(|| ToolParser { diff --git a/helios/src/server/protocol/decode.rs b/helios/src/server/protocol/decode.rs index 425ef2513..8347ef7c6 100644 --- a/helios/src/server/protocol/decode.rs +++ b/helios/src/server/protocol/decode.rs @@ -1250,6 +1250,7 @@ mod native_prompt_tests { max_images: 2, patches_per_feature: 4, patch_capacities: vec![geometry.patches], + patch_features: 0, }; config.contract.frontend.image_layout = Some(layout); config.contract.frontend.position_dimensions = if layout == ImageLayoutKind::Qwen { diff --git a/helios/src/server/request.rs b/helios/src/server/request.rs index ecd37897a..1d74edf9a 100644 --- a/helios/src/server/request.rs +++ b/helios/src/server/request.rs @@ -815,7 +815,8 @@ mod tests { let geometry = initial.geometry(1075, 1521).unwrap(); let vision = crate::model::VisionCapabilities { feature_slots: 1, max_images: 1, features_per_request: geometry.tokens, patches_per_feature: 9, - patch_capacities: vec![geometry.patches] }; + patch_capacities: vec![geometry.patches], + patch_features: 0, }; let context = 2 * geometry.tokens + 64; let limits = crate::server::config::image_limits(&vision, context).unwrap(); let processor = ImageProcessor::load(ImageSettings::Deepseek4 {}, limits).unwrap(); diff --git a/helios/src/server/request/tml_tests.rs b/helios/src/server/request/tml_tests.rs index 562af5523..edb3c6be0 100644 --- a/helios/src/server/request/tml_tests.rs +++ b/helios/src/server/request/tml_tests.rs @@ -279,6 +279,7 @@ fn images_preserve_reference_order_feature_spans_and_message_endpoints() { inkling.config.contract.vision = crate::model::VisionCapabilities { feature_slots: 4, max_images: 4, features_per_request: 16384, patches_per_feature: 4, patch_capacities: vec![65536], + patch_features: 0, }; let processor = ImageProcessor::load(ImageSettings::PaddedGrid {}, ImageLimits { max_images: 4, max_patches_per_image: 65536, max_total_patches: 65536, diff --git a/helios/src/server/runtime.rs b/helios/src/server/runtime.rs index 6e61dc23f..5ca6fcac0 100644 --- a/helios/src/server/runtime.rs +++ b/helios/src/server/runtime.rs @@ -3451,6 +3451,7 @@ mod tests { max_images: 4, patches_per_feature: 4, patch_capacities: vec![256, 1024, 4096, 16384], + patch_features: 0, }, draft_pages_per_request: 1, @@ -4225,6 +4226,7 @@ mod tests { max_images: 4, patches_per_feature: 4, patch_capacities: vec![256, 1024, 4096, 16384], + patch_features: 0, }, draft_pages_per_request: 1, diff --git a/helios/src/server/runtime/phase_tests.rs b/helios/src/server/runtime/phase_tests.rs index 6ca976e5d..d1720c62d 100644 --- a/helios/src/server/runtime/phase_tests.rs +++ b/helios/src/server/runtime/phase_tests.rs @@ -280,6 +280,7 @@ fn image_admission_queues_excess_images_and_admits_text() { max_images: 1, patches_per_feature: 4, patch_capacities: vec![256], + patch_features: 0, }; let vision_contract: crate::model::contract::PreparedContract = serde_json::from_str(include_str!("../../../tests/support/contracts/qwen38.json")).unwrap(); @@ -5477,6 +5478,7 @@ fn host_prefix_selects_whole_required_images_and_compacts_feature_indices() { max_images: 4, patches_per_feature: 4, patch_capacities: vec![256], + patch_features: 0, }; fixture.config.contract.frontend = serde_json::from_str::(include_str!( @@ -5542,6 +5544,7 @@ fn failed_host_restore_replans_all_images_from_the_shallower_prefix() { max_images: 4, patches_per_feature: 4, patch_capacities: vec![256], + patch_features: 0, }; fixture.config.contract.frontend = serde_json::from_str::(include_str!( @@ -5609,6 +5612,7 @@ fn image_materialization_failure_retires_only_its_request() { max_images: 4, patches_per_feature: 4, patch_capacities: vec![256], + patch_features: 0, }; fixture.config.contract.frontend = serde_json::from_str::(include_str!( @@ -5656,6 +5660,7 @@ fn prepared_image_window_stays_global_until_pack_or_cancellation() { max_images: 4, patches_per_feature: 4, patch_capacities: vec![256], + patch_features: 0, }; fixture.config.contract.frontend = serde_json::from_str::( include_str!("../../../tests/support/contracts/qwen38.json"), @@ -5722,6 +5727,7 @@ fn park_and_device_error_teardown_release_prepared_image_slot_for_next_request() max_images: 4, patches_per_feature: 4, patch_capacities: vec![256], + patch_features: 0, }; fixture.config.contract.frontend = serde_json::from_str::( include_str!("../../../tests/support/contracts/qwen38.json"), @@ -5919,6 +5925,7 @@ fn worker_restores_conditioned_windows_with_fresh_generation_and_unchanged_sampl max_images: 4, patches_per_feature: 4, patch_capacities: vec![256], + patch_features: 0, }; fixture.config.contract.frontend = serde_json::from_str::( include_str!("../../../tests/support/contracts/qwen38.json"), diff --git a/helios/tests/deepseek_requests.rs b/helios/tests/deepseek_requests.rs index ddcec058c..6a752293d 100644 --- a/helios/tests/deepseek_requests.rs +++ b/helios/tests/deepseek_requests.rs @@ -545,6 +545,7 @@ fn base64_images_follow_the_rendered_placeholder_order() { max_images: 4, patches_per_feature: 9, patch_capacities: vec![576, 1152, 2304, 4608, 9216], + patch_features: 0, }; let syntax = &mut f.config.contract.frontend; syntax.image_preparation = Some(ImagePreparationKind::DeepseekRowMajor); diff --git a/ignition/preparation/contract.py b/ignition/preparation/contract.py index a8c1f4672..0b71d422b 100644 --- a/ignition/preparation/contract.py +++ b/ignition/preparation/contract.py @@ -147,8 +147,14 @@ def core_parameter(name, default, *, minimum=None, maximum=None): def model_contract(*, vocabulary, input_vocabulary=None, vision=None, page_tokens, page_tables, graphs, frontend, regions, codec_layout=None, core_parameters=()): + """Build a version-3 `ModelContract` dict. + + `Bracketed` vision recipes whose per-patch float width differs from the legacy `1176` + default (for example `768` for Gemma 4) must set `vision["patch_features"]`. + """ result = dict(version=3, vocabulary=vocabulary, input_vocabulary=input_vocabulary or vocabulary, - vision={"feature_slots": 0, **(vision or dict(features_per_request=0, max_images=0, patches_per_feature=0, patch_capacities=[]))}, + vision={"feature_slots": 0, "patch_features": 0, + **(vision or dict(features_per_request=0, max_images=0, patches_per_feature=0, patch_capacities=[]))}, cache=dict(page_tokens=page_tokens, page_tables=page_tables, regions=regions, **({"codec_layout": codec_layout} if codec_layout else {})), graphs=graphs, frontend=frontend) if core_parameters: diff --git a/ignition/preparation/frontend.py b/ignition/preparation/frontend.py index befb094d3..80d37fb25 100644 --- a/ignition/preparation/frontend.py +++ b/ignition/preparation/frontend.py @@ -89,7 +89,8 @@ def _expected(config, values, label): raise ValueError(f"unsupported {label} {key}") -def image_settings(config, model, profile, qwen_model_type="qwen4_exp"): +def image_settings(config, model, profile, qwen_model_type="qwen4_exp", *, + tokenizer_config=None, snapshot=None): """Resolve the image settings the native frontend consumes for ``profile``. The Qwen profile serves two checkpoint families with one processor; ``qwen_model_type`` @@ -110,6 +111,66 @@ def image_settings(config, model, profile, qwen_model_type="qwen4_exp"): _expected(model["vision_config"], {"native_patch_size": 20, "adapter_merge_size": 2, "posemb_grid_size": 32, "temporal_patch_size": 2}, "padded-grid vision configuration") return {"padded_grid": {}} + if profile == "gemma4": + # Validate the canonical Gemma4ImageProcessor geometry (`image_processor.max_soft_tokens`, + # `patch_size=16`, `pooling_kernel_size=3`) and tokenizer envelope for `gemma4` / + # `gemma4_vision` checkpoints; encoder depth and width belong to the preparing recipe. + if not isinstance(config, dict): + raise ValueError("unsupported Gemma 4 processor") + _expected(config, {"processor_class": "Gemma4Processor"}, "Gemma 4 processor") + image = config.get("image_processor") + if not isinstance(image, dict): + raise ValueError("unsupported Gemma 4 image processor") + _expected(image, {"image_processor_type": "Gemma4ImageProcessor", "patch_size": 16, + "pooling_kernel_size": 3, "do_resize": True, "do_rescale": True, + "do_normalize": False, "image_mean": [0.0] * 3, "image_std": [1.0] * 3}, + "Gemma 4 image processor") + optional = {"resample": 3, "rescale_factor": 1 / 255, "do_convert_rgb": True} + _expected(image, {key: value for key, value in optional.items() if key in image}, + "Gemma 4 image processor") + max_soft_tokens = image.get("max_soft_tokens") + if type(max_soft_tokens) is not int or max_soft_tokens not in (70, 140, 280, 560, 1120): + raise ValueError("unsupported Gemma 4 max_soft_tokens") + if not isinstance(model, dict): + raise ValueError("unsupported Gemma 4 model configuration") + _expected(model, {"model_type": "gemma4"}, "Gemma 4 model configuration") + vision = model.get("vision_config") + if not isinstance(vision, dict): + raise ValueError("unsupported Gemma 4 vision configuration") + _expected(vision, {"model_type": "gemma4_vision", "patch_size": 16, + "pooling_kernel_size": 3}, "Gemma 4 vision configuration") + if not isinstance(tokenizer_config, dict) or snapshot is None: + raise ValueError( + "Gemma 4 image settings require tokenizer_config and snapshot to validate envelope tokens") + tokens = {} + for field, key in (("image_token", "image_token"), ("start_token", "boi_token"), + ("end_token", "eoi_token")): + if tokenizer_config.get(key) is None: + raise ValueError(f"missing Gemma 4 {key}") + value = _token(tokenizer_config[key]) + if not value: + raise ValueError(f"empty Gemma 4 {key}") + tokens[field] = value + if len(set(tokens.values())) != 3: + raise ValueError("Gemma 4 image envelope tokens must be distinct") + from tokenizers import Tokenizer + + tokenizer = Tokenizer.from_file(str(Path(snapshot) / "tokenizer.json")) + for field, id_key in (("image_token", "image_token_id"), ("start_token", "boi_token_id"), + ("end_token", "eoi_token_id")): + tok = tokens[field] + token_id = tokenizer.token_to_id(tok) + if token_id is None or tokenizer.encode(tok, add_special_tokens=False).ids != [token_id]: + raise ValueError(f"Gemma 4 {field} must encode as a single vocabulary token") + expected_id = model.get(id_key) + if expected_id is not None and (type(expected_id) is not int or expected_id != token_id): + raise ValueError(f"Gemma 4 {id_key} does not match tokenizer vocabulary") + return {"gemma4": dict( + patch_size=16, + pooling_kernel_size=3, + max_soft_tokens=max_soft_tokens, + **tokens, + )} if profile == "glm": _expected(config, {"processor_class": "Glm5NextProcessor"}, "GLM processor") image = config["image_processor"] @@ -232,20 +293,23 @@ def prepare_frontend(snapshot, *, eos_token_ids, image_profile=None, preprocesso if (not eos_token_ids or len(eos_token_ids) > 8 or len(set(eos_token_ids)) != len(eos_token_ids) or any(type(value) is not int or not 0 <= value < 2**32 for value in eos_token_ids)): raise ValueError("EOS token IDs must be one through eight distinct uint32 values") - result = {"tokenizer": tokenizer_settings(json.loads((snapshot / "tokenizer_config.json").read_text())), + tokenizer_config = json.loads((snapshot / "tokenizer_config.json").read_text()) + result = {"tokenizer": tokenizer_settings(tokenizer_config), "eos_token_ids": eos_token_ids} if prompt_encoder != PromptEncoder.PROMPT_JINJA: result["prompt_encoder"] = int(prompt_encoder) if image_profile is not None: + model_config = json.loads((snapshot / "config.json").read_text()) expected_profile = {PromptEncoder.DEEPSEEK_V4: "deepseek4", PromptEncoder.DEEPSEEK_V41: "deepseek_row_major"}.get(prompt_encoder) if expected_profile is not None: if image_profile != expected_profile: raise ValueError("image profile differs from the prompt encoder") result["image_placeholder_token_id"] = _native_image_placeholder( - snapshot, json.loads((snapshot / "config.json").read_text()), prompt_encoder) + snapshot, model_config, prompt_encoder) path = snapshot / "preprocessor_config.json" if preprocessor is None else Path(preprocessor) - result["image"] = image_settings({} if image_profile == "deepseek_row_major" else json.loads(path.read_text()), - json.loads((snapshot / "config.json").read_text()), image_profile, - qwen_model_type=qwen_model_type) + result["image"] = image_settings( + {} if image_profile == "deepseek_row_major" else json.loads(path.read_text()), + model_config, image_profile, qwen_model_type=qwen_model_type, + tokenizer_config=tokenizer_config, snapshot=snapshot) return result diff --git a/ignition/preparation/runtime_core_pb2.py b/ignition/preparation/runtime_core_pb2.py index 76789f968..11a9d820f 100644 --- a/ignition/preparation/runtime_core_pb2.py +++ b/ignition/preparation/runtime_core_pb2.py @@ -24,7 +24,7 @@ -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x12runtime_core.proto\x12\rflare.runtime\"\x99\x01\n\x0eProtectedIndex\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\x0f\n\x07\x63ore_id\x18\x02 \x01(\x0c\x12\x0e\n\x06signer\x18\x03 \x01(\x0c\x12*\n\x06groups\x18\x04 \x03(\x0b\x32\x1a.flare.runtime.SignedGroup\x12)\n\x05ranks\x18\x05 \x03(\x0b\x32\x1a.flare.runtime.SignedGroup\"<\n\x0bSignedGroup\x12\x0c\n\x04kind\x18\x01 \x01(\r\x12\x0c\n\x04\x62ody\x18\x02 \x01(\x0c\x12\x11\n\tsignature\x18\x03 \x01(\x0c\"\xcc\x01\n\x11PublisherMetadata\x12(\n\x05index\x18\x01 \x01(\x0b\x32\x19.flare.runtime.ModelIndex\x12\x11\n\tnamespace\x18\x02 \x01(\t\x12\x17\n\x0fofficial_source\x18\x03 \x01(\t\x12\x14\n\x0cgroup_hashes\x18\x04 \x03(\x0c\x12\x13\n\x0b\x64\x65velopment\x18\x05 \x01(\x08\x12\r\n\x05ranks\x18\x06 \x01(\r\x12\'\n\x07license\x18\x07 \x01(\x0b\x32\x16.flare.runtime.License\"%\n\x07License\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04link\x18\x02 \x01(\t\"F\n\x0fResourceCatalog\x12\x33\n\tresources\x18\x01 \x03(\x0b\x32 .flare.runtime.ProtectedResource\"^\n\x11ProtectedResource\x12\x0e\n\x06offset\x18\x01 \x01(\x04\x12\x14\n\x0cstored_bytes\x18\x02 \x01(\x04\x12\x13\n\x0bplain_bytes\x18\x03 \x01(\x04\x12\x0e\n\x06sha256\x18\x04 \x03(\x0c\"`\n\nStoredData\x12\x0e\n\x06nbytes\x18\x01 \x01(\x04\x12\x0e\n\x06sha256\x18\x02 \x01(\x0c\x12\x0e\n\x06offset\x18\x03 \x01(\x04\x12\"\n\x05parts\x18\x04 \x03(\x0b\x32\x13.flare.runtime.Span\"\xd9\x01\n\x0eRankProtection\x12\x0c\n\x04rank\x18\x01 \x01(\r\x12*\n\x06\x62undle\x18\x02 \x01(\x0b\x32\x1a.flare.runtime.BundleIndex\x12\x33\n\x0b\x65xecutables\x18\x03 \x01(\x0b\x32\x1e.flare.runtime.ResourceCatalog\x12/\n\x07support\x18\x04 \x01(\x0b\x32\x1e.flare.runtime.ResourceCatalog\x12\'\n\x04\x64\x61ta\x18\x05 \x01(\x0b\x32\x19.flare.runtime.StoredData\"\x8c\x04\n\nModelIndex\x12\x0f\n\x07version\x18\x01 \x01(\r\x12)\n\x05ranks\x18\x02 \x03(\x0b\x32\x1a.flare.runtime.BundleIndex\x12.\n\x0bpeer_memory\x18\x03 \x03(\x0b\x32\x19.flare.runtime.PeerMemory\x12$\n\x06\x61ssets\x18\x05 \x03(\x0b\x32\x14.flare.runtime.Asset\x12%\n\x06\x65ngram\x18\x06 \x01(\x0b\x32\x15.flare.runtime.Engram\x12\x43\n\x11sampling_defaults\x18\x07 \x01(\x0b\x32(.flare.runtime.DefaultSamplingParameters\x12\x31\n\x08\x66rontend\x18\x08 \x01(\x0b\x32\x1f.flare.runtime.FrontendSettings\x12\'\n\x07\x63luster\x18\t \x01(\x0b\x32\x16.flare.runtime.Cluster\x12\x30\n\x08\x63ontract\x18\n \x01(\x0b\x32\x1e.flare.runtime.ServingContract\x12\x33\n\x07rebuild\x18\x0b \x01(\x0b\x32\x1e.flare.runtime.RebuildManifestB\x02\x18\x01\x12\x37\n\x0bpreparation\x18\x0c \x01(\x0b\x32\".flare.runtime.PreparationManifestJ\x04\x08\x04\x10\x05\"\xf9\x01\n\x13PreparationManifest\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\x0e\n\x06recipe\x18\x02 \x01(\t\x12\x17\n\x0fsource_identity\x18\x03 \x01(\t\x12\x1d\n\x15\x63heckpoint_repository\x18\x04 \x01(\t\x12\x1b\n\x13\x63heckpoint_revision\x18\x05 \x01(\t\x12\x18\n\x10local_checkpoint\x18\x06 \x01(\x08\x12\x19\n\x11reproduction_args\x18\x07 \x03(\t\x12\x37\n\nparameters\x18\x08 \x03(\x0b\x32#.flare.runtime.PreparationParameter\"\x8c\x01\n\x14PreparationParameter\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x37\n\x05scope\x18\x02 \x01(\x0e\x32(.flare.runtime.PreparationParameterScope\x12.\n\x05value\x18\x03 \x01(\x0b\x32\x1f.flare.runtime.PreparationValue\"\xc6\x01\n\x10PreparationValue\x12\x14\n\nbool_value\x18\x01 \x01(\x08H\x00\x12\x13\n\tint_value\x18\x02 \x01(\x03H\x00\x12\x14\n\nuint_value\x18\x03 \x01(\x04H\x00\x12\x15\n\x0b\x66loat_value\x18\x04 \x01(\x01H\x00\x12\x16\n\x0cstring_value\x18\x05 \x01(\tH\x00\x12\x39\n\nlist_value\x18\x06 \x01(\x0b\x32#.flare.runtime.PreparationValueListH\x00\x42\x07\n\x05value\"G\n\x14PreparationValueList\x12/\n\x06values\x18\x01 \x03(\x0b\x32\x1f.flare.runtime.PreparationValue\"\xdb\x07\n\x0fRebuildManifest\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\x0e\n\x06recipe\x18\x02 \x01(\t\x12\x17\n\x0fsource_identity\x18\x03 \x01(\t\x12\x1d\n\x15\x63heckpoint_repository\x18\x04 \x01(\t\x12\x1b\n\x13\x63heckpoint_revision\x18\x05 \x01(\t\x12\x17\n\x0ftensor_parallel\x18\x06 \x01(\r\x12\x17\n\x0fmax_concurrency\x18\x07 \x01(\x04\x12\x15\n\rprefill_chunk\x18\x08 \x01(\x04\x12\x19\n\x11image_concurrency\x18\t \x01(\x04\x12\x18\n\x10\x63ontext_parallel\x18\n \x01(\x08\x12\x16\n\x0estream_overlap\x18\x0b \x01(\x08\x12\x15\n\rmixed_prefill\x18\x0c \x01(\x08\x12%\n\x18\x65xpert_scale_compression\x18\r \x01(\tH\x00\x88\x01\x01\x12\x18\n\x10mla_compute_mode\x18\x0e \x01(\t\x12\x11\n\troce_ring\x18\x0f \x01(\x08\x12\x14\n\x0conline_mxfp8\x18\x10 \x01(\x08\x12\x1b\n\x13language_model_only\x18\x11 \x01(\x08\x12\x36\n\x0bspeculation\x18\x12 \x01(\x0b\x32!.flare.runtime.RebuildSpeculation\x12\x19\n\x11\x63ompiled_forwards\x18\x13 \x01(\x08\x12\x15\n\rreserve_bytes\x18\x14 \x01(\x04\x12\x18\n\x10local_checkpoint\x18\x15 \x01(\x08\x12\x12\n\nroce_chain\x18\x16 \x01(\x08\x12\x1e\n\x16shard_hyperconnections\x18\x18 \x01(\x08\x12\x1c\n\x14\x66orce_moe_decode_a16\x18\x1b \x01(\x08\x12\x19\n\x11row_shard_prefill\x18\x1c \x01(\x08\x12\x1a\n\x12online_mxfp8_scope\x18\x1e \x01(\t\x12\x1d\n\x15\x63ontext_parallel_size\x18\x1f \x01(\r\x12\x17\n\x0fprompt_logprobs\x18 \x01(\x08\x12\x17\n\x0f\x61utotune_effort\x18! \x01(\t\x12 \n\x18native_dense_activations\x18\" \x01(\x08\x12\x17\n\x0flock_gpu_clocks\x18# \x01(\x08\x12\x19\n\x11reproduction_args\x18$ \x03(\t:\x02\x18\x01\x42\x1b\n\x19_expert_scale_compressionJ\x04\x08\x17\x10\x18J\x04\x08\x19\x10\x1aJ\x04\x08\x1a\x10\x1bR\x0cjoint_tuningR\x11\x63ollective_tuningR\x16\x63ollective_ladder_json\"\x82\x04\n\x12RebuildSpeculation\x12\x14\n\x0c\x64raft_tokens\x18\x01 \x01(\r\x12\x10\n\x08\x61\x64\x61ptive\x18\x02 \x01(\x08\x12\x17\n\x0fproposal_source\x18\x03 \x01(\t\x12\x16\n\x0ehistory_drafts\x18\x04 \x01(\x08\x12\x16\n\x0etoken_capacity\x18\x05 \x01(\x04\x12\x1b\n\x13packed_verification\x18\x06 \x01(\x08\x12\x1e\n\x16\x64raft_prefix_selection\x18\x07 \x01(\t\x12$\n\x17\x64raft_head_quantization\x18\x08 \x01(\tH\x00\x88\x01\x01\x12%\n\x18markov_head_quantization\x18\t \x01(\tH\x01\x88\x01\x01\x12\x19\n\x0cgraph_budget\x18\n \x01(\x04H\x02\x88\x01\x01\x12$\n\x1cvocabulary_parallel_sampling\x18\x0b \x01(\x08\x12\x0e\n\x06method\x18\x0c \x01(\t\x12\x10\n\x08mtp_only\x18\r \x01(\x08\x12$\n\x17\x64raft_body_quantization\x18\x0e \x01(\tH\x03\x88\x01\x01:\x02\x18\x01\x42\x1a\n\x18_draft_head_quantizationB\x1b\n\x19_markov_head_quantizationB\x0f\n\r_graph_budgetB\x1a\n\x18_draft_body_quantization\"e\n\x0eRebuildWeights\x12\x0f\n\x07version\x18\x01 \x01(\r\x12-\n\x07tensors\x18\x02 \x03(\x0b\x32\x1c.flare.runtime.RebuildTensor\x12\x13\n\x0bunavailable\x18\x03 \x03(\t\"\xa2\x01\n\rRebuildTensor\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05\x64type\x18\x02 \x01(\t\x12\x15\n\relement_bytes\x18\x03 \x01(\r\x12\r\n\x05shape\x18\x04 \x03(\x04\x12\x0e\n\x06stride\x18\x05 \x03(\x04\x12\x13\n\x0blayout_type\x18\x06 \x01(\t\x12)\n\x07storage\x18\x07 \x01(\x0b\x32\x18.flare.runtime.Reference\"\xcb\x06\n\x0fServingContract\x12\x10\n\x08model_id\x18\x01 \x01(\t\x12\x10\n\x08identity\x18\x02 \x01(\t\x12\x34\n\x0emodel_contract\x18\x03 \x01(\x0b\x32\x1c.flare.runtime.ModelContract\x12\x1b\n\x13max_sequence_tokens\x18\x04 \x01(\x04\x12\x1a\n\x12prefill_chunk_size\x18\x05 \x01(\x04\x12\r\n\x05pages\x18\x06 \x01(\x04\x12\x12\n\nstate_rows\x18\x07 \x01(\x04\x12\x11\n\tsnapshots\x18\x08 \x01(\x04\x12\x13\n\x0bpage_tokens\x18\t \x01(\x04\x12\x1a\n\x12speculative_widths\x18\x0b \x03(\x04\x12$\n\x17speculative_fixed_width\x18\x0c \x01(\x04H\x00\x88\x01\x01\x12\x16\n\x0ehistory_drafts\x18\r \x01(\x08\x12#\n\x1bspeculative_proposal_source\x18\x0e \x01(\t\x12\x1b\n\x0emax_new_tokens\x18\x0f \x01(\x04H\x01\x88\x01\x01\x12\x17\n\nmax_active\x18\x10 \x01(\x04H\x02\x88\x01\x01\x12\x14\n\x0cserved_names\x18\x11 \x03(\t\x12\x1a\n\rreserve_bytes\x18\x12 \x01(\x04H\x03\x88\x01\x01\x12\x1b\n\x0equeue_capacity\x18\x13 \x01(\x04H\x04\x88\x01\x01\x12\x1d\n\x10\x66rontend_workers\x18\x14 \x01(\x04H\x05\x88\x01\x01\x12\x1b\n\x0emax_body_bytes\x18\x15 \x01(\x04H\x06\x88\x01\x01\x12\x14\n\x0c\x63ontext_hint\x18\x16 \x01(\t\x12\x15\n\rcapacity_hint\x18\x17 \x01(\t\x12\"\n\x1aspeculative_token_capacity\x18\x18 \x01(\x04\x12 \n\x13\x64\x65\x63ode_weight_bytes\x18\x19 \x01(\x04H\x07\x88\x01\x01\x42\x1a\n\x18_speculative_fixed_widthB\x11\n\x0f_max_new_tokensB\r\n\x0b_max_activeB\x10\n\x0e_reserve_bytesB\x11\n\x0f_queue_capacityB\x13\n\x11_frontend_workersB\x11\n\x0f_max_body_bytesB\x16\n\x14_decode_weight_bytesJ\x04\x08\n\x10\x0b\"\xc2\x02\n\rModelContract\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\x12\n\nvocabulary\x18\x02 \x01(\x04\x12\x18\n\x10input_vocabulary\x18\x03 \x01(\x04\x12-\n\x06vision\x18\x04 \x01(\x0b\x32\x1d.flare.runtime.VisionCapacity\x12+\n\x05\x63\x61\x63he\x18\x05 \x01(\x0b\x32\x1c.flare.runtime.CacheContract\x12,\n\x06graphs\x18\x06 \x03(\x0b\x32\x1c.flare.runtime.GraphContract\x12\x31\n\x08\x66rontend\x18\x07 \x01(\x0b\x32\x1f.flare.runtime.FrontendContract\x12\x35\n\x0f\x63ore_parameters\x18\x08 \x03(\x0b\x32\x1c.flare.runtime.CoreParameter\"}\n\rCoreParameter\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x1a\n\rdefault_value\x18\x02 \x01(\x02H\x00\x88\x01\x01\x12\x30\n\x05range\x18\x03 \x01(\x0b\x32!.flare.runtime.CoreParameterRangeB\x10\n\x0e_default_value\"H\n\x12\x43oreParameterRange\x12\x10\n\x03min\x18\x01 \x01(\x02H\x00\x88\x01\x01\x12\x10\n\x03max\x18\x02 \x01(\x02H\x01\x88\x01\x01\x42\x06\n\x04_minB\x06\n\x04_max\"\x90\x01\n\x0eVisionCapacity\x12\x15\n\rfeature_slots\x18\x05 \x01(\x04\x12\x1c\n\x14\x66\x65\x61tures_per_request\x18\x01 \x01(\x04\x12\x12\n\nmax_images\x18\x02 \x01(\x04\x12\x1b\n\x13patches_per_feature\x18\x03 \x01(\x04\x12\x18\n\x10patch_capacities\x18\x04 \x03(\x04\"\xb8\x01\n\rCacheContract\x12\x13\n\x0bpage_tokens\x18\x01 \x01(\x04\x12-\n\x07regions\x18\x02 \x03(\x0b\x32\x1c.flare.runtime.HistoryRegion\x12\x31\n\x0bpage_tables\x18\x03 \x03(\x0b\x32\x1c.flare.runtime.PageTableView\x12\x30\n\x0c\x63odec_layout\x18\x04 \x01(\x0b\x32\x1a.flare.runtime.CodecLayout\"r\n\x0b\x43odecLayout\x12\x10\n\x08revision\x18\x01 \x01(\r\x12)\n\x06\x66ields\x18\x02 \x03(\x0b\x32\x19.flare.runtime.CodecField\x12\x17\n\ngpu_module\x18\x03 \x01(\tH\x00\x88\x01\x01\x42\r\n\x0b_gpu_module\"N\n\nCodecField\x12\x0e\n\x06\x62uffer\x18\x01 \x01(\t\x12\x0e\n\x06offset\x18\x02 \x01(\x04\x12\x0e\n\x06length\x18\x03 \x01(\x04\x12\x10\n\x08\x65ncoding\x18\x04 \x01(\r\"\x96\x01\n\rHistoryRegion\x12(\n\x04kind\x18\x01 \x01(\x0e\x32\x1a.flare.runtime.HistoryKind\x12)\n\x07storage\x18\x02 \x01(\x0b\x32\x18.flare.runtime.StateView\x12\x19\n\x11tokens_per_record\x18\x03 \x01(\x04\x12\x15\n\rwindow_tokens\x18\x04 \x01(\x04\"4\n\rPageTableView\x12\x0e\n\x06\x62uffer\x18\x01 \x01(\t\x12\x13\n\x0bpage_offset\x18\x02 \x01(\x04\"\xc4\x01\n\x0cValueBinding\x12\x0e\n\x06\x62uffer\x18\x01 \x01(\t\x12*\n\x06source\x18\x02 \x01(\x0e\x32\x1a.flare.runtime.ValueSource\x12.\n\x08indexing\x18\x03 \x01(\x0e\x32\x1c.flare.runtime.InputIndexing\x12\x14\n\x0cvalue_offset\x18\x04 \x01(\x12\x12\x0f\n\x07padding\x18\x05 \x01(\x12\x12\x0e\n\x06tensor\x18\x06 \x01(\t\x12\x11\n\tparameter\x18\x07 \x01(\t\"K\n\tStateView\x12\x0e\n\x06\x62uffer\x18\x01 \x01(\t\x12\x0e\n\x06offset\x18\x02 \x01(\x04\x12\x0e\n\x06stride\x18\x03 \x01(\x04\x12\x0e\n\x06nbytes\x18\x04 \x01(\x04\"e\n\x0bStateAccess\x12&\n\x04view\x18\x01 \x01(\x0b\x32\x18.flare.runtime.StateView\x12.\n\x06\x61\x63\x63\x65ss\x18\x02 \x01(\x0e\x32\x1e.flare.runtime.StateAccessKind\"O\n\x10\x43ompletionCursor\x12\'\n\x05state\x18\x01 \x01(\x0b\x32\x18.flare.runtime.StateView\x12\x12\n\nlag_tokens\x18\x02 \x01(\x04\"4\n\x0cTunedBinding\x12\x0e\n\x06\x62uffer\x18\x01 \x01(\t\x12\x14\n\x0ctuning_graph\x18\x02 \x01(\t\"\xfa\x02\n\rGraphContract\x12\r\n\x05graph\x18\x01 \x01(\t\x12+\n\x06inputs\x18\x02 \x03(\x0b\x32\x1b.flare.runtime.ValueBinding\x12)\n\x05state\x18\x03 \x03(\x0b\x32\x1a.flare.runtime.StateAccess\x12\x1e\n\x16state_rows_per_request\x18\x04 \x01(\x04\x12\x35\n\x0c\x64raft_cursor\x18\x05 \x01(\x0b\x32\x1f.flare.runtime.CompletionCursor\x12\x18\n\x10\x65mbedding_tables\x18\x06 \x03(\r\x12/\n\rpending_token\x18\x07 \x01(\x0b\x32\x18.flare.runtime.StateView\x12+\n\x04kind\x18\x08 \x01(\x0e\x32\x1d.flare.runtime.GraphOperation\x12\x33\n\x0etuned_bindings\x18\t \x03(\x0b\x32\x1b.flare.runtime.TunedBinding\"k\n\nToolParser\x12+\n\x04kind\x18\x01 \x01(\x0e\x32\x1d.flare.runtime.ToolParserKind\x12\x19\n\x11wrapping_newlines\x18\x02 \x01(\r\x12\x15\n\rtag_separator\x18\x03 \x01(\t\"\x95\x01\n\x0fReasoningParser\x12\x30\n\x04kind\x18\x01 \x01(\x0e\x32\".flare.runtime.ReasoningParserKind\x12\x0c\n\x04open\x18\x02 \x01(\t\x12\r\n\x05\x63lose\x18\x03 \x01(\t\x12\x19\n\x11wrapping_newlines\x18\x04 \x01(\r\x12\x18\n\x10terminal_markers\x18\x05 \x03(\t\"\xca\x01\n\x0ePrefixBoundary\x12\r\n\x05roles\x18\x01 \x03(\t\x12\x18\n\x0b\x61ppend_role\x18\x02 \x01(\tH\x00\x88\x01\x01\x12\x1e\n\x16\x63ontinue_final_message\x18\x03 \x01(\x08\x12\x18\n\x10minimum_messages\x18\x04 \x01(\x04\x12\x16\n\x0erequired_start\x18\x05 \x01(\t\x12\x14\n\x0crequired_end\x18\x06 \x01(\t\x12\x17\n\x0frequired_marker\x18\x07 \x01(\tB\x0e\n\x0c_append_role\"y\n\tImageSpan\x12\x13\n\x0bstart_token\x18\x01 \x01(\r\x12\x11\n\tend_token\x18\x02 \x01(\r\x12\x12\n\nmax_tokens\x18\x03 \x01(\x04\x12\x17\n\x0finterior_tokens\x18\x04 \x03(\r\x12\x17\n\x0funscoped_tokens\x18\x05 \x03(\r\"Q\n\x10ImageTokenLayout\x12\x15\n\rfeature_token\x18\x01 \x01(\r\x12&\n\x04span\x18\x02 \x01(\x0b\x32\x18.flare.runtime.ImageSpan\"\xf2\x03\n\x10\x46rontendContract\x12(\n\x05tools\x18\x01 \x01(\x0b\x32\x19.flare.runtime.ToolParser\x12\x31\n\treasoning\x18\x02 \x01(\x0b\x32\x1e.flare.runtime.ReasoningParser\x12\x43\n\x11image_preparation\x18\x03 \x01(\x0e\x32#.flare.runtime.ImagePreparationKindH\x00\x88\x01\x01\x12\x39\n\x0cimage_layout\x18\x04 \x01(\x0e\x32\x1e.flare.runtime.ImageLayoutKindH\x01\x88\x01\x01\x12\x17\n\x0frejected_tokens\x18\x05 \x03(\r\x12\x1b\n\x13position_dimensions\x18\x06 \x01(\r\x12\x18\n\x10\x61ssistant_marker\x18\x07 \x01(\t\x12\x1b\n\x13message_end_markers\x18\x08 \x03(\t\x12\x36\n\x0fprefix_boundary\x18\t \x01(\x0b\x32\x1d.flare.runtime.PrefixBoundary\x12\x35\n\x0cimage_tokens\x18\n \x01(\x0b\x32\x1f.flare.runtime.ImageTokenLayoutB\x14\n\x12_image_preparationB\x0f\n\r_image_layout\"1\n\x07\x43luster\x12\r\n\x05world\x18\x01 \x01(\r\x12\x11\n\texport_id\x18\x03 \x01(\tJ\x04\x08\x02\x10\x03\"\x8c\x03\n\x19\x44\x65\x66\x61ultSamplingParameters\x12\x11\n\x04seed\x18\x01 \x01(\x04H\x00\x88\x01\x01\x12\x18\n\x0btemperature\x18\x02 \x01(\x02H\x01\x88\x01\x01\x12\x12\n\x05top_k\x18\x03 \x01(\x05H\x02\x88\x01\x01\x12\x12\n\x05top_p\x18\x04 \x01(\x02H\x03\x88\x01\x01\x12\x12\n\x05min_p\x18\x05 \x01(\x02H\x04\x88\x01\x01\x12\x1f\n\x12repetition_penalty\x18\x06 \x01(\x02H\x05\x88\x01\x01\x12\x1d\n\x10presence_penalty\x18\x07 \x01(\x02H\x06\x88\x01\x01\x12\x1e\n\x11\x66requency_penalty\x18\x08 \x01(\x02H\x07\x88\x01\x01\x12-\n\x06ranges\x18\t \x01(\x0b\x32\x1d.flare.runtime.SamplingRangesB\x07\n\x05_seedB\x0e\n\x0c_temperatureB\x08\n\x06_top_kB\x08\n\x06_top_pB\x08\n\x06_min_pB\x15\n\x13_repetition_penaltyB\x13\n\x11_presence_penaltyB\x14\n\x12_frequency_penalty\"H\n\x12SamplingFloatRange\x12\x10\n\x03min\x18\x01 \x01(\x02H\x00\x88\x01\x01\x12\x10\n\x03max\x18\x02 \x01(\x02H\x01\x88\x01\x01\x42\x06\n\x04_minB\x06\n\x04_max\"F\n\x10SamplingIntRange\x12\x10\n\x03min\x18\x01 \x01(\x05H\x00\x88\x01\x01\x12\x10\n\x03max\x18\x02 \x01(\x05H\x01\x88\x01\x01\x42\x06\n\x04_minB\x06\n\x04_max\"\x96\x03\n\x0eSamplingRanges\x12\x36\n\x0btemperature\x18\x01 \x01(\x0b\x32!.flare.runtime.SamplingFloatRange\x12.\n\x05top_k\x18\x02 \x01(\x0b\x32\x1f.flare.runtime.SamplingIntRange\x12\x30\n\x05top_p\x18\x03 \x01(\x0b\x32!.flare.runtime.SamplingFloatRange\x12\x30\n\x05min_p\x18\x04 \x01(\x0b\x32!.flare.runtime.SamplingFloatRange\x12=\n\x12repetition_penalty\x18\x05 \x01(\x0b\x32!.flare.runtime.SamplingFloatRange\x12;\n\x10presence_penalty\x18\x06 \x01(\x0b\x32!.flare.runtime.SamplingFloatRange\x12<\n\x11\x66requency_penalty\x18\x07 \x01(\x0b\x32!.flare.runtime.SamplingFloatRange\"\xc5\x02\n\x10\x46rontendSettings\x12\x33\n\ttokenizer\x18\x01 \x01(\x0b\x32 .flare.runtime.TokenizerSettings\x12+\n\x05image\x18\x02 \x01(\x0b\x32\x1c.flare.runtime.ImageSettings\x12\x15\n\reos_token_ids\x18\x03 \x03(\r\x12:\n\x11template_encoding\x18\x04 \x01(\x0e\x32\x1f.flare.runtime.TemplateEncoding\x12\x34\n\x0eprompt_encoder\x18\x05 \x01(\x0e\x32\x1c.flare.runtime.PromptEncoder\x12\'\n\x1aimage_placeholder_token_id\x18\x06 \x01(\rH\x00\x88\x01\x01\x42\x1d\n\x1b_image_placeholder_token_id\"\xdc\x02\n\x11TokenizerSettings\x12\x16\n\tbos_token\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x16\n\teos_token\x18\x02 \x01(\tH\x01\x88\x01\x01\x12\x16\n\tunk_token\x18\x03 \x01(\tH\x02\x88\x01\x01\x12\x16\n\tsep_token\x18\x04 \x01(\tH\x03\x88\x01\x01\x12\x16\n\tpad_token\x18\x05 \x01(\tH\x04\x88\x01\x01\x12\x16\n\tcls_token\x18\x06 \x01(\tH\x05\x88\x01\x01\x12\x17\n\nmask_token\x18\x07 \x01(\tH\x06\x88\x01\x01\x12;\n\x19\x61\x64\x64itional_special_tokens\x18\x08 \x01(\x0b\x32\x18.flare.runtime.TokenListB\x0c\n\n_bos_tokenB\x0c\n\n_eos_tokenB\x0c\n\n_unk_tokenB\x0c\n\n_sep_tokenB\x0c\n\n_pad_tokenB\x0c\n\n_cls_tokenB\r\n\x0b_mask_token\"\x1b\n\tTokenList\x12\x0e\n\x06values\x18\x01 \x03(\t\"\xfc\x03\n\rImageSettings\x12\x30\n\x04qwen\x18\x01 \x01(\x0b\x32 .flare.runtime.QwenImageSettingsH\x00\x12\x30\n\x04mimo\x18\x02 \x01(\x0b\x32 .flare.runtime.MimoImageSettingsH\x00\x12)\n\tdeepseek4\x18\x03 \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x12\'\n\x07moonvit\x18\x04 \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x12$\n\x04step\x18\x05 \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x12%\n\x05radio\x18\x06 \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x12J\n\x12\x64\x65\x65pseek_row_major\x18\x07 \x01(\x0b\x32,.flare.runtime.DeepseekRowMajorImageSettingsH\x00\x12#\n\x03glm\x18\x08 \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x12=\n\x0bpatch_merge\x18\t \x01(\x0b\x32&.flare.runtime.PatchMergeImageSettingsH\x00\x12+\n\x0bpadded_grid\x18\n \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x42\t\n\x07profile\"\xb9\x01\n\x17PatchMergeImageSettings\x12\x12\n\npatch_size\x18\x01 \x01(\r\x12\x12\n\nmin_pixels\x18\x02 \x01(\x04\x12\x12\n\nmax_pixels\x18\x03 \x01(\x04\x12\x12\n\nimage_mean\x18\x04 \x03(\x02\x12\x11\n\timage_std\x18\x05 \x03(\x02\x12\x13\n\x0bimage_token\x18\x06 \x01(\t\x12\x13\n\x0bstart_token\x18\x07 \x01(\t\x12\x11\n\tend_token\x18\x08 \x01(\t\"\x87\x01\n\x1d\x44\x65\x65pseekRowMajorImageSettings\x12\x12\n\nmin_pixels\x18\x01 \x01(\x04\x12\x12\n\nmax_tokens\x18\x02 \x01(\x04\x12#\n\x16max_width_height_ratio\x18\x03 \x01(\x04H\x00\x88\x01\x01\x42\x19\n\x17_max_width_height_ratio\"\x82\x01\n\x11QwenImageSettings\x12\x12\n\nmin_pixels\x18\x01 \x01(\x04\x12\x12\n\nmax_pixels\x18\x02 \x01(\x04\x12\x15\n\rposition_side\x18\x03 \x01(\r\x12\x16\n\x0eimage_token_id\x18\x04 \x01(\r\x12\x16\n\x0evideo_token_id\x18\x05 \x01(\r\"b\n\x11MimoImageSettings\x12\x12\n\nmin_pixels\x18\x01 \x01(\x04\x12\x12\n\nmax_pixels\x18\x02 \x01(\x04\x12\x12\n\nimage_mean\x18\x03 \x03(\x02\x12\x11\n\timage_std\x18\x04 \x03(\x02\"|\n\x06\x45ngram\x12\x11\n\ttoken_map\x18\x01 \x03(\r\x12\x14\n\x0cpad_token_id\x18\x02 \x01(\r\x12\x1d\n\x15\x63ompressed_vocabulary\x18\x03 \x01(\r\x12*\n\x06tables\x18\x04 \x03(\x0b\x32\x1a.flare.runtime.EngramTable\"\x99\x04\n\x0b\x45ngramTable\x12\r\n\x05layer\x18\x01 \x01(\r\x12\x0c\n\x04rows\x18\x02 \x01(\x04\x12\x17\n\x0f\x65mbedding_width\x18\x03 \x01(\r\x12\x13\n\x0bscale_block\x18\x04 \x01(\r\x12$\n\x07weights\x18\x05 \x01(\x0b\x32\x13.flare.runtime.Span\x12#\n\x06scales\x18\x06 \x01(\x0b\x32\x13.flare.runtime.Span\x12\'\n\x04hash\x18\x07 \x01(\x0b\x32\x19.flare.runtime.EngramHash\x12\x15\n\rweight_buffer\x18\x08 \x01(\t\x12\x14\n\x0cscale_buffer\x18\t \x01(\t\x12\x13\n\x0bhash_buffer\x18\n \x01(\t\x12\x13\n\x0bready_event\x18\x0b \x01(\t\x12\x35\n\x08\x65ncoding\x18\x0c \x01(\x0e\x32#.flare.runtime.EngramTable.Encoding\x12\x16\n\x0erequest_buffer\x18\r \x01(\t\x12\x14\n\x0cglobal_scale\x18\x0e \x01(\x02\x12/\n\x06shards\x18\x0f \x03(\x0b\x32\x1f.flare.runtime.EngramTableShard\x12\x17\n\x0fprefetch_buffer\x18\x10 \x01(\t\"E\n\x08\x45ncoding\x12\x0f\n\x0bUNSPECIFIED\x10\x00\x12\x11\n\rFP8_E4M3_E8M0\x10\x01\x12\x15\n\x11NVFP4_E4M3_GLOBAL\x10\x02\"\x8c\x01\n\x10\x45ngramTableShard\x12\x0c\n\x04rank\x18\x01 \x01(\r\x12\x11\n\tfirst_row\x18\x02 \x01(\x04\x12\x0c\n\x04rows\x18\x03 \x01(\x04\x12$\n\x07weights\x18\x04 \x01(\x0b\x32\x13.flare.runtime.Span\x12#\n\x06scales\x18\x05 \x01(\x0b\x32\x13.flare.runtime.Span\"\xc3\x01\n\nEngramHash\x12\x30\n\x06method\x18\x01 \x01(\x0e\x32 .flare.runtime.EngramHash.Method\x12\x0e\n\x06orders\x18\x02 \x03(\r\x12\x13\n\x0bmultipliers\x18\x03 \x03(\x04\x12\x0e\n\x06primes\x18\x04 \x03(\x04\x12\x0f\n\x07offsets\x18\x05 \x03(\x04\"=\n\x06Method\x12\x0f\n\x0bUNSPECIFIED\x10\x00\x12\x0e\n\nXOR_MODULO\x10\x01\x12\x12\n\x0e\x45OS_XOR_MODULO\x10\x02\"K\n\x05\x41sset\x12\x0c\n\x04name\x18\x01 \x01(\t\x12$\n\x07payload\x18\x02 \x01(\x0b\x32\x13.flare.runtime.Span\x12\x0e\n\x06sha256\x18\x03 \x01(\t\"\xd3\x04\n\x0b\x42undleIndex\x12\x14\n\x0c\x61rchitecture\x18\x01 \x03(\x05\x12.\n\x0b\x61llocations\x18\x02 \x03(\x0b\x32\x19.flare.runtime.Allocation\x12&\n\x07modules\x18\x03 \x03(\x0b\x32\x15.flare.runtime.Module\x12*\n\tfunctions\x18\x04 \x03(\x0b\x32\x17.flare.runtime.Function\x12)\n\x06graphs\x18\x05 \x03(\x0b\x32\x19.flare.runtime.GraphIndex\x12\x30\n\x0creservations\x18\x06 \x03(\x0b\x32\x1a.flare.runtime.Reservation\x12+\n\texecution\x18\x07 \x01(\x0b\x32\x18.flare.runtime.Execution\x12\'\n\x07\x63ontext\x18\x08 \x01(\x0b\x32\x16.flare.runtime.Context\x12<\n\tresources\x18\t \x03(\x0b\x32).flare.runtime.BundleIndex.ResourcesEntry\x12\x0e\n\x06\x65vents\x18\n \x03(\t\x12*\n\x04roce\x18\x0b \x01(\x0b\x32\x1c.flare.runtime.RoceTransport\x12\x36\n\x0frebuild_weights\x18\x0c \x01(\x0b\x32\x1d.flare.runtime.RebuildWeights\x1a\x45\n\x0eResourcesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\"\n\x05value\x18\x02 \x01(\x0b\x32\x13.flare.runtime.Span:\x02\x38\x01\"\xf8\x01\n\rRoceTransport\x12\x11\n\tproxy_abi\x18\x01 \x01(\r\x12\r\n\x05world\x18\x02 \x01(\r\x12\x0c\n\x04rank\x18\x03 \x01(\r\x12\x16\n\x0eregion_address\x18\x04 \x01(\x04\x12\x14\n\x0cregion_bytes\x18\x05 \x01(\x04\x12\x18\n\x10\x63ounters_address\x18\x06 \x01(\x04\x12\x16\n\x0e\x63ounters_bytes\x18\x07 \x01(\x04\x12\x12\n\nslot_bytes\x18\x08 \x01(\x04\x12\x12\n\npipe_bytes\x18\t \x01(\x04\x12\x13\n\x0b\x63trl_offset\x18\n \x01(\x04\x12\x14\n\x0cvarlen_bytes\x18\x10 \x01(\x04J\x04\x08\x0b\x10\x10\"v\n\nGraphIndex\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05\x66lags\x18\x02 \x01(\x04\x12\x10\n\x08resource\x18\x03 \x01(\t\x12\x12\n\nnode_count\x18\x04 \x01(\x04\x12\x12\n\nedge_count\x18\x05 \x01(\x04\x12\x11\n\tfunctions\x18\x06 \x03(\x04\"M\n\nPeerMemory\x12\r\n\x05owner\x18\x01 \x01(\r\x12\x0f\n\x07\x61\x64\x64ress\x18\x02 \x01(\x04\x12\x0e\n\x06nbytes\x18\x03 \x01(\x04\x12\x0f\n\x07readers\x18\x04 \x03(\r\"M\n\x07\x43ontext\x12\r\n\x05\x66lags\x18\x01 \x01(\r\x12\r\n\x05\x63\x61\x63he\x18\x02 \x01(\x05\x12$\n\x06limits\x18\x03 \x03(\x0b\x32\x14.flare.runtime.Limit\"\"\n\x05Limit\x12\n\n\x02id\x18\x01 \x01(\x04\x12\r\n\x05value\x18\x02 \x01(\x04\".\n\x0bReservation\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\x04\x12\x0e\n\x06nbytes\x18\x02 \x01(\x04\"8\n\x04Span\x12\x0e\n\x06offset\x18\x01 \x01(\x04\x12\x0e\n\x06nbytes\x18\x02 \x01(\x04\x12\x10\n\x08\x66ilename\x18\x03 \x01(\t\"\xa2\x02\n\nAllocation\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0e\n\x06nbytes\x18\x02 \x01(\x04\x12\x11\n\talignment\x18\x03 \x01(\x04\x12\x11\n\x04\x66ile\x18\x04 \x01(\tH\x00\x88\x01\x01\x12\'\n\ndata_spans\x18\x05 \x03(\x0b\x32\x13.flare.runtime.Span\x12.\n\x0brelocations\x18\x06 \x03(\x0b\x32\x19.flare.runtime.Relocation\x12\x14\n\x07\x61\x64\x64ress\x18\x07 \x01(\x04H\x01\x88\x01\x01\x12%\n\x06memory\x18\x08 \x01(\x0e\x32\x15.flare.runtime.Memory\x12%\n\x06sizing\x18\t \x01(\x0b\x32\x15.flare.runtime.SizingB\x07\n\x05_fileB\n\n\x08_address\"X\n\x06Sizing\x12)\n\x08\x63\x61pacity\x18\x01 \x01(\x0e\x32\x17.flare.runtime.Capacity\x12\x12\n\nunit_bytes\x18\x02 \x01(\x04\x12\x0f\n\x07maximum\x18\x03 \x01(\x04\"L\n\x06Module\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04\x66ile\x18\x02 \x01(\t\x12&\n\x07globals\x18\x03 \x03(\x0b\x32\x15.flare.runtime.Global\"f\n\x06Global\x12\x0e\n\x06symbol\x18\x01 \x01(\t\x12\x0c\n\x04\x66ile\x18\x02 \x01(\t\x12\x0e\n\x06nbytes\x18\x03 \x01(\x04\x12.\n\x0brelocations\x18\x04 \x03(\x0b\x32\x19.flare.runtime.Relocation\"y\n\x08\x46unction\x12\x0e\n\x06module\x18\x01 \x01(\t\x12\x0e\n\x06symbol\x18\x02 \x01(\t\x12\x17\n\x0fparameter_sizes\x18\x03 \x03(\x04\x12\x34\n\nattributes\x18\x04 \x03(\x0b\x32 .flare.runtime.FunctionAttribute\".\n\x11\x46unctionAttribute\x12\n\n\x02id\x18\x01 \x01(\x05\x12\r\n\x05value\x18\x02 \x01(\x05\"/\n\tReference\x12\x12\n\nallocation\x18\x01 \x01(\t\x12\x0e\n\x06offset\x18\x02 \x01(\x04\"s\n\nRelocation\x12\x0e\n\x06offset\x18\x01 \x01(\x04\x12(\n\x06target\x18\x02 \x01(\x0b\x32\x18.flare.runtime.Reference\x12+\n\x04kind\x18\x03 \x01(\x0e\x32\x1d.flare.runtime.RelocationKind\"D\n\x04\x42lob\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\x0c\x12.\n\x0brelocations\x18\x02 \x03(\x0b\x32\x19.flare.runtime.Relocation\";\n\tAttribute\x12\n\n\x02id\x18\x01 \x01(\x05\x12\"\n\x05value\x18\x02 \x01(\x0b\x32\x13.flare.runtime.Blob\"\x9d\x01\n\x06Kernel\x12\x10\n\x08\x66unction\x18\x01 \x01(\x04\x12\x0c\n\x04grid\x18\x02 \x03(\r\x12\r\n\x05\x62lock\x18\x03 \x03(\r\x12\x0e\n\x06shared\x18\x04 \x01(\r\x12&\n\targuments\x18\x05 \x03(\x0b\x32\x13.flare.runtime.Blob\x12,\n\nattributes\x18\x06 \x03(\x0b\x32\x18.flare.runtime.Attribute\"\x8a\x01\n\x06Memset\x12-\n\x0b\x64\x65stination\x18\x01 \x01(\x0b\x32\x18.flare.runtime.Reference\x12\r\n\x05pitch\x18\x02 \x01(\x04\x12\r\n\x05value\x18\x03 \x01(\r\x12\x14\n\x0c\x65lement_size\x18\x04 \x01(\r\x12\r\n\x05width\x18\x05 \x01(\x04\x12\x0e\n\x06height\x18\x06 \x01(\x04\"o\n\x04\x43opy\x12(\n\x06source\x18\x01 \x01(\x0b\x32\x18.flare.runtime.Reference\x12-\n\x0b\x64\x65stination\x18\x02 \x01(\x0b\x32\x18.flare.runtime.Reference\x12\x0e\n\x06nbytes\x18\x03 \x01(\x04\"\x07\n\x05\x45mpty\"\x1a\n\tEventWait\x12\r\n\x05\x65vent\x18\x01 \x01(\t\"\xe1\x01\n\x04Node\x12\'\n\x06kernel\x18\x01 \x01(\x0b\x32\x15.flare.runtime.KernelH\x00\x12\'\n\x06memset\x18\x02 \x01(\x0b\x32\x15.flare.runtime.MemsetH\x00\x12#\n\x04\x63opy\x18\x03 \x01(\x0b\x32\x13.flare.runtime.CopyH\x00\x12%\n\x05\x65mpty\x18\x04 \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x12.\n\nevent_wait\x18\x05 \x01(\x0b\x32\x18.flare.runtime.EventWaitH\x00\x42\x0b\n\toperation\"9\n\x04\x45\x64ge\x12\x0e\n\x06source\x18\x01 \x01(\x04\x12\x13\n\x0b\x64\x65stination\x18\x02 \x01(\x04\x12\x0c\n\x04\x64\x61ta\x18\x03 \x01(\x0c\"\xb9\x02\n\tExecution\x12\x13\n\x0b\x61\x62i_version\x18\x01 \x01(\r\x12\x12\n\nmax_active\x18\x02 \x01(\x04\x12\x19\n\x11input_frame_bytes\x18\x03 \x01(\x04\x12&\n\x07\x62uffers\x18\x04 \x03(\x0b\x32\x15.flare.runtime.Buffer\x12-\n\x06graphs\x18\x05 \x03(\x0b\x32\x1d.flare.runtime.ExecutionGraph\x12\x31\n\rtuning_graphs\x18\x06 \x03(\x0b\x32\x1a.flare.runtime.TuningGraph\x12!\n\x19\x63ompletion_token_capacity\x18\x07 \x01(\r\x12;\n\x12persistent_workers\x18\x08 \x03(\x0b\x32\x1f.flare.runtime.PersistentWorker\"\xa9\x01\n\x10PersistentWorker\x12\x17\n\x0fworker_sm_count\x18\x01 \x01(\r\x12\r\n\x05graph\x18\x02 \x01(\t\x12+\n\tstop_flag\x18\x03 \x01(\x0b\x32\x18.flare.runtime.Reference\x12)\n\x07metrics\x18\x04 \x01(\x0b\x32\x18.flare.runtime.Reference\x12\x15\n\rmetrics_count\x18\x05 \x01(\r\"C\n\x0bTuningGraph\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07outputs\x18\x02 \x03(\t\x12\x15\n\rstatus_buffer\x18\x03 \x01(\t\"\x82\x01\n\x06\x42uffer\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0e\n\x06nbytes\x18\x02 \x01(\x04\x12\r\n\x05\x64type\x18\x03 \x01(\t\x12\r\n\x05shape\x18\x04 \x03(\x04\x12\x0f\n\x07strides\x18\x05 \x03(\x04\x12+\n\treference\x18\x06 \x01(\x0b\x32\x18.flare.runtime.Reference\"\x95\x04\n\x0e\x45xecutionGraph\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04kind\x18\x02 \x01(\t\x12\x15\n\rsampling_mode\x18\x03 \x01(\t\x12\x16\n\x0e\x62\x61tch_capacity\x18\x04 \x01(\x04\x12\x16\n\x0etoken_capacity\x18\x05 \x01(\x04\x12\x33\n\x0einput_bindings\x18\x06 \x03(\x0b\x32\x1b.flare.runtime.InputBinding\x12\x19\n\x0c\x64raft_tokens\x18\x07 \x01(\rH\x00\x88\x01\x01\x12\x1a\n\rverify_tokens\x18\x08 \x01(\rH\x01\x88\x01\x01\x12\x30\n\x0c\x64raft_source\x18\t \x01(\x0e\x32\x1a.flare.runtime.DraftSource\x12 \n\x13speculation_enabled\x18\n \x01(\x08H\x02\x88\x01\x01\x12\x1d\n\x15\x65stimated_duration_ns\x18\x0b \x01(\x04\x12\x18\n\x10prefill_capacity\x18\x0c \x01(\x04\x12\x1d\n\x15packed_token_capacity\x18\r \x01(\x04\x12\x18\n\x10\x63onfidence_width\x18\x0e \x01(\r\x12\x33\n\x0etuned_bindings\x18\x0f \x03(\x0b\x32\x1b.flare.runtime.TunedBindingB\x0f\n\r_draft_tokensB\x10\n\x0e_verify_tokensB\x16\n\x14_speculation_enabled\"H\n\x0cInputBinding\x12\x13\n\x0b\x62uffer_name\x18\x01 \x01(\t\x12\x13\n\x0bhost_offset\x18\x02 \x01(\x04\x12\x0e\n\x06nbytes\x18\x03 \x01(\x04*\xfa\x01\n\x19PreparationParameterScope\x12+\n\'PREPARATION_PARAMETER_SCOPE_UNSPECIFIED\x10\x00\x12*\n&PREPARATION_PARAMETER_SCOPE_DEPLOYMENT\x10\x01\x12\'\n#PREPARATION_PARAMETER_SCOPE_COMBINE\x10\x02\x12-\n)PREPARATION_PARAMETER_SCOPE_TARGET_WEIGHT\x10\x03\x12,\n(PREPARATION_PARAMETER_SCOPE_DRAFT_WEIGHT\x10\x04*\x8e\x01\n\x0bHistoryKind\x12\x17\n\x13HISTORY_UNSPECIFIED\x10\x00\x12\x13\n\x0fPAGED_KEY_VALUE\x10\x01\x12\x10\n\x0cPAGED_LATENT\x10\x02\x12\x12\n\x0eSLIDING_WINDOW\x10\x03\x12\x13\n\x0fRECURRENT_STATE\x10\x04\x12\x16\n\x12\x43ONTINUATION_STATE\x10\x05*\xc7\x07\n\x0bValueSource\x12\x15\n\x11VALUE_UNSPECIFIED\x10\x00\x12\x0c\n\x08\x43ONSTANT\x10\x01\x12\x10\n\x0cREQUEST_SLOT\x10\x02\x12\x16\n\x12REQUEST_GENERATION\x10\x03\x12\r\n\tLIVE_ROWS\x10\x04\x12\x10\n\x0cQUERY_LENGTH\x10\x05\x12\x12\n\x0eSAMPLE_ENABLED\x10\x06\x12\x10\n\x0cPROMPT_TOKEN\x10\x07\x12\x11\n\rPENDING_TOKEN\x10\x08\x12\x1c\n\x18PROMPT_AND_PENDING_TOKEN\x10\t\x12\x13\n\x0fPROMPT_POSITION\x10\n\x12\x17\n\x13IMAGE_FEATURE_INDEX\x10\x0b\x12\x16\n\x12IMAGE_LEFT_CONTEXT\x10\x0c\x12\x17\n\x13IMAGE_RIGHT_CONTEXT\x10\r\x12\x0e\n\nPAGE_TABLE\x10\x0e\x12\x13\n\x0fLIVE_STATE_ROWS\x10\x0f\x12\x12\n\x0eLIVE_STATE_ROW\x10\x10\x12\x14\n\x10PREFIX_STATE_ROW\x10\x11\x12\x16\n\x12SNAPSHOT_STATE_ROW\x10\x12\x12\x13\n\x0f\x43ONSUMED_TOKENS\x10\x13\x12\x1c\n\x18SNAPSHOT_CONSUMED_TOKENS\x10\x14\x12\x0f\n\x0bPREFILL_ROW\x10\x15\x12\x11\n\rSAMPLING_SEED\x10\x16\x12\x17\n\x13SAMPLING_PARAMETERS\x10\x17\x12\x12\n\x0eSAMPLING_TOP_K\x10\x18\x12\x12\n\x0eMAX_NEW_TOKENS\x10\x19\x12\x11\n\rEOS_TOKEN_IDS\x10\x1a\x12\r\n\tEOS_COUNT\x10\x1b\x12\x14\n\x10PROMPT_HISTOGRAM\x10\x1c\x12\x10\n\x0cGRAMMAR_MASK\x10\x1d\x12\x13\n\x0fGRAMMAR_ENABLED\x10\x1e\x12\x12\n\x0e\x43OPY_TOKEN_IDS\x10\x1f\x12\x14\n\x10\x43OPY_TOKEN_COUNT\x10 \x12\x18\n\x14\x43OPY_CONSUMED_TOKENS\x10!\x12\x13\n\x0f\x43OPY_GENERATION\x10\"\x12\x15\n\x11\x43OPY_GRAMMAR_MASK\x10#\x12\x16\n\x12\x43OPY_GRAMMAR_COUNT\x10$\x12\x10\n\x0cIMAGE_TENSOR\x10%\x12\x16\n\x12IMAGE_FEATURE_SLOT\x10&\x12\x17\n\x13PROMPT_TARGET_TOKEN\x10\'\x12\x1c\n\x18SPECULATIVE_PREFIX_LIMIT\x10(\x12\x1a\n\x16PROMPT_LOOKAHEAD_TOKEN\x10)\x12\x1b\n\x17PROMPT_LOOKAHEAD_LENGTH\x10*\x12\x12\n\x0e\x43ORE_PARAMETER\x10+*|\n\rInputIndexing\x12\x18\n\x14INDEXING_UNSPECIFIED\x10\x00\x12\n\n\x06SCALAR\x10\x01\x12\x12\n\x0eSUBMISSION_ROW\x10\x02\x12\x0f\n\x0bREQUEST_ROW\x10\x03\x12\x10\n\x0cPACKED_TOKEN\x10\x04\x12\x0e\n\nACTIVE_ROW\x10\x05*T\n\x0fStateAccessKind\x12\x1c\n\x18STATE_ACCESS_UNSPECIFIED\x10\x00\x12\x08\n\x04READ\x10\x01\x12\t\n\x05WRITE\x10\x02\x12\x0e\n\nREAD_WRITE\x10\x03*\x8b\x02\n\x0eGraphOperation\x12\x1f\n\x1bGRAPH_OPERATION_UNSPECIFIED\x10\x00\x12\x08\n\x04INIT\x10\x01\x12\x0b\n\x07RESTORE\x10\x02\x12\x0c\n\x08SNAPSHOT\x10\x03\x12\x0b\n\x07PREFILL\x10\x04\x12\n\n\x06\x44\x45\x43ODE\x10\x05\x12\n\n\x06RESUME\x10\x06\x12\n\n\x06VISION\x10\x07\x12\x0f\n\x0bSPECULATIVE\x10\x08\x12\t\n\x05MIXED\x10\t\x12\x12\n\x0eSCORED_PREFILL\x10\x0c\x12\x14\n\x10TERMINAL_PREFILL\x10\x0e\"\x04\x08\n\x10\n\"\x04\x08\x0b\x10\x0b\"\x04\x08\r\x10\r*\x08PROPOSAL*\x0cVERIFICATION*\x12PACKED_SPECULATIVE*\xa1\x01\n\x0eToolParserKind\x12\x1b\n\x17TOOL_PARSER_UNSPECIFIED\x10\x00\x12\x0e\n\nQWEN_CODER\x10\x01\x12\x15\n\x11GLM_ARGUMENT_TAGS\x10\x02\x12\x08\n\x04\x44SML\x10\x03\x12\x08\n\x04XTML\x10\x04\x12\x0f\n\x0bMINIMAX_XML\x10\x05\x12\x0e\n\nGEMMA_CALL\x10\x06\x12\x08\n\x04\x41TEM\x10\x07\x12\x0c\n\x08TML_JSON\x10\x08*\xa6\x01\n\x13ReasoningParserKind\x12 \n\x1cREASONING_PARSER_UNSPECIFIED\x10\x00\x12\x0e\n\nTHINK_TAGS\x10\x01\x12\x0e\n\nXTML_THINK\x10\x02\x12\x0c\n\x08MM_THINK\x10\x03\x12\x13\n\x0f\x43HANNEL_THOUGHT\x10\x04\x12\x15\n\x11RECIPIENT_HEADERS\x10\x05\x12\x13\n\x0f\x43ONTENT_HEADERS\x10\x06*\xf4\x02\n\x14ImagePreparationKind\x12!\n\x1dIMAGE_PREPARATION_UNSPECIFIED\x10\x00\x12\x1a\n\x16QWEN_IMAGE_PREPARATION\x10\x01\x12\x1a\n\x16MIMO_IMAGE_PREPARATION\x10\x02\x12\x1e\n\x1a\x44\x45\x45PSEEK_IMAGE_PREPARATION\x10\x03\x12\x1d\n\x19MOONVIT_IMAGE_PREPARATION\x10\x04\x12\x1a\n\x16STEP_IMAGE_PREPARATION\x10\x05\x12\x1b\n\x17RADIO_IMAGE_PREPARATION\x10\x06\x12(\n$DEEPSEEK_ROW_MAJOR_IMAGE_PREPARATION\x10\x07\x12\x19\n\x15GLM_IMAGE_PREPARATION\x10\x08\x12!\n\x1dPATCH_MERGE_IMAGE_PREPARATION\x10\t\x12!\n\x1dPADDED_GRID_IMAGE_PREPARATION\x10\n*\xb6\x02\n\x0fImageLayoutKind\x12\x1c\n\x18IMAGE_LAYOUT_UNSPECIFIED\x10\x00\x12\x15\n\x11QWEN_IMAGE_LAYOUT\x10\x01\x12\x15\n\x11MIMO_IMAGE_LAYOUT\x10\x02\x12\x19\n\x15\x44\x45\x45PSEEK_IMAGE_LAYOUT\x10\x03\x12\x18\n\x14MOONVIT_IMAGE_LAYOUT\x10\x04\x12\x15\n\x11STEP_IMAGE_LAYOUT\x10\x05\x12\x16\n\x12RADIO_IMAGE_LAYOUT\x10\x06\x12#\n\x1f\x44\x45\x45PSEEK_ROW_MAJOR_IMAGE_LAYOUT\x10\x07\x12\x14\n\x10GLM_IMAGE_LAYOUT\x10\x08\x12\x1a\n\x16\x42RACKETED_IMAGE_LAYOUT\x10\t\x12\x1c\n\x18\x43LASS_TOKEN_IMAGE_LAYOUT\x10\n*P\n\rPromptEncoder\x12\x10\n\x0cPROMPT_JINJA\x10\x00\x12\x0f\n\x0b\x44\x45\x45PSEEK_V4\x10\x01\x12\x10\n\x0c\x44\x45\x45PSEEK_V41\x10\x02\x12\n\n\x06TML_V0\x10\x03*B\n\x10TemplateEncoding\x12\x11\n\rTEMPLATE_TEXT\x10\x00\x12\x1b\n\x17TEMPLATE_TOKEN_SEGMENTS\x10\x01*/\n\x06Memory\x12\n\n\x06\x44\x45VICE\x10\x00\x12\x0f\n\x0bMAPPED_HOST\x10\x01\x12\x08\n\x04PEER\x10\x02*(\n\x08\x43\x61pacity\x12\x0e\n\nSTATE_ROWS\x10\x00\x12\x0c\n\x08KV_PAGES\x10\x01*-\n\x0eRelocationKind\x12\x0b\n\x07POINTER\x10\x00\x12\x0e\n\nTENSOR_MAP\x10\x01*4\n\x0b\x44raftSource\x12\x0c\n\x08NO_DRAFT\x10\x00\x12\x07\n\x03MTP\x10\x01\x12\x0e\n\nCOPY_DRAFT\x10\x02\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x12runtime_core.proto\x12\rflare.runtime\"\x99\x01\n\x0eProtectedIndex\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\x0f\n\x07\x63ore_id\x18\x02 \x01(\x0c\x12\x0e\n\x06signer\x18\x03 \x01(\x0c\x12*\n\x06groups\x18\x04 \x03(\x0b\x32\x1a.flare.runtime.SignedGroup\x12)\n\x05ranks\x18\x05 \x03(\x0b\x32\x1a.flare.runtime.SignedGroup\"<\n\x0bSignedGroup\x12\x0c\n\x04kind\x18\x01 \x01(\r\x12\x0c\n\x04\x62ody\x18\x02 \x01(\x0c\x12\x11\n\tsignature\x18\x03 \x01(\x0c\"\xcc\x01\n\x11PublisherMetadata\x12(\n\x05index\x18\x01 \x01(\x0b\x32\x19.flare.runtime.ModelIndex\x12\x11\n\tnamespace\x18\x02 \x01(\t\x12\x17\n\x0fofficial_source\x18\x03 \x01(\t\x12\x14\n\x0cgroup_hashes\x18\x04 \x03(\x0c\x12\x13\n\x0b\x64\x65velopment\x18\x05 \x01(\x08\x12\r\n\x05ranks\x18\x06 \x01(\r\x12\'\n\x07license\x18\x07 \x01(\x0b\x32\x16.flare.runtime.License\"%\n\x07License\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04link\x18\x02 \x01(\t\"F\n\x0fResourceCatalog\x12\x33\n\tresources\x18\x01 \x03(\x0b\x32 .flare.runtime.ProtectedResource\"^\n\x11ProtectedResource\x12\x0e\n\x06offset\x18\x01 \x01(\x04\x12\x14\n\x0cstored_bytes\x18\x02 \x01(\x04\x12\x13\n\x0bplain_bytes\x18\x03 \x01(\x04\x12\x0e\n\x06sha256\x18\x04 \x03(\x0c\"`\n\nStoredData\x12\x0e\n\x06nbytes\x18\x01 \x01(\x04\x12\x0e\n\x06sha256\x18\x02 \x01(\x0c\x12\x0e\n\x06offset\x18\x03 \x01(\x04\x12\"\n\x05parts\x18\x04 \x03(\x0b\x32\x13.flare.runtime.Span\"\xd9\x01\n\x0eRankProtection\x12\x0c\n\x04rank\x18\x01 \x01(\r\x12*\n\x06\x62undle\x18\x02 \x01(\x0b\x32\x1a.flare.runtime.BundleIndex\x12\x33\n\x0b\x65xecutables\x18\x03 \x01(\x0b\x32\x1e.flare.runtime.ResourceCatalog\x12/\n\x07support\x18\x04 \x01(\x0b\x32\x1e.flare.runtime.ResourceCatalog\x12\'\n\x04\x64\x61ta\x18\x05 \x01(\x0b\x32\x19.flare.runtime.StoredData\"\x8c\x04\n\nModelIndex\x12\x0f\n\x07version\x18\x01 \x01(\r\x12)\n\x05ranks\x18\x02 \x03(\x0b\x32\x1a.flare.runtime.BundleIndex\x12.\n\x0bpeer_memory\x18\x03 \x03(\x0b\x32\x19.flare.runtime.PeerMemory\x12$\n\x06\x61ssets\x18\x05 \x03(\x0b\x32\x14.flare.runtime.Asset\x12%\n\x06\x65ngram\x18\x06 \x01(\x0b\x32\x15.flare.runtime.Engram\x12\x43\n\x11sampling_defaults\x18\x07 \x01(\x0b\x32(.flare.runtime.DefaultSamplingParameters\x12\x31\n\x08\x66rontend\x18\x08 \x01(\x0b\x32\x1f.flare.runtime.FrontendSettings\x12\'\n\x07\x63luster\x18\t \x01(\x0b\x32\x16.flare.runtime.Cluster\x12\x30\n\x08\x63ontract\x18\n \x01(\x0b\x32\x1e.flare.runtime.ServingContract\x12\x33\n\x07rebuild\x18\x0b \x01(\x0b\x32\x1e.flare.runtime.RebuildManifestB\x02\x18\x01\x12\x37\n\x0bpreparation\x18\x0c \x01(\x0b\x32\".flare.runtime.PreparationManifestJ\x04\x08\x04\x10\x05\"\xf9\x01\n\x13PreparationManifest\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\x0e\n\x06recipe\x18\x02 \x01(\t\x12\x17\n\x0fsource_identity\x18\x03 \x01(\t\x12\x1d\n\x15\x63heckpoint_repository\x18\x04 \x01(\t\x12\x1b\n\x13\x63heckpoint_revision\x18\x05 \x01(\t\x12\x18\n\x10local_checkpoint\x18\x06 \x01(\x08\x12\x19\n\x11reproduction_args\x18\x07 \x03(\t\x12\x37\n\nparameters\x18\x08 \x03(\x0b\x32#.flare.runtime.PreparationParameter\"\x8c\x01\n\x14PreparationParameter\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x37\n\x05scope\x18\x02 \x01(\x0e\x32(.flare.runtime.PreparationParameterScope\x12.\n\x05value\x18\x03 \x01(\x0b\x32\x1f.flare.runtime.PreparationValue\"\xc6\x01\n\x10PreparationValue\x12\x14\n\nbool_value\x18\x01 \x01(\x08H\x00\x12\x13\n\tint_value\x18\x02 \x01(\x03H\x00\x12\x14\n\nuint_value\x18\x03 \x01(\x04H\x00\x12\x15\n\x0b\x66loat_value\x18\x04 \x01(\x01H\x00\x12\x16\n\x0cstring_value\x18\x05 \x01(\tH\x00\x12\x39\n\nlist_value\x18\x06 \x01(\x0b\x32#.flare.runtime.PreparationValueListH\x00\x42\x07\n\x05value\"G\n\x14PreparationValueList\x12/\n\x06values\x18\x01 \x03(\x0b\x32\x1f.flare.runtime.PreparationValue\"\xdb\x07\n\x0fRebuildManifest\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\x0e\n\x06recipe\x18\x02 \x01(\t\x12\x17\n\x0fsource_identity\x18\x03 \x01(\t\x12\x1d\n\x15\x63heckpoint_repository\x18\x04 \x01(\t\x12\x1b\n\x13\x63heckpoint_revision\x18\x05 \x01(\t\x12\x17\n\x0ftensor_parallel\x18\x06 \x01(\r\x12\x17\n\x0fmax_concurrency\x18\x07 \x01(\x04\x12\x15\n\rprefill_chunk\x18\x08 \x01(\x04\x12\x19\n\x11image_concurrency\x18\t \x01(\x04\x12\x18\n\x10\x63ontext_parallel\x18\n \x01(\x08\x12\x16\n\x0estream_overlap\x18\x0b \x01(\x08\x12\x15\n\rmixed_prefill\x18\x0c \x01(\x08\x12%\n\x18\x65xpert_scale_compression\x18\r \x01(\tH\x00\x88\x01\x01\x12\x18\n\x10mla_compute_mode\x18\x0e \x01(\t\x12\x11\n\troce_ring\x18\x0f \x01(\x08\x12\x14\n\x0conline_mxfp8\x18\x10 \x01(\x08\x12\x1b\n\x13language_model_only\x18\x11 \x01(\x08\x12\x36\n\x0bspeculation\x18\x12 \x01(\x0b\x32!.flare.runtime.RebuildSpeculation\x12\x19\n\x11\x63ompiled_forwards\x18\x13 \x01(\x08\x12\x15\n\rreserve_bytes\x18\x14 \x01(\x04\x12\x18\n\x10local_checkpoint\x18\x15 \x01(\x08\x12\x12\n\nroce_chain\x18\x16 \x01(\x08\x12\x1e\n\x16shard_hyperconnections\x18\x18 \x01(\x08\x12\x1c\n\x14\x66orce_moe_decode_a16\x18\x1b \x01(\x08\x12\x19\n\x11row_shard_prefill\x18\x1c \x01(\x08\x12\x1a\n\x12online_mxfp8_scope\x18\x1e \x01(\t\x12\x1d\n\x15\x63ontext_parallel_size\x18\x1f \x01(\r\x12\x17\n\x0fprompt_logprobs\x18 \x01(\x08\x12\x17\n\x0f\x61utotune_effort\x18! \x01(\t\x12 \n\x18native_dense_activations\x18\" \x01(\x08\x12\x17\n\x0flock_gpu_clocks\x18# \x01(\x08\x12\x19\n\x11reproduction_args\x18$ \x03(\t:\x02\x18\x01\x42\x1b\n\x19_expert_scale_compressionJ\x04\x08\x17\x10\x18J\x04\x08\x19\x10\x1aJ\x04\x08\x1a\x10\x1bR\x0cjoint_tuningR\x11\x63ollective_tuningR\x16\x63ollective_ladder_json\"\x82\x04\n\x12RebuildSpeculation\x12\x14\n\x0c\x64raft_tokens\x18\x01 \x01(\r\x12\x10\n\x08\x61\x64\x61ptive\x18\x02 \x01(\x08\x12\x17\n\x0fproposal_source\x18\x03 \x01(\t\x12\x16\n\x0ehistory_drafts\x18\x04 \x01(\x08\x12\x16\n\x0etoken_capacity\x18\x05 \x01(\x04\x12\x1b\n\x13packed_verification\x18\x06 \x01(\x08\x12\x1e\n\x16\x64raft_prefix_selection\x18\x07 \x01(\t\x12$\n\x17\x64raft_head_quantization\x18\x08 \x01(\tH\x00\x88\x01\x01\x12%\n\x18markov_head_quantization\x18\t \x01(\tH\x01\x88\x01\x01\x12\x19\n\x0cgraph_budget\x18\n \x01(\x04H\x02\x88\x01\x01\x12$\n\x1cvocabulary_parallel_sampling\x18\x0b \x01(\x08\x12\x0e\n\x06method\x18\x0c \x01(\t\x12\x10\n\x08mtp_only\x18\r \x01(\x08\x12$\n\x17\x64raft_body_quantization\x18\x0e \x01(\tH\x03\x88\x01\x01:\x02\x18\x01\x42\x1a\n\x18_draft_head_quantizationB\x1b\n\x19_markov_head_quantizationB\x0f\n\r_graph_budgetB\x1a\n\x18_draft_body_quantization\"e\n\x0eRebuildWeights\x12\x0f\n\x07version\x18\x01 \x01(\r\x12-\n\x07tensors\x18\x02 \x03(\x0b\x32\x1c.flare.runtime.RebuildTensor\x12\x13\n\x0bunavailable\x18\x03 \x03(\t\"\xa2\x01\n\rRebuildTensor\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05\x64type\x18\x02 \x01(\t\x12\x15\n\relement_bytes\x18\x03 \x01(\r\x12\r\n\x05shape\x18\x04 \x03(\x04\x12\x0e\n\x06stride\x18\x05 \x03(\x04\x12\x13\n\x0blayout_type\x18\x06 \x01(\t\x12)\n\x07storage\x18\x07 \x01(\x0b\x32\x18.flare.runtime.Reference\"\xcb\x06\n\x0fServingContract\x12\x10\n\x08model_id\x18\x01 \x01(\t\x12\x10\n\x08identity\x18\x02 \x01(\t\x12\x34\n\x0emodel_contract\x18\x03 \x01(\x0b\x32\x1c.flare.runtime.ModelContract\x12\x1b\n\x13max_sequence_tokens\x18\x04 \x01(\x04\x12\x1a\n\x12prefill_chunk_size\x18\x05 \x01(\x04\x12\r\n\x05pages\x18\x06 \x01(\x04\x12\x12\n\nstate_rows\x18\x07 \x01(\x04\x12\x11\n\tsnapshots\x18\x08 \x01(\x04\x12\x13\n\x0bpage_tokens\x18\t \x01(\x04\x12\x1a\n\x12speculative_widths\x18\x0b \x03(\x04\x12$\n\x17speculative_fixed_width\x18\x0c \x01(\x04H\x00\x88\x01\x01\x12\x16\n\x0ehistory_drafts\x18\r \x01(\x08\x12#\n\x1bspeculative_proposal_source\x18\x0e \x01(\t\x12\x1b\n\x0emax_new_tokens\x18\x0f \x01(\x04H\x01\x88\x01\x01\x12\x17\n\nmax_active\x18\x10 \x01(\x04H\x02\x88\x01\x01\x12\x14\n\x0cserved_names\x18\x11 \x03(\t\x12\x1a\n\rreserve_bytes\x18\x12 \x01(\x04H\x03\x88\x01\x01\x12\x1b\n\x0equeue_capacity\x18\x13 \x01(\x04H\x04\x88\x01\x01\x12\x1d\n\x10\x66rontend_workers\x18\x14 \x01(\x04H\x05\x88\x01\x01\x12\x1b\n\x0emax_body_bytes\x18\x15 \x01(\x04H\x06\x88\x01\x01\x12\x14\n\x0c\x63ontext_hint\x18\x16 \x01(\t\x12\x15\n\rcapacity_hint\x18\x17 \x01(\t\x12\"\n\x1aspeculative_token_capacity\x18\x18 \x01(\x04\x12 \n\x13\x64\x65\x63ode_weight_bytes\x18\x19 \x01(\x04H\x07\x88\x01\x01\x42\x1a\n\x18_speculative_fixed_widthB\x11\n\x0f_max_new_tokensB\r\n\x0b_max_activeB\x10\n\x0e_reserve_bytesB\x11\n\x0f_queue_capacityB\x13\n\x11_frontend_workersB\x11\n\x0f_max_body_bytesB\x16\n\x14_decode_weight_bytesJ\x04\x08\n\x10\x0b\"\xc2\x02\n\rModelContract\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\x12\n\nvocabulary\x18\x02 \x01(\x04\x12\x18\n\x10input_vocabulary\x18\x03 \x01(\x04\x12-\n\x06vision\x18\x04 \x01(\x0b\x32\x1d.flare.runtime.VisionCapacity\x12+\n\x05\x63\x61\x63he\x18\x05 \x01(\x0b\x32\x1c.flare.runtime.CacheContract\x12,\n\x06graphs\x18\x06 \x03(\x0b\x32\x1c.flare.runtime.GraphContract\x12\x31\n\x08\x66rontend\x18\x07 \x01(\x0b\x32\x1f.flare.runtime.FrontendContract\x12\x35\n\x0f\x63ore_parameters\x18\x08 \x03(\x0b\x32\x1c.flare.runtime.CoreParameter\"}\n\rCoreParameter\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x1a\n\rdefault_value\x18\x02 \x01(\x02H\x00\x88\x01\x01\x12\x30\n\x05range\x18\x03 \x01(\x0b\x32!.flare.runtime.CoreParameterRangeB\x10\n\x0e_default_value\"H\n\x12\x43oreParameterRange\x12\x10\n\x03min\x18\x01 \x01(\x02H\x00\x88\x01\x01\x12\x10\n\x03max\x18\x02 \x01(\x02H\x01\x88\x01\x01\x42\x06\n\x04_minB\x06\n\x04_max\"\xa8\x01\n\x0eVisionCapacity\x12\x15\n\rfeature_slots\x18\x05 \x01(\x04\x12\x1c\n\x14\x66\x65\x61tures_per_request\x18\x01 \x01(\x04\x12\x12\n\nmax_images\x18\x02 \x01(\x04\x12\x1b\n\x13patches_per_feature\x18\x03 \x01(\x04\x12\x18\n\x10patch_capacities\x18\x04 \x03(\x04\x12\x16\n\x0epatch_features\x18\x06 \x01(\x04\"\xb8\x01\n\rCacheContract\x12\x13\n\x0bpage_tokens\x18\x01 \x01(\x04\x12-\n\x07regions\x18\x02 \x03(\x0b\x32\x1c.flare.runtime.HistoryRegion\x12\x31\n\x0bpage_tables\x18\x03 \x03(\x0b\x32\x1c.flare.runtime.PageTableView\x12\x30\n\x0c\x63odec_layout\x18\x04 \x01(\x0b\x32\x1a.flare.runtime.CodecLayout\"r\n\x0b\x43odecLayout\x12\x10\n\x08revision\x18\x01 \x01(\r\x12)\n\x06\x66ields\x18\x02 \x03(\x0b\x32\x19.flare.runtime.CodecField\x12\x17\n\ngpu_module\x18\x03 \x01(\tH\x00\x88\x01\x01\x42\r\n\x0b_gpu_module\"N\n\nCodecField\x12\x0e\n\x06\x62uffer\x18\x01 \x01(\t\x12\x0e\n\x06offset\x18\x02 \x01(\x04\x12\x0e\n\x06length\x18\x03 \x01(\x04\x12\x10\n\x08\x65ncoding\x18\x04 \x01(\r\"\x96\x01\n\rHistoryRegion\x12(\n\x04kind\x18\x01 \x01(\x0e\x32\x1a.flare.runtime.HistoryKind\x12)\n\x07storage\x18\x02 \x01(\x0b\x32\x18.flare.runtime.StateView\x12\x19\n\x11tokens_per_record\x18\x03 \x01(\x04\x12\x15\n\rwindow_tokens\x18\x04 \x01(\x04\"4\n\rPageTableView\x12\x0e\n\x06\x62uffer\x18\x01 \x01(\t\x12\x13\n\x0bpage_offset\x18\x02 \x01(\x04\"\xc4\x01\n\x0cValueBinding\x12\x0e\n\x06\x62uffer\x18\x01 \x01(\t\x12*\n\x06source\x18\x02 \x01(\x0e\x32\x1a.flare.runtime.ValueSource\x12.\n\x08indexing\x18\x03 \x01(\x0e\x32\x1c.flare.runtime.InputIndexing\x12\x14\n\x0cvalue_offset\x18\x04 \x01(\x12\x12\x0f\n\x07padding\x18\x05 \x01(\x12\x12\x0e\n\x06tensor\x18\x06 \x01(\t\x12\x11\n\tparameter\x18\x07 \x01(\t\"K\n\tStateView\x12\x0e\n\x06\x62uffer\x18\x01 \x01(\t\x12\x0e\n\x06offset\x18\x02 \x01(\x04\x12\x0e\n\x06stride\x18\x03 \x01(\x04\x12\x0e\n\x06nbytes\x18\x04 \x01(\x04\"e\n\x0bStateAccess\x12&\n\x04view\x18\x01 \x01(\x0b\x32\x18.flare.runtime.StateView\x12.\n\x06\x61\x63\x63\x65ss\x18\x02 \x01(\x0e\x32\x1e.flare.runtime.StateAccessKind\"O\n\x10\x43ompletionCursor\x12\'\n\x05state\x18\x01 \x01(\x0b\x32\x18.flare.runtime.StateView\x12\x12\n\nlag_tokens\x18\x02 \x01(\x04\"4\n\x0cTunedBinding\x12\x0e\n\x06\x62uffer\x18\x01 \x01(\t\x12\x14\n\x0ctuning_graph\x18\x02 \x01(\t\"\xfa\x02\n\rGraphContract\x12\r\n\x05graph\x18\x01 \x01(\t\x12+\n\x06inputs\x18\x02 \x03(\x0b\x32\x1b.flare.runtime.ValueBinding\x12)\n\x05state\x18\x03 \x03(\x0b\x32\x1a.flare.runtime.StateAccess\x12\x1e\n\x16state_rows_per_request\x18\x04 \x01(\x04\x12\x35\n\x0c\x64raft_cursor\x18\x05 \x01(\x0b\x32\x1f.flare.runtime.CompletionCursor\x12\x18\n\x10\x65mbedding_tables\x18\x06 \x03(\r\x12/\n\rpending_token\x18\x07 \x01(\x0b\x32\x18.flare.runtime.StateView\x12+\n\x04kind\x18\x08 \x01(\x0e\x32\x1d.flare.runtime.GraphOperation\x12\x33\n\x0etuned_bindings\x18\t \x03(\x0b\x32\x1b.flare.runtime.TunedBinding\"k\n\nToolParser\x12+\n\x04kind\x18\x01 \x01(\x0e\x32\x1d.flare.runtime.ToolParserKind\x12\x19\n\x11wrapping_newlines\x18\x02 \x01(\r\x12\x15\n\rtag_separator\x18\x03 \x01(\t\"\x95\x01\n\x0fReasoningParser\x12\x30\n\x04kind\x18\x01 \x01(\x0e\x32\".flare.runtime.ReasoningParserKind\x12\x0c\n\x04open\x18\x02 \x01(\t\x12\r\n\x05\x63lose\x18\x03 \x01(\t\x12\x19\n\x11wrapping_newlines\x18\x04 \x01(\r\x12\x18\n\x10terminal_markers\x18\x05 \x03(\t\"\xca\x01\n\x0ePrefixBoundary\x12\r\n\x05roles\x18\x01 \x03(\t\x12\x18\n\x0b\x61ppend_role\x18\x02 \x01(\tH\x00\x88\x01\x01\x12\x1e\n\x16\x63ontinue_final_message\x18\x03 \x01(\x08\x12\x18\n\x10minimum_messages\x18\x04 \x01(\x04\x12\x16\n\x0erequired_start\x18\x05 \x01(\t\x12\x14\n\x0crequired_end\x18\x06 \x01(\t\x12\x17\n\x0frequired_marker\x18\x07 \x01(\tB\x0e\n\x0c_append_role\"y\n\tImageSpan\x12\x13\n\x0bstart_token\x18\x01 \x01(\r\x12\x11\n\tend_token\x18\x02 \x01(\r\x12\x12\n\nmax_tokens\x18\x03 \x01(\x04\x12\x17\n\x0finterior_tokens\x18\x04 \x03(\r\x12\x17\n\x0funscoped_tokens\x18\x05 \x03(\r\"Q\n\x10ImageTokenLayout\x12\x15\n\rfeature_token\x18\x01 \x01(\r\x12&\n\x04span\x18\x02 \x01(\x0b\x32\x18.flare.runtime.ImageSpan\"\xf2\x03\n\x10\x46rontendContract\x12(\n\x05tools\x18\x01 \x01(\x0b\x32\x19.flare.runtime.ToolParser\x12\x31\n\treasoning\x18\x02 \x01(\x0b\x32\x1e.flare.runtime.ReasoningParser\x12\x43\n\x11image_preparation\x18\x03 \x01(\x0e\x32#.flare.runtime.ImagePreparationKindH\x00\x88\x01\x01\x12\x39\n\x0cimage_layout\x18\x04 \x01(\x0e\x32\x1e.flare.runtime.ImageLayoutKindH\x01\x88\x01\x01\x12\x17\n\x0frejected_tokens\x18\x05 \x03(\r\x12\x1b\n\x13position_dimensions\x18\x06 \x01(\r\x12\x18\n\x10\x61ssistant_marker\x18\x07 \x01(\t\x12\x1b\n\x13message_end_markers\x18\x08 \x03(\t\x12\x36\n\x0fprefix_boundary\x18\t \x01(\x0b\x32\x1d.flare.runtime.PrefixBoundary\x12\x35\n\x0cimage_tokens\x18\n \x01(\x0b\x32\x1f.flare.runtime.ImageTokenLayoutB\x14\n\x12_image_preparationB\x0f\n\r_image_layout\"1\n\x07\x43luster\x12\r\n\x05world\x18\x01 \x01(\r\x12\x11\n\texport_id\x18\x03 \x01(\tJ\x04\x08\x02\x10\x03\"\x8c\x03\n\x19\x44\x65\x66\x61ultSamplingParameters\x12\x11\n\x04seed\x18\x01 \x01(\x04H\x00\x88\x01\x01\x12\x18\n\x0btemperature\x18\x02 \x01(\x02H\x01\x88\x01\x01\x12\x12\n\x05top_k\x18\x03 \x01(\x05H\x02\x88\x01\x01\x12\x12\n\x05top_p\x18\x04 \x01(\x02H\x03\x88\x01\x01\x12\x12\n\x05min_p\x18\x05 \x01(\x02H\x04\x88\x01\x01\x12\x1f\n\x12repetition_penalty\x18\x06 \x01(\x02H\x05\x88\x01\x01\x12\x1d\n\x10presence_penalty\x18\x07 \x01(\x02H\x06\x88\x01\x01\x12\x1e\n\x11\x66requency_penalty\x18\x08 \x01(\x02H\x07\x88\x01\x01\x12-\n\x06ranges\x18\t \x01(\x0b\x32\x1d.flare.runtime.SamplingRangesB\x07\n\x05_seedB\x0e\n\x0c_temperatureB\x08\n\x06_top_kB\x08\n\x06_top_pB\x08\n\x06_min_pB\x15\n\x13_repetition_penaltyB\x13\n\x11_presence_penaltyB\x14\n\x12_frequency_penalty\"H\n\x12SamplingFloatRange\x12\x10\n\x03min\x18\x01 \x01(\x02H\x00\x88\x01\x01\x12\x10\n\x03max\x18\x02 \x01(\x02H\x01\x88\x01\x01\x42\x06\n\x04_minB\x06\n\x04_max\"F\n\x10SamplingIntRange\x12\x10\n\x03min\x18\x01 \x01(\x05H\x00\x88\x01\x01\x12\x10\n\x03max\x18\x02 \x01(\x05H\x01\x88\x01\x01\x42\x06\n\x04_minB\x06\n\x04_max\"\x96\x03\n\x0eSamplingRanges\x12\x36\n\x0btemperature\x18\x01 \x01(\x0b\x32!.flare.runtime.SamplingFloatRange\x12.\n\x05top_k\x18\x02 \x01(\x0b\x32\x1f.flare.runtime.SamplingIntRange\x12\x30\n\x05top_p\x18\x03 \x01(\x0b\x32!.flare.runtime.SamplingFloatRange\x12\x30\n\x05min_p\x18\x04 \x01(\x0b\x32!.flare.runtime.SamplingFloatRange\x12=\n\x12repetition_penalty\x18\x05 \x01(\x0b\x32!.flare.runtime.SamplingFloatRange\x12;\n\x10presence_penalty\x18\x06 \x01(\x0b\x32!.flare.runtime.SamplingFloatRange\x12<\n\x11\x66requency_penalty\x18\x07 \x01(\x0b\x32!.flare.runtime.SamplingFloatRange\"\xc5\x02\n\x10\x46rontendSettings\x12\x33\n\ttokenizer\x18\x01 \x01(\x0b\x32 .flare.runtime.TokenizerSettings\x12+\n\x05image\x18\x02 \x01(\x0b\x32\x1c.flare.runtime.ImageSettings\x12\x15\n\reos_token_ids\x18\x03 \x03(\r\x12:\n\x11template_encoding\x18\x04 \x01(\x0e\x32\x1f.flare.runtime.TemplateEncoding\x12\x34\n\x0eprompt_encoder\x18\x05 \x01(\x0e\x32\x1c.flare.runtime.PromptEncoder\x12\'\n\x1aimage_placeholder_token_id\x18\x06 \x01(\rH\x00\x88\x01\x01\x42\x1d\n\x1b_image_placeholder_token_id\"\xdc\x02\n\x11TokenizerSettings\x12\x16\n\tbos_token\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x16\n\teos_token\x18\x02 \x01(\tH\x01\x88\x01\x01\x12\x16\n\tunk_token\x18\x03 \x01(\tH\x02\x88\x01\x01\x12\x16\n\tsep_token\x18\x04 \x01(\tH\x03\x88\x01\x01\x12\x16\n\tpad_token\x18\x05 \x01(\tH\x04\x88\x01\x01\x12\x16\n\tcls_token\x18\x06 \x01(\tH\x05\x88\x01\x01\x12\x17\n\nmask_token\x18\x07 \x01(\tH\x06\x88\x01\x01\x12;\n\x19\x61\x64\x64itional_special_tokens\x18\x08 \x01(\x0b\x32\x18.flare.runtime.TokenListB\x0c\n\n_bos_tokenB\x0c\n\n_eos_tokenB\x0c\n\n_unk_tokenB\x0c\n\n_sep_tokenB\x0c\n\n_pad_tokenB\x0c\n\n_cls_tokenB\r\n\x0b_mask_token\"\x1b\n\tTokenList\x12\x0e\n\x06values\x18\x01 \x03(\t\"\xb2\x04\n\rImageSettings\x12\x30\n\x04qwen\x18\x01 \x01(\x0b\x32 .flare.runtime.QwenImageSettingsH\x00\x12\x30\n\x04mimo\x18\x02 \x01(\x0b\x32 .flare.runtime.MimoImageSettingsH\x00\x12)\n\tdeepseek4\x18\x03 \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x12\'\n\x07moonvit\x18\x04 \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x12$\n\x04step\x18\x05 \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x12%\n\x05radio\x18\x06 \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x12J\n\x12\x64\x65\x65pseek_row_major\x18\x07 \x01(\x0b\x32,.flare.runtime.DeepseekRowMajorImageSettingsH\x00\x12#\n\x03glm\x18\x08 \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x12=\n\x0bpatch_merge\x18\t \x01(\x0b\x32&.flare.runtime.PatchMergeImageSettingsH\x00\x12+\n\x0bpadded_grid\x18\n \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x12\x34\n\x06gemma4\x18\x0b \x01(\x0b\x32\".flare.runtime.Gemma4ImageSettingsH\x00\x42\t\n\x07profile\"\xb9\x01\n\x17PatchMergeImageSettings\x12\x12\n\npatch_size\x18\x01 \x01(\r\x12\x12\n\nmin_pixels\x18\x02 \x01(\x04\x12\x12\n\nmax_pixels\x18\x03 \x01(\x04\x12\x12\n\nimage_mean\x18\x04 \x03(\x02\x12\x11\n\timage_std\x18\x05 \x03(\x02\x12\x13\n\x0bimage_token\x18\x06 \x01(\t\x12\x13\n\x0bstart_token\x18\x07 \x01(\t\x12\x11\n\tend_token\x18\x08 \x01(\t\"\x9c\x01\n\x13Gemma4ImageSettings\x12\x12\n\npatch_size\x18\x01 \x01(\r\x12\x1b\n\x13pooling_kernel_size\x18\x02 \x01(\r\x12\x17\n\x0fmax_soft_tokens\x18\x03 \x01(\r\x12\x13\n\x0bimage_token\x18\x04 \x01(\t\x12\x13\n\x0bstart_token\x18\x05 \x01(\t\x12\x11\n\tend_token\x18\x06 \x01(\t\"\x87\x01\n\x1d\x44\x65\x65pseekRowMajorImageSettings\x12\x12\n\nmin_pixels\x18\x01 \x01(\x04\x12\x12\n\nmax_tokens\x18\x02 \x01(\x04\x12#\n\x16max_width_height_ratio\x18\x03 \x01(\x04H\x00\x88\x01\x01\x42\x19\n\x17_max_width_height_ratio\"\x82\x01\n\x11QwenImageSettings\x12\x12\n\nmin_pixels\x18\x01 \x01(\x04\x12\x12\n\nmax_pixels\x18\x02 \x01(\x04\x12\x15\n\rposition_side\x18\x03 \x01(\r\x12\x16\n\x0eimage_token_id\x18\x04 \x01(\r\x12\x16\n\x0evideo_token_id\x18\x05 \x01(\r\"b\n\x11MimoImageSettings\x12\x12\n\nmin_pixels\x18\x01 \x01(\x04\x12\x12\n\nmax_pixels\x18\x02 \x01(\x04\x12\x12\n\nimage_mean\x18\x03 \x03(\x02\x12\x11\n\timage_std\x18\x04 \x03(\x02\"|\n\x06\x45ngram\x12\x11\n\ttoken_map\x18\x01 \x03(\r\x12\x14\n\x0cpad_token_id\x18\x02 \x01(\r\x12\x1d\n\x15\x63ompressed_vocabulary\x18\x03 \x01(\r\x12*\n\x06tables\x18\x04 \x03(\x0b\x32\x1a.flare.runtime.EngramTable\"\x99\x04\n\x0b\x45ngramTable\x12\r\n\x05layer\x18\x01 \x01(\r\x12\x0c\n\x04rows\x18\x02 \x01(\x04\x12\x17\n\x0f\x65mbedding_width\x18\x03 \x01(\r\x12\x13\n\x0bscale_block\x18\x04 \x01(\r\x12$\n\x07weights\x18\x05 \x01(\x0b\x32\x13.flare.runtime.Span\x12#\n\x06scales\x18\x06 \x01(\x0b\x32\x13.flare.runtime.Span\x12\'\n\x04hash\x18\x07 \x01(\x0b\x32\x19.flare.runtime.EngramHash\x12\x15\n\rweight_buffer\x18\x08 \x01(\t\x12\x14\n\x0cscale_buffer\x18\t \x01(\t\x12\x13\n\x0bhash_buffer\x18\n \x01(\t\x12\x13\n\x0bready_event\x18\x0b \x01(\t\x12\x35\n\x08\x65ncoding\x18\x0c \x01(\x0e\x32#.flare.runtime.EngramTable.Encoding\x12\x16\n\x0erequest_buffer\x18\r \x01(\t\x12\x14\n\x0cglobal_scale\x18\x0e \x01(\x02\x12/\n\x06shards\x18\x0f \x03(\x0b\x32\x1f.flare.runtime.EngramTableShard\x12\x17\n\x0fprefetch_buffer\x18\x10 \x01(\t\"E\n\x08\x45ncoding\x12\x0f\n\x0bUNSPECIFIED\x10\x00\x12\x11\n\rFP8_E4M3_E8M0\x10\x01\x12\x15\n\x11NVFP4_E4M3_GLOBAL\x10\x02\"\x8c\x01\n\x10\x45ngramTableShard\x12\x0c\n\x04rank\x18\x01 \x01(\r\x12\x11\n\tfirst_row\x18\x02 \x01(\x04\x12\x0c\n\x04rows\x18\x03 \x01(\x04\x12$\n\x07weights\x18\x04 \x01(\x0b\x32\x13.flare.runtime.Span\x12#\n\x06scales\x18\x05 \x01(\x0b\x32\x13.flare.runtime.Span\"\xc3\x01\n\nEngramHash\x12\x30\n\x06method\x18\x01 \x01(\x0e\x32 .flare.runtime.EngramHash.Method\x12\x0e\n\x06orders\x18\x02 \x03(\r\x12\x13\n\x0bmultipliers\x18\x03 \x03(\x04\x12\x0e\n\x06primes\x18\x04 \x03(\x04\x12\x0f\n\x07offsets\x18\x05 \x03(\x04\"=\n\x06Method\x12\x0f\n\x0bUNSPECIFIED\x10\x00\x12\x0e\n\nXOR_MODULO\x10\x01\x12\x12\n\x0e\x45OS_XOR_MODULO\x10\x02\"K\n\x05\x41sset\x12\x0c\n\x04name\x18\x01 \x01(\t\x12$\n\x07payload\x18\x02 \x01(\x0b\x32\x13.flare.runtime.Span\x12\x0e\n\x06sha256\x18\x03 \x01(\t\"\xd3\x04\n\x0b\x42undleIndex\x12\x14\n\x0c\x61rchitecture\x18\x01 \x03(\x05\x12.\n\x0b\x61llocations\x18\x02 \x03(\x0b\x32\x19.flare.runtime.Allocation\x12&\n\x07modules\x18\x03 \x03(\x0b\x32\x15.flare.runtime.Module\x12*\n\tfunctions\x18\x04 \x03(\x0b\x32\x17.flare.runtime.Function\x12)\n\x06graphs\x18\x05 \x03(\x0b\x32\x19.flare.runtime.GraphIndex\x12\x30\n\x0creservations\x18\x06 \x03(\x0b\x32\x1a.flare.runtime.Reservation\x12+\n\texecution\x18\x07 \x01(\x0b\x32\x18.flare.runtime.Execution\x12\'\n\x07\x63ontext\x18\x08 \x01(\x0b\x32\x16.flare.runtime.Context\x12<\n\tresources\x18\t \x03(\x0b\x32).flare.runtime.BundleIndex.ResourcesEntry\x12\x0e\n\x06\x65vents\x18\n \x03(\t\x12*\n\x04roce\x18\x0b \x01(\x0b\x32\x1c.flare.runtime.RoceTransport\x12\x36\n\x0frebuild_weights\x18\x0c \x01(\x0b\x32\x1d.flare.runtime.RebuildWeights\x1a\x45\n\x0eResourcesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\"\n\x05value\x18\x02 \x01(\x0b\x32\x13.flare.runtime.Span:\x02\x38\x01\"\xf8\x01\n\rRoceTransport\x12\x11\n\tproxy_abi\x18\x01 \x01(\r\x12\r\n\x05world\x18\x02 \x01(\r\x12\x0c\n\x04rank\x18\x03 \x01(\r\x12\x16\n\x0eregion_address\x18\x04 \x01(\x04\x12\x14\n\x0cregion_bytes\x18\x05 \x01(\x04\x12\x18\n\x10\x63ounters_address\x18\x06 \x01(\x04\x12\x16\n\x0e\x63ounters_bytes\x18\x07 \x01(\x04\x12\x12\n\nslot_bytes\x18\x08 \x01(\x04\x12\x12\n\npipe_bytes\x18\t \x01(\x04\x12\x13\n\x0b\x63trl_offset\x18\n \x01(\x04\x12\x14\n\x0cvarlen_bytes\x18\x10 \x01(\x04J\x04\x08\x0b\x10\x10\"v\n\nGraphIndex\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05\x66lags\x18\x02 \x01(\x04\x12\x10\n\x08resource\x18\x03 \x01(\t\x12\x12\n\nnode_count\x18\x04 \x01(\x04\x12\x12\n\nedge_count\x18\x05 \x01(\x04\x12\x11\n\tfunctions\x18\x06 \x03(\x04\"M\n\nPeerMemory\x12\r\n\x05owner\x18\x01 \x01(\r\x12\x0f\n\x07\x61\x64\x64ress\x18\x02 \x01(\x04\x12\x0e\n\x06nbytes\x18\x03 \x01(\x04\x12\x0f\n\x07readers\x18\x04 \x03(\r\"M\n\x07\x43ontext\x12\r\n\x05\x66lags\x18\x01 \x01(\r\x12\r\n\x05\x63\x61\x63he\x18\x02 \x01(\x05\x12$\n\x06limits\x18\x03 \x03(\x0b\x32\x14.flare.runtime.Limit\"\"\n\x05Limit\x12\n\n\x02id\x18\x01 \x01(\x04\x12\r\n\x05value\x18\x02 \x01(\x04\".\n\x0bReservation\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\x04\x12\x0e\n\x06nbytes\x18\x02 \x01(\x04\"8\n\x04Span\x12\x0e\n\x06offset\x18\x01 \x01(\x04\x12\x0e\n\x06nbytes\x18\x02 \x01(\x04\x12\x10\n\x08\x66ilename\x18\x03 \x01(\t\"\xa2\x02\n\nAllocation\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0e\n\x06nbytes\x18\x02 \x01(\x04\x12\x11\n\talignment\x18\x03 \x01(\x04\x12\x11\n\x04\x66ile\x18\x04 \x01(\tH\x00\x88\x01\x01\x12\'\n\ndata_spans\x18\x05 \x03(\x0b\x32\x13.flare.runtime.Span\x12.\n\x0brelocations\x18\x06 \x03(\x0b\x32\x19.flare.runtime.Relocation\x12\x14\n\x07\x61\x64\x64ress\x18\x07 \x01(\x04H\x01\x88\x01\x01\x12%\n\x06memory\x18\x08 \x01(\x0e\x32\x15.flare.runtime.Memory\x12%\n\x06sizing\x18\t \x01(\x0b\x32\x15.flare.runtime.SizingB\x07\n\x05_fileB\n\n\x08_address\"X\n\x06Sizing\x12)\n\x08\x63\x61pacity\x18\x01 \x01(\x0e\x32\x17.flare.runtime.Capacity\x12\x12\n\nunit_bytes\x18\x02 \x01(\x04\x12\x0f\n\x07maximum\x18\x03 \x01(\x04\"L\n\x06Module\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04\x66ile\x18\x02 \x01(\t\x12&\n\x07globals\x18\x03 \x03(\x0b\x32\x15.flare.runtime.Global\"f\n\x06Global\x12\x0e\n\x06symbol\x18\x01 \x01(\t\x12\x0c\n\x04\x66ile\x18\x02 \x01(\t\x12\x0e\n\x06nbytes\x18\x03 \x01(\x04\x12.\n\x0brelocations\x18\x04 \x03(\x0b\x32\x19.flare.runtime.Relocation\"y\n\x08\x46unction\x12\x0e\n\x06module\x18\x01 \x01(\t\x12\x0e\n\x06symbol\x18\x02 \x01(\t\x12\x17\n\x0fparameter_sizes\x18\x03 \x03(\x04\x12\x34\n\nattributes\x18\x04 \x03(\x0b\x32 .flare.runtime.FunctionAttribute\".\n\x11\x46unctionAttribute\x12\n\n\x02id\x18\x01 \x01(\x05\x12\r\n\x05value\x18\x02 \x01(\x05\"/\n\tReference\x12\x12\n\nallocation\x18\x01 \x01(\t\x12\x0e\n\x06offset\x18\x02 \x01(\x04\"s\n\nRelocation\x12\x0e\n\x06offset\x18\x01 \x01(\x04\x12(\n\x06target\x18\x02 \x01(\x0b\x32\x18.flare.runtime.Reference\x12+\n\x04kind\x18\x03 \x01(\x0e\x32\x1d.flare.runtime.RelocationKind\"D\n\x04\x42lob\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\x0c\x12.\n\x0brelocations\x18\x02 \x03(\x0b\x32\x19.flare.runtime.Relocation\";\n\tAttribute\x12\n\n\x02id\x18\x01 \x01(\x05\x12\"\n\x05value\x18\x02 \x01(\x0b\x32\x13.flare.runtime.Blob\"\x9d\x01\n\x06Kernel\x12\x10\n\x08\x66unction\x18\x01 \x01(\x04\x12\x0c\n\x04grid\x18\x02 \x03(\r\x12\r\n\x05\x62lock\x18\x03 \x03(\r\x12\x0e\n\x06shared\x18\x04 \x01(\r\x12&\n\targuments\x18\x05 \x03(\x0b\x32\x13.flare.runtime.Blob\x12,\n\nattributes\x18\x06 \x03(\x0b\x32\x18.flare.runtime.Attribute\"\x8a\x01\n\x06Memset\x12-\n\x0b\x64\x65stination\x18\x01 \x01(\x0b\x32\x18.flare.runtime.Reference\x12\r\n\x05pitch\x18\x02 \x01(\x04\x12\r\n\x05value\x18\x03 \x01(\r\x12\x14\n\x0c\x65lement_size\x18\x04 \x01(\r\x12\r\n\x05width\x18\x05 \x01(\x04\x12\x0e\n\x06height\x18\x06 \x01(\x04\"o\n\x04\x43opy\x12(\n\x06source\x18\x01 \x01(\x0b\x32\x18.flare.runtime.Reference\x12-\n\x0b\x64\x65stination\x18\x02 \x01(\x0b\x32\x18.flare.runtime.Reference\x12\x0e\n\x06nbytes\x18\x03 \x01(\x04\"\x07\n\x05\x45mpty\"\x1a\n\tEventWait\x12\r\n\x05\x65vent\x18\x01 \x01(\t\"\xe1\x01\n\x04Node\x12\'\n\x06kernel\x18\x01 \x01(\x0b\x32\x15.flare.runtime.KernelH\x00\x12\'\n\x06memset\x18\x02 \x01(\x0b\x32\x15.flare.runtime.MemsetH\x00\x12#\n\x04\x63opy\x18\x03 \x01(\x0b\x32\x13.flare.runtime.CopyH\x00\x12%\n\x05\x65mpty\x18\x04 \x01(\x0b\x32\x14.flare.runtime.EmptyH\x00\x12.\n\nevent_wait\x18\x05 \x01(\x0b\x32\x18.flare.runtime.EventWaitH\x00\x42\x0b\n\toperation\"9\n\x04\x45\x64ge\x12\x0e\n\x06source\x18\x01 \x01(\x04\x12\x13\n\x0b\x64\x65stination\x18\x02 \x01(\x04\x12\x0c\n\x04\x64\x61ta\x18\x03 \x01(\x0c\"\xb9\x02\n\tExecution\x12\x13\n\x0b\x61\x62i_version\x18\x01 \x01(\r\x12\x12\n\nmax_active\x18\x02 \x01(\x04\x12\x19\n\x11input_frame_bytes\x18\x03 \x01(\x04\x12&\n\x07\x62uffers\x18\x04 \x03(\x0b\x32\x15.flare.runtime.Buffer\x12-\n\x06graphs\x18\x05 \x03(\x0b\x32\x1d.flare.runtime.ExecutionGraph\x12\x31\n\rtuning_graphs\x18\x06 \x03(\x0b\x32\x1a.flare.runtime.TuningGraph\x12!\n\x19\x63ompletion_token_capacity\x18\x07 \x01(\r\x12;\n\x12persistent_workers\x18\x08 \x03(\x0b\x32\x1f.flare.runtime.PersistentWorker\"\xa9\x01\n\x10PersistentWorker\x12\x17\n\x0fworker_sm_count\x18\x01 \x01(\r\x12\r\n\x05graph\x18\x02 \x01(\t\x12+\n\tstop_flag\x18\x03 \x01(\x0b\x32\x18.flare.runtime.Reference\x12)\n\x07metrics\x18\x04 \x01(\x0b\x32\x18.flare.runtime.Reference\x12\x15\n\rmetrics_count\x18\x05 \x01(\r\"C\n\x0bTuningGraph\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07outputs\x18\x02 \x03(\t\x12\x15\n\rstatus_buffer\x18\x03 \x01(\t\"\x82\x01\n\x06\x42uffer\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0e\n\x06nbytes\x18\x02 \x01(\x04\x12\r\n\x05\x64type\x18\x03 \x01(\t\x12\r\n\x05shape\x18\x04 \x03(\x04\x12\x0f\n\x07strides\x18\x05 \x03(\x04\x12+\n\treference\x18\x06 \x01(\x0b\x32\x18.flare.runtime.Reference\"\x95\x04\n\x0e\x45xecutionGraph\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04kind\x18\x02 \x01(\t\x12\x15\n\rsampling_mode\x18\x03 \x01(\t\x12\x16\n\x0e\x62\x61tch_capacity\x18\x04 \x01(\x04\x12\x16\n\x0etoken_capacity\x18\x05 \x01(\x04\x12\x33\n\x0einput_bindings\x18\x06 \x03(\x0b\x32\x1b.flare.runtime.InputBinding\x12\x19\n\x0c\x64raft_tokens\x18\x07 \x01(\rH\x00\x88\x01\x01\x12\x1a\n\rverify_tokens\x18\x08 \x01(\rH\x01\x88\x01\x01\x12\x30\n\x0c\x64raft_source\x18\t \x01(\x0e\x32\x1a.flare.runtime.DraftSource\x12 \n\x13speculation_enabled\x18\n \x01(\x08H\x02\x88\x01\x01\x12\x1d\n\x15\x65stimated_duration_ns\x18\x0b \x01(\x04\x12\x18\n\x10prefill_capacity\x18\x0c \x01(\x04\x12\x1d\n\x15packed_token_capacity\x18\r \x01(\x04\x12\x18\n\x10\x63onfidence_width\x18\x0e \x01(\r\x12\x33\n\x0etuned_bindings\x18\x0f \x03(\x0b\x32\x1b.flare.runtime.TunedBindingB\x0f\n\r_draft_tokensB\x10\n\x0e_verify_tokensB\x16\n\x14_speculation_enabled\"H\n\x0cInputBinding\x12\x13\n\x0b\x62uffer_name\x18\x01 \x01(\t\x12\x13\n\x0bhost_offset\x18\x02 \x01(\x04\x12\x0e\n\x06nbytes\x18\x03 \x01(\x04*\xfa\x01\n\x19PreparationParameterScope\x12+\n\'PREPARATION_PARAMETER_SCOPE_UNSPECIFIED\x10\x00\x12*\n&PREPARATION_PARAMETER_SCOPE_DEPLOYMENT\x10\x01\x12\'\n#PREPARATION_PARAMETER_SCOPE_COMBINE\x10\x02\x12-\n)PREPARATION_PARAMETER_SCOPE_TARGET_WEIGHT\x10\x03\x12,\n(PREPARATION_PARAMETER_SCOPE_DRAFT_WEIGHT\x10\x04*\x8e\x01\n\x0bHistoryKind\x12\x17\n\x13HISTORY_UNSPECIFIED\x10\x00\x12\x13\n\x0fPAGED_KEY_VALUE\x10\x01\x12\x10\n\x0cPAGED_LATENT\x10\x02\x12\x12\n\x0eSLIDING_WINDOW\x10\x03\x12\x13\n\x0fRECURRENT_STATE\x10\x04\x12\x16\n\x12\x43ONTINUATION_STATE\x10\x05*\xc7\x07\n\x0bValueSource\x12\x15\n\x11VALUE_UNSPECIFIED\x10\x00\x12\x0c\n\x08\x43ONSTANT\x10\x01\x12\x10\n\x0cREQUEST_SLOT\x10\x02\x12\x16\n\x12REQUEST_GENERATION\x10\x03\x12\r\n\tLIVE_ROWS\x10\x04\x12\x10\n\x0cQUERY_LENGTH\x10\x05\x12\x12\n\x0eSAMPLE_ENABLED\x10\x06\x12\x10\n\x0cPROMPT_TOKEN\x10\x07\x12\x11\n\rPENDING_TOKEN\x10\x08\x12\x1c\n\x18PROMPT_AND_PENDING_TOKEN\x10\t\x12\x13\n\x0fPROMPT_POSITION\x10\n\x12\x17\n\x13IMAGE_FEATURE_INDEX\x10\x0b\x12\x16\n\x12IMAGE_LEFT_CONTEXT\x10\x0c\x12\x17\n\x13IMAGE_RIGHT_CONTEXT\x10\r\x12\x0e\n\nPAGE_TABLE\x10\x0e\x12\x13\n\x0fLIVE_STATE_ROWS\x10\x0f\x12\x12\n\x0eLIVE_STATE_ROW\x10\x10\x12\x14\n\x10PREFIX_STATE_ROW\x10\x11\x12\x16\n\x12SNAPSHOT_STATE_ROW\x10\x12\x12\x13\n\x0f\x43ONSUMED_TOKENS\x10\x13\x12\x1c\n\x18SNAPSHOT_CONSUMED_TOKENS\x10\x14\x12\x0f\n\x0bPREFILL_ROW\x10\x15\x12\x11\n\rSAMPLING_SEED\x10\x16\x12\x17\n\x13SAMPLING_PARAMETERS\x10\x17\x12\x12\n\x0eSAMPLING_TOP_K\x10\x18\x12\x12\n\x0eMAX_NEW_TOKENS\x10\x19\x12\x11\n\rEOS_TOKEN_IDS\x10\x1a\x12\r\n\tEOS_COUNT\x10\x1b\x12\x14\n\x10PROMPT_HISTOGRAM\x10\x1c\x12\x10\n\x0cGRAMMAR_MASK\x10\x1d\x12\x13\n\x0fGRAMMAR_ENABLED\x10\x1e\x12\x12\n\x0e\x43OPY_TOKEN_IDS\x10\x1f\x12\x14\n\x10\x43OPY_TOKEN_COUNT\x10 \x12\x18\n\x14\x43OPY_CONSUMED_TOKENS\x10!\x12\x13\n\x0f\x43OPY_GENERATION\x10\"\x12\x15\n\x11\x43OPY_GRAMMAR_MASK\x10#\x12\x16\n\x12\x43OPY_GRAMMAR_COUNT\x10$\x12\x10\n\x0cIMAGE_TENSOR\x10%\x12\x16\n\x12IMAGE_FEATURE_SLOT\x10&\x12\x17\n\x13PROMPT_TARGET_TOKEN\x10\'\x12\x1c\n\x18SPECULATIVE_PREFIX_LIMIT\x10(\x12\x1a\n\x16PROMPT_LOOKAHEAD_TOKEN\x10)\x12\x1b\n\x17PROMPT_LOOKAHEAD_LENGTH\x10*\x12\x12\n\x0e\x43ORE_PARAMETER\x10+*|\n\rInputIndexing\x12\x18\n\x14INDEXING_UNSPECIFIED\x10\x00\x12\n\n\x06SCALAR\x10\x01\x12\x12\n\x0eSUBMISSION_ROW\x10\x02\x12\x0f\n\x0bREQUEST_ROW\x10\x03\x12\x10\n\x0cPACKED_TOKEN\x10\x04\x12\x0e\n\nACTIVE_ROW\x10\x05*T\n\x0fStateAccessKind\x12\x1c\n\x18STATE_ACCESS_UNSPECIFIED\x10\x00\x12\x08\n\x04READ\x10\x01\x12\t\n\x05WRITE\x10\x02\x12\x0e\n\nREAD_WRITE\x10\x03*\x8b\x02\n\x0eGraphOperation\x12\x1f\n\x1bGRAPH_OPERATION_UNSPECIFIED\x10\x00\x12\x08\n\x04INIT\x10\x01\x12\x0b\n\x07RESTORE\x10\x02\x12\x0c\n\x08SNAPSHOT\x10\x03\x12\x0b\n\x07PREFILL\x10\x04\x12\n\n\x06\x44\x45\x43ODE\x10\x05\x12\n\n\x06RESUME\x10\x06\x12\n\n\x06VISION\x10\x07\x12\x0f\n\x0bSPECULATIVE\x10\x08\x12\t\n\x05MIXED\x10\t\x12\x12\n\x0eSCORED_PREFILL\x10\x0c\x12\x14\n\x10TERMINAL_PREFILL\x10\x0e\"\x04\x08\n\x10\n\"\x04\x08\x0b\x10\x0b\"\x04\x08\r\x10\r*\x08PROPOSAL*\x0cVERIFICATION*\x12PACKED_SPECULATIVE*\xa1\x01\n\x0eToolParserKind\x12\x1b\n\x17TOOL_PARSER_UNSPECIFIED\x10\x00\x12\x0e\n\nQWEN_CODER\x10\x01\x12\x15\n\x11GLM_ARGUMENT_TAGS\x10\x02\x12\x08\n\x04\x44SML\x10\x03\x12\x08\n\x04XTML\x10\x04\x12\x0f\n\x0bMINIMAX_XML\x10\x05\x12\x0e\n\nGEMMA_CALL\x10\x06\x12\x08\n\x04\x41TEM\x10\x07\x12\x0c\n\x08TML_JSON\x10\x08*\xa6\x01\n\x13ReasoningParserKind\x12 \n\x1cREASONING_PARSER_UNSPECIFIED\x10\x00\x12\x0e\n\nTHINK_TAGS\x10\x01\x12\x0e\n\nXTML_THINK\x10\x02\x12\x0c\n\x08MM_THINK\x10\x03\x12\x13\n\x0f\x43HANNEL_THOUGHT\x10\x04\x12\x15\n\x11RECIPIENT_HEADERS\x10\x05\x12\x13\n\x0f\x43ONTENT_HEADERS\x10\x06*\x92\x03\n\x14ImagePreparationKind\x12!\n\x1dIMAGE_PREPARATION_UNSPECIFIED\x10\x00\x12\x1a\n\x16QWEN_IMAGE_PREPARATION\x10\x01\x12\x1a\n\x16MIMO_IMAGE_PREPARATION\x10\x02\x12\x1e\n\x1a\x44\x45\x45PSEEK_IMAGE_PREPARATION\x10\x03\x12\x1d\n\x19MOONVIT_IMAGE_PREPARATION\x10\x04\x12\x1a\n\x16STEP_IMAGE_PREPARATION\x10\x05\x12\x1b\n\x17RADIO_IMAGE_PREPARATION\x10\x06\x12(\n$DEEPSEEK_ROW_MAJOR_IMAGE_PREPARATION\x10\x07\x12\x19\n\x15GLM_IMAGE_PREPARATION\x10\x08\x12!\n\x1dPATCH_MERGE_IMAGE_PREPARATION\x10\t\x12!\n\x1dPADDED_GRID_IMAGE_PREPARATION\x10\n\x12\x1c\n\x18GEMMA4_IMAGE_PREPARATION\x10\x0b*\xb6\x02\n\x0fImageLayoutKind\x12\x1c\n\x18IMAGE_LAYOUT_UNSPECIFIED\x10\x00\x12\x15\n\x11QWEN_IMAGE_LAYOUT\x10\x01\x12\x15\n\x11MIMO_IMAGE_LAYOUT\x10\x02\x12\x19\n\x15\x44\x45\x45PSEEK_IMAGE_LAYOUT\x10\x03\x12\x18\n\x14MOONVIT_IMAGE_LAYOUT\x10\x04\x12\x15\n\x11STEP_IMAGE_LAYOUT\x10\x05\x12\x16\n\x12RADIO_IMAGE_LAYOUT\x10\x06\x12#\n\x1f\x44\x45\x45PSEEK_ROW_MAJOR_IMAGE_LAYOUT\x10\x07\x12\x14\n\x10GLM_IMAGE_LAYOUT\x10\x08\x12\x1a\n\x16\x42RACKETED_IMAGE_LAYOUT\x10\t\x12\x1c\n\x18\x43LASS_TOKEN_IMAGE_LAYOUT\x10\n*P\n\rPromptEncoder\x12\x10\n\x0cPROMPT_JINJA\x10\x00\x12\x0f\n\x0b\x44\x45\x45PSEEK_V4\x10\x01\x12\x10\n\x0c\x44\x45\x45PSEEK_V41\x10\x02\x12\n\n\x06TML_V0\x10\x03*B\n\x10TemplateEncoding\x12\x11\n\rTEMPLATE_TEXT\x10\x00\x12\x1b\n\x17TEMPLATE_TOKEN_SEGMENTS\x10\x01*/\n\x06Memory\x12\n\n\x06\x44\x45VICE\x10\x00\x12\x0f\n\x0bMAPPED_HOST\x10\x01\x12\x08\n\x04PEER\x10\x02*(\n\x08\x43\x61pacity\x12\x0e\n\nSTATE_ROWS\x10\x00\x12\x0c\n\x08KV_PAGES\x10\x01*-\n\x0eRelocationKind\x12\x0b\n\x07POINTER\x10\x00\x12\x0e\n\nTENSOR_MAP\x10\x01*4\n\x0b\x44raftSource\x12\x0c\n\x08NO_DRAFT\x10\x00\x12\x07\n\x03MTP\x10\x01\x12\x0e\n\nCOPY_DRAFT\x10\x02\x62\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -39,38 +39,38 @@ _globals['_REBUILDSPECULATION']._serialized_options = b'\030\001' _globals['_BUNDLEINDEX_RESOURCESENTRY']._loaded_options = None _globals['_BUNDLEINDEX_RESOURCESENTRY']._serialized_options = b'8\001' - _globals['_PREPARATIONPARAMETERSCOPE']._serialized_start=16343 - _globals['_PREPARATIONPARAMETERSCOPE']._serialized_end=16593 - _globals['_HISTORYKIND']._serialized_start=16596 - _globals['_HISTORYKIND']._serialized_end=16738 - _globals['_VALUESOURCE']._serialized_start=16741 - _globals['_VALUESOURCE']._serialized_end=17708 - _globals['_INPUTINDEXING']._serialized_start=17710 - _globals['_INPUTINDEXING']._serialized_end=17834 - _globals['_STATEACCESSKIND']._serialized_start=17836 - _globals['_STATEACCESSKIND']._serialized_end=17920 - _globals['_GRAPHOPERATION']._serialized_start=17923 - _globals['_GRAPHOPERATION']._serialized_end=18190 - _globals['_TOOLPARSERKIND']._serialized_start=18193 - _globals['_TOOLPARSERKIND']._serialized_end=18354 - _globals['_REASONINGPARSERKIND']._serialized_start=18357 - _globals['_REASONINGPARSERKIND']._serialized_end=18523 - _globals['_IMAGEPREPARATIONKIND']._serialized_start=18526 - _globals['_IMAGEPREPARATIONKIND']._serialized_end=18898 - _globals['_IMAGELAYOUTKIND']._serialized_start=18901 - _globals['_IMAGELAYOUTKIND']._serialized_end=19211 - _globals['_PROMPTENCODER']._serialized_start=19213 - _globals['_PROMPTENCODER']._serialized_end=19293 - _globals['_TEMPLATEENCODING']._serialized_start=19295 - _globals['_TEMPLATEENCODING']._serialized_end=19361 - _globals['_MEMORY']._serialized_start=19363 - _globals['_MEMORY']._serialized_end=19410 - _globals['_CAPACITY']._serialized_start=19412 - _globals['_CAPACITY']._serialized_end=19452 - _globals['_RELOCATIONKIND']._serialized_start=19454 - _globals['_RELOCATIONKIND']._serialized_end=19499 - _globals['_DRAFTSOURCE']._serialized_start=19501 - _globals['_DRAFTSOURCE']._serialized_end=19553 + _globals['_PREPARATIONPARAMETERSCOPE']._serialized_start=16580 + _globals['_PREPARATIONPARAMETERSCOPE']._serialized_end=16830 + _globals['_HISTORYKIND']._serialized_start=16833 + _globals['_HISTORYKIND']._serialized_end=16975 + _globals['_VALUESOURCE']._serialized_start=16978 + _globals['_VALUESOURCE']._serialized_end=17945 + _globals['_INPUTINDEXING']._serialized_start=17947 + _globals['_INPUTINDEXING']._serialized_end=18071 + _globals['_STATEACCESSKIND']._serialized_start=18073 + _globals['_STATEACCESSKIND']._serialized_end=18157 + _globals['_GRAPHOPERATION']._serialized_start=18160 + _globals['_GRAPHOPERATION']._serialized_end=18427 + _globals['_TOOLPARSERKIND']._serialized_start=18430 + _globals['_TOOLPARSERKIND']._serialized_end=18591 + _globals['_REASONINGPARSERKIND']._serialized_start=18594 + _globals['_REASONINGPARSERKIND']._serialized_end=18760 + _globals['_IMAGEPREPARATIONKIND']._serialized_start=18763 + _globals['_IMAGEPREPARATIONKIND']._serialized_end=19165 + _globals['_IMAGELAYOUTKIND']._serialized_start=19168 + _globals['_IMAGELAYOUTKIND']._serialized_end=19478 + _globals['_PROMPTENCODER']._serialized_start=19480 + _globals['_PROMPTENCODER']._serialized_end=19560 + _globals['_TEMPLATEENCODING']._serialized_start=19562 + _globals['_TEMPLATEENCODING']._serialized_end=19628 + _globals['_MEMORY']._serialized_start=19630 + _globals['_MEMORY']._serialized_end=19677 + _globals['_CAPACITY']._serialized_start=19679 + _globals['_CAPACITY']._serialized_end=19719 + _globals['_RELOCATIONKIND']._serialized_start=19721 + _globals['_RELOCATIONKIND']._serialized_end=19766 + _globals['_DRAFTSOURCE']._serialized_start=19768 + _globals['_DRAFTSOURCE']._serialized_end=19820 _globals['_PROTECTEDINDEX']._serialized_start=38 _globals['_PROTECTEDINDEX']._serialized_end=191 _globals['_SIGNEDGROUP']._serialized_start=193 @@ -114,143 +114,145 @@ _globals['_COREPARAMETERRANGE']._serialized_start=5256 _globals['_COREPARAMETERRANGE']._serialized_end=5328 _globals['_VISIONCAPACITY']._serialized_start=5331 - _globals['_VISIONCAPACITY']._serialized_end=5475 - _globals['_CACHECONTRACT']._serialized_start=5478 - _globals['_CACHECONTRACT']._serialized_end=5662 - _globals['_CODECLAYOUT']._serialized_start=5664 - _globals['_CODECLAYOUT']._serialized_end=5778 - _globals['_CODECFIELD']._serialized_start=5780 - _globals['_CODECFIELD']._serialized_end=5858 - _globals['_HISTORYREGION']._serialized_start=5861 - _globals['_HISTORYREGION']._serialized_end=6011 - _globals['_PAGETABLEVIEW']._serialized_start=6013 - _globals['_PAGETABLEVIEW']._serialized_end=6065 - _globals['_VALUEBINDING']._serialized_start=6068 - _globals['_VALUEBINDING']._serialized_end=6264 - _globals['_STATEVIEW']._serialized_start=6266 - _globals['_STATEVIEW']._serialized_end=6341 - _globals['_STATEACCESS']._serialized_start=6343 - _globals['_STATEACCESS']._serialized_end=6444 - _globals['_COMPLETIONCURSOR']._serialized_start=6446 - _globals['_COMPLETIONCURSOR']._serialized_end=6525 - _globals['_TUNEDBINDING']._serialized_start=6527 - _globals['_TUNEDBINDING']._serialized_end=6579 - _globals['_GRAPHCONTRACT']._serialized_start=6582 - _globals['_GRAPHCONTRACT']._serialized_end=6960 - _globals['_TOOLPARSER']._serialized_start=6962 - _globals['_TOOLPARSER']._serialized_end=7069 - _globals['_REASONINGPARSER']._serialized_start=7072 - _globals['_REASONINGPARSER']._serialized_end=7221 - _globals['_PREFIXBOUNDARY']._serialized_start=7224 - _globals['_PREFIXBOUNDARY']._serialized_end=7426 - _globals['_IMAGESPAN']._serialized_start=7428 - _globals['_IMAGESPAN']._serialized_end=7549 - _globals['_IMAGETOKENLAYOUT']._serialized_start=7551 - _globals['_IMAGETOKENLAYOUT']._serialized_end=7632 - _globals['_FRONTENDCONTRACT']._serialized_start=7635 - _globals['_FRONTENDCONTRACT']._serialized_end=8133 - _globals['_CLUSTER']._serialized_start=8135 - _globals['_CLUSTER']._serialized_end=8184 - _globals['_DEFAULTSAMPLINGPARAMETERS']._serialized_start=8187 - _globals['_DEFAULTSAMPLINGPARAMETERS']._serialized_end=8583 - _globals['_SAMPLINGFLOATRANGE']._serialized_start=8585 - _globals['_SAMPLINGFLOATRANGE']._serialized_end=8657 - _globals['_SAMPLINGINTRANGE']._serialized_start=8659 - _globals['_SAMPLINGINTRANGE']._serialized_end=8729 - _globals['_SAMPLINGRANGES']._serialized_start=8732 - _globals['_SAMPLINGRANGES']._serialized_end=9138 - _globals['_FRONTENDSETTINGS']._serialized_start=9141 - _globals['_FRONTENDSETTINGS']._serialized_end=9466 - _globals['_TOKENIZERSETTINGS']._serialized_start=9469 - _globals['_TOKENIZERSETTINGS']._serialized_end=9817 - _globals['_TOKENLIST']._serialized_start=9819 - _globals['_TOKENLIST']._serialized_end=9846 - _globals['_IMAGESETTINGS']._serialized_start=9849 - _globals['_IMAGESETTINGS']._serialized_end=10357 - _globals['_PATCHMERGEIMAGESETTINGS']._serialized_start=10360 - _globals['_PATCHMERGEIMAGESETTINGS']._serialized_end=10545 - _globals['_DEEPSEEKROWMAJORIMAGESETTINGS']._serialized_start=10548 - _globals['_DEEPSEEKROWMAJORIMAGESETTINGS']._serialized_end=10683 - _globals['_QWENIMAGESETTINGS']._serialized_start=10686 - _globals['_QWENIMAGESETTINGS']._serialized_end=10816 - _globals['_MIMOIMAGESETTINGS']._serialized_start=10818 - _globals['_MIMOIMAGESETTINGS']._serialized_end=10916 - _globals['_ENGRAM']._serialized_start=10918 - _globals['_ENGRAM']._serialized_end=11042 - _globals['_ENGRAMTABLE']._serialized_start=11045 - _globals['_ENGRAMTABLE']._serialized_end=11582 - _globals['_ENGRAMTABLE_ENCODING']._serialized_start=11513 - _globals['_ENGRAMTABLE_ENCODING']._serialized_end=11582 - _globals['_ENGRAMTABLESHARD']._serialized_start=11585 - _globals['_ENGRAMTABLESHARD']._serialized_end=11725 - _globals['_ENGRAMHASH']._serialized_start=11728 - _globals['_ENGRAMHASH']._serialized_end=11923 - _globals['_ENGRAMHASH_METHOD']._serialized_start=11862 - _globals['_ENGRAMHASH_METHOD']._serialized_end=11923 - _globals['_ASSET']._serialized_start=11925 - _globals['_ASSET']._serialized_end=12000 - _globals['_BUNDLEINDEX']._serialized_start=12003 - _globals['_BUNDLEINDEX']._serialized_end=12598 - _globals['_BUNDLEINDEX_RESOURCESENTRY']._serialized_start=12529 - _globals['_BUNDLEINDEX_RESOURCESENTRY']._serialized_end=12598 - _globals['_ROCETRANSPORT']._serialized_start=12601 - _globals['_ROCETRANSPORT']._serialized_end=12849 - _globals['_GRAPHINDEX']._serialized_start=12851 - _globals['_GRAPHINDEX']._serialized_end=12969 - _globals['_PEERMEMORY']._serialized_start=12971 - _globals['_PEERMEMORY']._serialized_end=13048 - _globals['_CONTEXT']._serialized_start=13050 - _globals['_CONTEXT']._serialized_end=13127 - _globals['_LIMIT']._serialized_start=13129 - _globals['_LIMIT']._serialized_end=13163 - _globals['_RESERVATION']._serialized_start=13165 - _globals['_RESERVATION']._serialized_end=13211 - _globals['_SPAN']._serialized_start=13213 - _globals['_SPAN']._serialized_end=13269 - _globals['_ALLOCATION']._serialized_start=13272 - _globals['_ALLOCATION']._serialized_end=13562 - _globals['_SIZING']._serialized_start=13564 - _globals['_SIZING']._serialized_end=13652 - _globals['_MODULE']._serialized_start=13654 - _globals['_MODULE']._serialized_end=13730 - _globals['_GLOBAL']._serialized_start=13732 - _globals['_GLOBAL']._serialized_end=13834 - _globals['_FUNCTION']._serialized_start=13836 - _globals['_FUNCTION']._serialized_end=13957 - _globals['_FUNCTIONATTRIBUTE']._serialized_start=13959 - _globals['_FUNCTIONATTRIBUTE']._serialized_end=14005 - _globals['_REFERENCE']._serialized_start=14007 - _globals['_REFERENCE']._serialized_end=14054 - _globals['_RELOCATION']._serialized_start=14056 - _globals['_RELOCATION']._serialized_end=14171 - _globals['_BLOB']._serialized_start=14173 - _globals['_BLOB']._serialized_end=14241 - _globals['_ATTRIBUTE']._serialized_start=14243 - _globals['_ATTRIBUTE']._serialized_end=14302 - _globals['_KERNEL']._serialized_start=14305 - _globals['_KERNEL']._serialized_end=14462 - _globals['_MEMSET']._serialized_start=14465 - _globals['_MEMSET']._serialized_end=14603 - _globals['_COPY']._serialized_start=14605 - _globals['_COPY']._serialized_end=14716 - _globals['_EMPTY']._serialized_start=14718 - _globals['_EMPTY']._serialized_end=14725 - _globals['_EVENTWAIT']._serialized_start=14727 - _globals['_EVENTWAIT']._serialized_end=14753 - _globals['_NODE']._serialized_start=14756 - _globals['_NODE']._serialized_end=14981 - _globals['_EDGE']._serialized_start=14983 - _globals['_EDGE']._serialized_end=15040 - _globals['_EXECUTION']._serialized_start=15043 - _globals['_EXECUTION']._serialized_end=15356 - _globals['_PERSISTENTWORKER']._serialized_start=15359 - _globals['_PERSISTENTWORKER']._serialized_end=15528 - _globals['_TUNINGGRAPH']._serialized_start=15530 - _globals['_TUNINGGRAPH']._serialized_end=15597 - _globals['_BUFFER']._serialized_start=15600 - _globals['_BUFFER']._serialized_end=15730 - _globals['_EXECUTIONGRAPH']._serialized_start=15733 - _globals['_EXECUTIONGRAPH']._serialized_end=16266 - _globals['_INPUTBINDING']._serialized_start=16268 - _globals['_INPUTBINDING']._serialized_end=16340 + _globals['_VISIONCAPACITY']._serialized_end=5499 + _globals['_CACHECONTRACT']._serialized_start=5502 + _globals['_CACHECONTRACT']._serialized_end=5686 + _globals['_CODECLAYOUT']._serialized_start=5688 + _globals['_CODECLAYOUT']._serialized_end=5802 + _globals['_CODECFIELD']._serialized_start=5804 + _globals['_CODECFIELD']._serialized_end=5882 + _globals['_HISTORYREGION']._serialized_start=5885 + _globals['_HISTORYREGION']._serialized_end=6035 + _globals['_PAGETABLEVIEW']._serialized_start=6037 + _globals['_PAGETABLEVIEW']._serialized_end=6089 + _globals['_VALUEBINDING']._serialized_start=6092 + _globals['_VALUEBINDING']._serialized_end=6288 + _globals['_STATEVIEW']._serialized_start=6290 + _globals['_STATEVIEW']._serialized_end=6365 + _globals['_STATEACCESS']._serialized_start=6367 + _globals['_STATEACCESS']._serialized_end=6468 + _globals['_COMPLETIONCURSOR']._serialized_start=6470 + _globals['_COMPLETIONCURSOR']._serialized_end=6549 + _globals['_TUNEDBINDING']._serialized_start=6551 + _globals['_TUNEDBINDING']._serialized_end=6603 + _globals['_GRAPHCONTRACT']._serialized_start=6606 + _globals['_GRAPHCONTRACT']._serialized_end=6984 + _globals['_TOOLPARSER']._serialized_start=6986 + _globals['_TOOLPARSER']._serialized_end=7093 + _globals['_REASONINGPARSER']._serialized_start=7096 + _globals['_REASONINGPARSER']._serialized_end=7245 + _globals['_PREFIXBOUNDARY']._serialized_start=7248 + _globals['_PREFIXBOUNDARY']._serialized_end=7450 + _globals['_IMAGESPAN']._serialized_start=7452 + _globals['_IMAGESPAN']._serialized_end=7573 + _globals['_IMAGETOKENLAYOUT']._serialized_start=7575 + _globals['_IMAGETOKENLAYOUT']._serialized_end=7656 + _globals['_FRONTENDCONTRACT']._serialized_start=7659 + _globals['_FRONTENDCONTRACT']._serialized_end=8157 + _globals['_CLUSTER']._serialized_start=8159 + _globals['_CLUSTER']._serialized_end=8208 + _globals['_DEFAULTSAMPLINGPARAMETERS']._serialized_start=8211 + _globals['_DEFAULTSAMPLINGPARAMETERS']._serialized_end=8607 + _globals['_SAMPLINGFLOATRANGE']._serialized_start=8609 + _globals['_SAMPLINGFLOATRANGE']._serialized_end=8681 + _globals['_SAMPLINGINTRANGE']._serialized_start=8683 + _globals['_SAMPLINGINTRANGE']._serialized_end=8753 + _globals['_SAMPLINGRANGES']._serialized_start=8756 + _globals['_SAMPLINGRANGES']._serialized_end=9162 + _globals['_FRONTENDSETTINGS']._serialized_start=9165 + _globals['_FRONTENDSETTINGS']._serialized_end=9490 + _globals['_TOKENIZERSETTINGS']._serialized_start=9493 + _globals['_TOKENIZERSETTINGS']._serialized_end=9841 + _globals['_TOKENLIST']._serialized_start=9843 + _globals['_TOKENLIST']._serialized_end=9870 + _globals['_IMAGESETTINGS']._serialized_start=9873 + _globals['_IMAGESETTINGS']._serialized_end=10435 + _globals['_PATCHMERGEIMAGESETTINGS']._serialized_start=10438 + _globals['_PATCHMERGEIMAGESETTINGS']._serialized_end=10623 + _globals['_GEMMA4IMAGESETTINGS']._serialized_start=10626 + _globals['_GEMMA4IMAGESETTINGS']._serialized_end=10782 + _globals['_DEEPSEEKROWMAJORIMAGESETTINGS']._serialized_start=10785 + _globals['_DEEPSEEKROWMAJORIMAGESETTINGS']._serialized_end=10920 + _globals['_QWENIMAGESETTINGS']._serialized_start=10923 + _globals['_QWENIMAGESETTINGS']._serialized_end=11053 + _globals['_MIMOIMAGESETTINGS']._serialized_start=11055 + _globals['_MIMOIMAGESETTINGS']._serialized_end=11153 + _globals['_ENGRAM']._serialized_start=11155 + _globals['_ENGRAM']._serialized_end=11279 + _globals['_ENGRAMTABLE']._serialized_start=11282 + _globals['_ENGRAMTABLE']._serialized_end=11819 + _globals['_ENGRAMTABLE_ENCODING']._serialized_start=11750 + _globals['_ENGRAMTABLE_ENCODING']._serialized_end=11819 + _globals['_ENGRAMTABLESHARD']._serialized_start=11822 + _globals['_ENGRAMTABLESHARD']._serialized_end=11962 + _globals['_ENGRAMHASH']._serialized_start=11965 + _globals['_ENGRAMHASH']._serialized_end=12160 + _globals['_ENGRAMHASH_METHOD']._serialized_start=12099 + _globals['_ENGRAMHASH_METHOD']._serialized_end=12160 + _globals['_ASSET']._serialized_start=12162 + _globals['_ASSET']._serialized_end=12237 + _globals['_BUNDLEINDEX']._serialized_start=12240 + _globals['_BUNDLEINDEX']._serialized_end=12835 + _globals['_BUNDLEINDEX_RESOURCESENTRY']._serialized_start=12766 + _globals['_BUNDLEINDEX_RESOURCESENTRY']._serialized_end=12835 + _globals['_ROCETRANSPORT']._serialized_start=12838 + _globals['_ROCETRANSPORT']._serialized_end=13086 + _globals['_GRAPHINDEX']._serialized_start=13088 + _globals['_GRAPHINDEX']._serialized_end=13206 + _globals['_PEERMEMORY']._serialized_start=13208 + _globals['_PEERMEMORY']._serialized_end=13285 + _globals['_CONTEXT']._serialized_start=13287 + _globals['_CONTEXT']._serialized_end=13364 + _globals['_LIMIT']._serialized_start=13366 + _globals['_LIMIT']._serialized_end=13400 + _globals['_RESERVATION']._serialized_start=13402 + _globals['_RESERVATION']._serialized_end=13448 + _globals['_SPAN']._serialized_start=13450 + _globals['_SPAN']._serialized_end=13506 + _globals['_ALLOCATION']._serialized_start=13509 + _globals['_ALLOCATION']._serialized_end=13799 + _globals['_SIZING']._serialized_start=13801 + _globals['_SIZING']._serialized_end=13889 + _globals['_MODULE']._serialized_start=13891 + _globals['_MODULE']._serialized_end=13967 + _globals['_GLOBAL']._serialized_start=13969 + _globals['_GLOBAL']._serialized_end=14071 + _globals['_FUNCTION']._serialized_start=14073 + _globals['_FUNCTION']._serialized_end=14194 + _globals['_FUNCTIONATTRIBUTE']._serialized_start=14196 + _globals['_FUNCTIONATTRIBUTE']._serialized_end=14242 + _globals['_REFERENCE']._serialized_start=14244 + _globals['_REFERENCE']._serialized_end=14291 + _globals['_RELOCATION']._serialized_start=14293 + _globals['_RELOCATION']._serialized_end=14408 + _globals['_BLOB']._serialized_start=14410 + _globals['_BLOB']._serialized_end=14478 + _globals['_ATTRIBUTE']._serialized_start=14480 + _globals['_ATTRIBUTE']._serialized_end=14539 + _globals['_KERNEL']._serialized_start=14542 + _globals['_KERNEL']._serialized_end=14699 + _globals['_MEMSET']._serialized_start=14702 + _globals['_MEMSET']._serialized_end=14840 + _globals['_COPY']._serialized_start=14842 + _globals['_COPY']._serialized_end=14953 + _globals['_EMPTY']._serialized_start=14955 + _globals['_EMPTY']._serialized_end=14962 + _globals['_EVENTWAIT']._serialized_start=14964 + _globals['_EVENTWAIT']._serialized_end=14990 + _globals['_NODE']._serialized_start=14993 + _globals['_NODE']._serialized_end=15218 + _globals['_EDGE']._serialized_start=15220 + _globals['_EDGE']._serialized_end=15277 + _globals['_EXECUTION']._serialized_start=15280 + _globals['_EXECUTION']._serialized_end=15593 + _globals['_PERSISTENTWORKER']._serialized_start=15596 + _globals['_PERSISTENTWORKER']._serialized_end=15765 + _globals['_TUNINGGRAPH']._serialized_start=15767 + _globals['_TUNINGGRAPH']._serialized_end=15834 + _globals['_BUFFER']._serialized_start=15837 + _globals['_BUFFER']._serialized_end=15967 + _globals['_EXECUTIONGRAPH']._serialized_start=15970 + _globals['_EXECUTIONGRAPH']._serialized_end=16503 + _globals['_INPUTBINDING']._serialized_start=16505 + _globals['_INPUTBINDING']._serialized_end=16577 # @@protoc_insertion_point(module_scope) diff --git a/tests/frontend/gemma4_images.json b/tests/frontend/gemma4_images.json new file mode 100644 index 000000000..7975e44d9 --- /dev/null +++ b/tests/frontend/gemma4_images.json @@ -0,0 +1,256 @@ +{ + "processor": { + "audio_ms_per_token": 40, + "audio_seq_length": 750, + "feature_extractor": { + "dither": 0.0, + "feature_extractor_type": "Gemma4AudioFeatureExtractor", + "feature_size": 128, + "fft_length": 512, + "fft_overdrive": false, + "frame_length": 320, + "hop_length": 160, + "input_scale_factor": 1.0, + "max_frequency": 8000.0, + "mel_floor": 0.001, + "min_frequency": 0.0, + "padding_side": "right", + "padding_value": 0.0, + "per_bin_mean": null, + "per_bin_stddev": null, + "preemphasis": 0.0, + "preemphasis_htk_flavor": true, + "return_attention_mask": true, + "sampling_rate": 16000 + }, + "image_processor": { + "do_convert_rgb": true, + "do_normalize": false, + "do_rescale": true, + "do_resize": true, + "image_mean": [ + 0.0, + 0.0, + 0.0 + ], + "image_processor_type": "Gemma4ImageProcessor", + "image_seq_length": 280, + "image_std": [ + 1.0, + 1.0, + 1.0 + ], + "max_soft_tokens": 280, + "patch_size": 16, + "pooling_kernel_size": 3, + "resample": 3, + "rescale_factor": 0.00392156862745098 + }, + "image_seq_length": 280, + "processor_class": "Gemma4Processor", + "video_processor": { + "do_convert_rgb": true, + "do_normalize": true, + "do_rescale": true, + "do_resize": true, + "do_sample_frames": true, + "image_mean": [ + 0.0, + 0.0, + 0.0 + ], + "image_std": [ + 1.0, + 1.0, + 1.0 + ], + "max_soft_tokens": 70, + "num_frames": 32, + "patch_size": 16, + "pooling_kernel_size": 3, + "resample": 3, + "rescale_factor": 0.00392156862745098, + "return_metadata": false, + "video_processor_type": "Gemma4VideoProcessor" + } + }, + "model": { + "vision_config": { + "_name_or_path": "", + "architectures": null, + "attention_bias": false, + "attention_dropout": 0.0, + "chunk_size_feed_forward": 0, + "default_output_length": 280, + "dtype": "bfloat16", + "global_head_dim": 72, + "head_dim": 72, + "hidden_activation": "gelu_pytorch_tanh", + "hidden_size": 1152, + "id2label": { + "0": "LABEL_0", + "1": "LABEL_1" + }, + "initializer_range": 0.02, + "intermediate_size": 4304, + "is_encoder_decoder": false, + "label2id": { + "LABEL_0": 0, + "LABEL_1": 1 + }, + "max_position_embeddings": 131072, + "model_type": "gemma4_vision", + "num_attention_heads": 16, + "num_hidden_layers": 27, + "num_key_value_heads": 16, + "output_attentions": false, + "output_hidden_states": false, + "patch_size": 16, + "pooling_kernel_size": 3, + "position_embedding_size": 10240, + "problem_type": null, + "return_dict": true, + "rms_norm_eps": 1e-06, + "rope_parameters": { + "rope_theta": 100.0, + "rope_type": "default" + }, + "standardize": true, + "use_clipped_linears": false + }, + "model_type": "gemma4", + "image_token_id": 258880, + "boi_token_id": 255999, + "eoi_token_id": 258882 + }, + "cases": [ + { + "width": 1, + "height": 1, + "seed": 0, + "max_soft_tokens": 280, + "grid": [ + 1, + 48, + 48 + ], + "tokens": 256, + "patches": 2304, + "pixels": "468a4a459772da4e498bc9635d3a9c9b12584490e1edcc1d914ee7df6448d8b2", + "positions": "4aad87bbd779207de57f944f92624525222e08c076b6c349f82cb6c98d0b3dcd", + "resized": "f0a0e8d753bbee26646b9cedd3cad510258b922274c4085b8da7d4f08e4cca3f" + }, + { + "width": 91, + "height": 37, + "seed": 1, + "max_soft_tokens": 280, + "grid": [ + 1, + 30, + 78 + ], + "tokens": 260, + "patches": 2340, + "pixels": "5265a89e1fce5478a650d56dfcc96127c30c21d2ea429b44c7af7d8a6682ac18", + "positions": "230fe091541f6e013b0d2a81d4db758517641e62625d183f5fe9413084933d38", + "resized": "74844bf7eb16d04ff85b2c4e7eb918db8d1aea0e2e302208008904b776dd3c31" + }, + { + "width": 672, + "height": 672, + "seed": 2, + "max_soft_tokens": 280, + "grid": [ + 1, + 48, + 48 + ], + "tokens": 256, + "patches": 2304, + "pixels": "66294430dcf7320533ade9aa9944cb1e7eefbf0ee969737041c51dc4474242e4", + "positions": "4aad87bbd779207de57f944f92624525222e08c076b6c349f82cb6c98d0b3dcd", + "resized": "993d71e2a28e4389e225eed5378b03ca1cb6c1056395c8a5b4b31754f594a81a" + }, + { + "width": 1008, + "height": 672, + "seed": 3, + "max_soft_tokens": 280, + "grid": [ + 1, + 39, + 60 + ], + "tokens": 260, + "patches": 2340, + "pixels": "c5c5fb7fe6d48bd9a3670d89832d4dadb51759666188ecbc3a7429c2bb43e3f9", + "positions": "ad2b173f5b91cabb2863a1d545039ab7e22bb7b45309657f92c7e53d079dfb50", + "resized": "33cbdc838936699ecaeff512700edf7f6049a87af183bb09f8db7d96f2320808" + }, + { + "width": 1920, + "height": 1080, + "seed": 4, + "max_soft_tokens": 280, + "grid": [ + 1, + 36, + 66 + ], + "tokens": 264, + "patches": 2376, + "pixels": "815b779d85aa29f4f7ddb74d47c0b8d73e656897be5d8a45ce74893cbbfd2338", + "positions": "e43d86caabf6609fe1ad0ef620caef5581ad7b5c6dbf69f3eb6d55fabf49d773", + "resized": "cd2ec808d9fb5ab009b7756729b0befc89c5ff6119ecfbafc25c9f0089907e21" + }, + { + "width": 10, + "height": 3000, + "seed": 5, + "max_soft_tokens": 280, + "grid": [ + 1, + 840, + 3 + ], + "tokens": 280, + "patches": 2520, + "pixels": "b17b383076944d67f62ccfd2dd998d80daa5be42f2b0ba6bda8f309ff7d21f7b", + "positions": "97d697bfd1f692c2e5393ed53d68c05abee541492e4bdc875526318c206ef557", + "resized": "0f17928e5360c931dc5c54bb1ebdd50afb7b126dab817e634c8358be87be1fbe" + }, + { + "width": 3000, + "height": 10, + "seed": 6, + "max_soft_tokens": 280, + "grid": [ + 1, + 3, + 840 + ], + "tokens": 280, + "patches": 2520, + "pixels": "16ef5cbab3d32dd200b95fbe680c28290c914ff65c26619cf7e22155f2118f45", + "positions": "2f51f7ce8893690da5ec517147c02d8367bdac99ccadbbe17d564d5a5d338683", + "resized": "e39f4eb95590e7ece96dbe9c5ce3d1388ecc7dffe40ac64bfc6bad1a04ae1548" + }, + { + "width": 1920, + "height": 1080, + "seed": 7, + "max_soft_tokens": 1120, + "grid": [ + 1, + 75, + 132 + ], + "tokens": 1100, + "patches": 9900, + "pixels": "4ff02c2491f5406ff26c77ad1115bceabc3c03152eb11f183ee5907a2ae016a0", + "positions": "76fbdbbe40e17eec69727f75e9de788f773ca33fd7fc83ad7b99c6c32fc79946", + "resized": "b411dbb8c91eba7b9db63355c7d63e74102800d8aafa70df989d39ff65ad2d2c" + } + ] +} diff --git a/tests/frontend/generate_gemma4_image_fixtures.py b/tests/frontend/generate_gemma4_image_fixtures.py new file mode 100644 index 000000000..09e91dabd --- /dev/null +++ b/tests/frontend/generate_gemma4_image_fixtures.py @@ -0,0 +1,94 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 Flare community contributors +# SPDX-License-Identifier: Apache-2.0 + +"""Generate Gemma 4 image preprocessing fixtures from the canonical processor.""" + +import argparse +import hashlib +import json +from pathlib import Path + +import numpy as np +import torch +import torchvision.transforms.functional as tvF +from transformers.models.gemma4.image_processing_gemma4 import Gemma4ImageProcessor + + +def pattern(width, height, seed): + # Vectorized channel ramps exercise bicubic interpolation and extreme aspect clamping. + y, x = np.indices((height, width)) + return np.stack(((x * 7 + seed * 31) % 256, (y * 11) % 256, (x + y * 3) % 256), -1).astype(np.uint8) + + +def digest(tensor): + return hashlib.sha256(tensor.contiguous().numpy().tobytes()).hexdigest() + + +def generate(snapshot, output): + raw = json.loads((snapshot / "processor_config.json").read_text()) + model = json.loads((snapshot / "config.json").read_text()) + cases = [] + specs = [ + (1, 1, 280), + (91, 37, 280), + (672, 672, 280), + (1008, 672, 280), + (1920, 1080, 280), + (10, 3000, 280), + (3000, 10, 280), + (1920, 1080, 1120), + ] + for seed, (width, height, max_soft_tokens) in enumerate(specs): + processor_kwargs = {**raw["image_processor"], "max_soft_tokens": max_soft_tokens} + processor = Gemma4ImageProcessor(**processor_kwargs) + pixels = pattern(width, height, seed) + chw = torch.from_numpy(pixels).permute(2, 0, 1).contiguous() + result = processor(images=[chw], return_tensors="pt") + positions = result["image_position_ids"][0] + valid = (positions >= 0).all(-1) + patches = int(valid.sum()) + valid_positions = positions[:patches] + assert bool(valid[:patches].all()) and not bool(valid[patches:].any()), ( + f"unexpected non-contiguous padding in {width}x{height}" + ) + grid_h = int(valid_positions[..., 1].max()) + 1 + grid_w = int(valid_positions[..., 0].max()) + 1 + pixel_values = result["pixel_values"][0, :patches] + assert pixel_values.dtype == torch.float32 + assert valid_positions.dtype == torch.int64 + resized = processor.aspect_ratio_preserving_resize( + chw, + patch_size=processor.patch_size, + max_patches=max_soft_tokens * processor.pooling_kernel_size * processor.pooling_kernel_size, + pooling_kernel_size=processor.pooling_kernel_size, + resample=tvF.InterpolationMode.BICUBIC, + ).permute(1, 2, 0) + assert resized.dtype == torch.uint8 + cases.append( + dict( + width=width, + height=height, + seed=seed, + max_soft_tokens=max_soft_tokens, + grid=[1, grid_h, grid_w], + tokens=int(result["num_soft_tokens_per_image"][0]), + patches=patches, + pixels=digest(pixel_values), + positions=digest(valid_positions), + resized=digest(resized), + ) + ) + profile = { + key: model[key] + for key in ("vision_config", "model_type", "image_token_id", "boi_token_id", "eoi_token_id") + if key in model + } + output.write_text(json.dumps(dict(processor=raw, model=profile, cases=cases), indent=2) + "\n") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("snapshot", type=Path) + parser.add_argument("output", type=Path) + args = parser.parse_args() + generate(args.snapshot, args.output) diff --git a/tests/preparation/test_frontend_gemma4.py b/tests/preparation/test_frontend_gemma4.py new file mode 100644 index 000000000..69c006d2a --- /dev/null +++ b/tests/preparation/test_frontend_gemma4.py @@ -0,0 +1,257 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 Flare community contributors +# SPDX-License-Identifier: Apache-2.0 + +"""Validate Gemma 4 frontend image-profile extraction and negative gates.""" + +import copy +import json +import os +from pathlib import Path + +import pytest +from tokenizers import Tokenizer, models, pre_tokenizers + +from ignition.preparation.frontend import image_settings, prepare_frontend + + +def _write_synthetic_snapshot( + root: Path, + *, + processor=None, + model=None, + tokenizer_config=None, + vocab=None, +): + root.mkdir(parents=True, exist_ok=True) + vocab = vocab or { + "": 0, + "extra": 1, + "<|image|> extra": 2, + "<|image>": 255999, + "<|image|>": 258880, + "": 258882, + } + tokenizer = Tokenizer(models.WordLevel(vocab=vocab, unk_token="")) + tokenizer.pre_tokenizer = pre_tokenizers.WhitespaceSplit() + tokenizer.save(str(root / "tokenizer.json")) + + processor = processor or { + "processor_class": "Gemma4Processor", + "image_processor": { + "image_processor_type": "Gemma4ImageProcessor", + "patch_size": 16, + "pooling_kernel_size": 3, + "max_soft_tokens": 280, + "do_resize": True, + "do_rescale": True, + "do_normalize": False, + "do_convert_rgb": True, + "resample": 3, + "rescale_factor": 1 / 255, + "image_mean": [0.0, 0.0, 0.0], + "image_std": [1.0, 1.0, 1.0], + }, + } + model = model or { + "model_type": "gemma4", + "image_token_id": 258880, + "boi_token_id": 255999, + "eoi_token_id": 258882, + "vision_config": { + "model_type": "gemma4_vision", + "patch_size": 16, + "pooling_kernel_size": 3, + "num_hidden_layers": 16, + "hidden_size": 768, + "num_attention_heads": 12, + "head_dim": 64, + "intermediate_size": 3072, + }, + } + tokenizer_config = tokenizer_config or { + "image_token": "<|image|>", + "boi_token": "<|image>", + "eoi_token": "", + } + (root / "processor_config.json").write_text(json.dumps(processor)) + (root / "config.json").write_text(json.dumps(model)) + (root / "tokenizer_config.json").write_text(json.dumps(tokenizer_config)) + return processor, model, tokenizer_config + + +def test_prepare_frontend_accepts_e2b_sized_gemma4_tower(tmp_path): + _write_synthetic_snapshot(tmp_path) + prepared = prepare_frontend( + tmp_path, + eos_token_ids=[1], + image_profile="gemma4", + preprocessor=tmp_path / "processor_config.json", + ) + assert prepared["image"] == { + "gemma4": { + "patch_size": 16, + "pooling_kernel_size": 3, + "max_soft_tokens": 280, + "image_token": "<|image|>", + "start_token": "<|image>", + "end_token": "", + } + } + + +def test_image_settings_accepts_object_tokens_and_omitted_model_ids(tmp_path): + processor, model, tokenizer_config = _write_synthetic_snapshot( + tmp_path, + tokenizer_config={ + "image_token": {"content": "<|image|>"}, + "boi_token": {"content": "<|image>"}, + "eoi_token": {"content": ""}, + }, + ) + model_without_ids = { + k: v for k, v in model.items() if k not in ("image_token_id", "boi_token_id", "eoi_token_id") + } + resolved = image_settings( + processor, + model_without_ids, + "gemma4", + tokenizer_config=tokenizer_config, + snapshot=tmp_path, + ) + assert resolved["gemma4"]["image_token"] == "<|image|>" + assert resolved["gemma4"]["start_token"] == "<|image>" + assert resolved["gemma4"]["end_token"] == "" + + +def test_image_settings_rejects_gemma4_unified_and_bad_geometry(tmp_path): + processor, model, tokenizer_config = _write_synthetic_snapshot(tmp_path) + + # Gemma 4 12B uses gemma4_unified / Gemma4UnifiedImageProcessor, which must be rejected. + unified_model = copy.deepcopy(model) + unified_model["model_type"] = "gemma4_unified" + with pytest.raises(ValueError, match="model_type"): + image_settings(processor, unified_model, "gemma4", tokenizer_config=tokenizer_config, snapshot=tmp_path) + + unified_vision = copy.deepcopy(model) + unified_vision["vision_config"]["model_type"] = "gemma4_unified_vision" + with pytest.raises(ValueError, match="model_type"): + image_settings(processor, unified_vision, "gemma4", tokenizer_config=tokenizer_config, snapshot=tmp_path) + + unified_proc = copy.deepcopy(processor) + unified_proc["image_processor"]["image_processor_type"] = "Gemma4UnifiedImageProcessor" + with pytest.raises(ValueError, match="image_processor_type"): + image_settings(unified_proc, model, "gemma4", tokenizer_config=tokenizer_config, snapshot=tmp_path) + + # Non-dict guards and bad numeric geometry / bool guards. + with pytest.raises(ValueError): + image_settings({"processor_class": "Gemma4Processor", "image_processor": None}, model, "gemma4") + with pytest.raises(ValueError): + image_settings(processor, {**model, "vision_config": None}, "gemma4") + for field, bad_value in (("patch_size", 14), ("pooling_kernel_size", 2), ("max_soft_tokens", 300), ("max_soft_tokens", True)): + bad_proc = copy.deepcopy(processor) + bad_proc["image_processor"][field] = bad_value + with pytest.raises(ValueError): + image_settings(bad_proc, model, "gemma4", tokenizer_config=tokenizer_config, snapshot=tmp_path) + + +def test_image_settings_fails_closed_without_tokenizer_or_bad_envelope_tokens(tmp_path): + processor, model, tokenizer_config = _write_synthetic_snapshot(tmp_path) + + # Failing closed when tokenizer_config or snapshot is omitted. + with pytest.raises(ValueError, match="tokenizer_config and snapshot"): + image_settings(processor, model, "gemma4") + with pytest.raises(ValueError, match="tokenizer_config and snapshot"): + image_settings(processor, model, "gemma4", tokenizer_config=tokenizer_config) + + # Missing, empty, and duplicate envelope tokens. + with pytest.raises(ValueError, match="boi_token"): + image_settings(processor, model, "gemma4", tokenizer_config={"image_token": "<|image|>", "eoi_token": ""}, snapshot=tmp_path) + with pytest.raises(ValueError, match="empty"): + image_settings(processor, model, "gemma4", tokenizer_config={**tokenizer_config, "eoi_token": ""}, snapshot=tmp_path) + with pytest.raises(ValueError, match="distinct"): + image_settings(processor, model, "gemma4", tokenizer_config={**tokenizer_config, "eoi_token": "<|image>"}, snapshot=tmp_path) + + # Unknown token and multi-token string (Whitespace pre-tokenizer splits "<|image|> extra" into 2 tokens). + with pytest.raises(ValueError, match="single vocabulary token"): + image_settings(processor, model, "gemma4", tokenizer_config={**tokenizer_config, "image_token": ""}, snapshot=tmp_path) + with pytest.raises(ValueError, match="single vocabulary token"): + image_settings(processor, model, "gemma4", tokenizer_config={**tokenizer_config, "image_token": "<|image|> extra"}, snapshot=tmp_path) + + # Mismatched or bool config.json token IDs. + with pytest.raises(ValueError, match="image_token_id"): + image_settings(processor, {**model, "image_token_id": 999}, "gemma4", tokenizer_config=tokenizer_config, snapshot=tmp_path) + with pytest.raises(ValueError, match="boi_token_id"): + image_settings(processor, {**model, "boi_token_id": True}, "gemma4", tokenizer_config=tokenizer_config, snapshot=tmp_path) + + +def test_checked_in_gemma4_fixture_provenance_matches_image_settings(tmp_path): + fixture_path = Path(__file__).resolve().parents[1] / "frontend" / "gemma4_images.json" + fixture = json.loads(fixture_path.read_text()) + model = fixture["model"] + vocab = { + "": 0, + "<|image|>": model["image_token_id"], + "<|image>": model["boi_token_id"], + "": model["eoi_token_id"], + } + tokenizer_config = { + "image_token": "<|image|>", + "boi_token": "<|image>", + "eoi_token": "", + } + _write_synthetic_snapshot( + tmp_path, + processor=fixture["processor"], + model=model, + tokenizer_config=tokenizer_config, + vocab=vocab, + ) + resolved = image_settings( + fixture["processor"], + model, + "gemma4", + tokenizer_config=tokenizer_config, + snapshot=tmp_path, + ) + assert resolved == { + "gemma4": { + "patch_size": 16, + "pooling_kernel_size": 3, + "max_soft_tokens": 280, + "image_token": "<|image|>", + "start_token": "<|image>", + "end_token": "", + } + } + + +@pytest.mark.parametrize( + ("repository", "revision"), + [ + ("google/gemma-4-31B-it", "842da3794eaa0b77d5f08bae87a17459d91ff475"), + ("nvidia/Gemma-4-31B-IT-NVFP4", "4135a98a9b728a548947683219633b25682223ac"), + ("google/gemma-4-E2B-it", "3e22461f65e89153144f8adb70e3b8c2cc9845a7"), + ], +) +def test_cached_gemma4_checkpoints_prepare_image_settings(repository, revision): + hub = Path(os.environ.get("HF_HOME", Path.home() / ".cache/huggingface")) / "hub" + snapshot = hub / ("models--" + repository.replace("/", "--")) / "snapshots" / revision + for name in ("config.json", "processor_config.json", "tokenizer.json", "tokenizer_config.json"): + if not (snapshot / name).is_file(): + pytest.skip(f"{repository}@{revision} {name} is not cached under {hub}") + prepared = prepare_frontend( + snapshot, + eos_token_ids=[1], + image_profile="gemma4", + preprocessor=snapshot / "processor_config.json", + ) + assert prepared["image"] == { + "gemma4": { + "patch_size": 16, + "pooling_kernel_size": 3, + "max_soft_tokens": 280, + "image_token": "<|image|>", + "start_token": "<|image>", + "end_token": "", + } + }