diff --git a/docs/cli-design.md b/docs/cli-design.md index 3a2bc1648..945f445c8 100644 --- a/docs/cli-design.md +++ b/docs/cli-design.md @@ -808,11 +808,14 @@ memory budget. The cache remains fixed in size while serving and warms from requests each time the server starts. `--embedding-table-resident-scales` loads the original scale plane into immutable -host RAM before KV sizing. Disk-backed tables enable this by default unless any -selected GPU shares host memory, as on DGX Spark. Explicit enable and disable -flags override the hardware default on each host. RAM table storage and cores -without embedding tables do not enable it automatically. It applies to every -table in the core's embedding catalog, including Qwen PLE and DeepSeek Engram. The loader uses the declared +host RAM before KV sizing. Disk-backed tables carrying scales enable this by +default unless any selected GPU shares host memory, as on DGX Spark. Explicit +enable and disable flags override the hardware default on each host; explicitly +enabling it fails loading when the core has no embedding tables or when no table +in the catalog carries a scale plane (such as single-plane `BF16` tables). RAM +table storage, cores without embedding tables, and single-plane tables do not +enable it automatically. It applies to every table with a scale plane in the +core's embedding catalog, including Qwen PLE and DeepSeek Engram. The loader uses the declared weight and scale row sizes; it does not select behavior by model identity. Weight rows remain on disk, and a row-cache miss reads only the weight plane. The resident scale allocation is additional to diff --git a/docs/core-format-design.md b/docs/core-format-design.md index 1c41a17ab..06dcfc1b1 100644 --- a/docs/core-format-design.md +++ b/docs/core-format-design.md @@ -89,9 +89,10 @@ Tuning-dependent layouts occupy separate payloads. TP-specific files exist only for byte-distinct layouts required by selected deployments. Offloaded DeepSeek Engram and Qwen PLE tables are stored separately from ordinary -weight groups. Each full table uses `weights/engram--weights.safetensors` +weight groups. Each full two-plane table uses `weights/engram--weights.safetensors` and `weights/engram--scales.safetensors`, with checkpoint row ordering -independent of TP size. Every host receives the full table; local ranks share +independent of TP size; single-plane encodings such as `BF16` omit the `-scales` +file. Every host receives the full table; local ranks share its reader and row cache. Disk backing requires only bounded staging and row cache memory. DeepSeek's projection and reduction are TP-sharded, while its graph requests use canonical full-table row IDs on every rank. A core @@ -99,7 +100,7 @@ whose tables record partition-local rows executes with that recorded layout. A table recorded with rank-owned row partitions (`EngramTable.shards`) stores each partition's planes as `deployments//engram--shard--weights.safetensors` -and the matching `-scales` file. +and, for two-plane encodings, the matching `-scales` file. Hardware names in deployment IDs and cache-entry names use device identifiers such as `gb202` and `gb10`, producing names such as `gb202-tp1` and `gb10-tp2`. diff --git a/docs/model-preparation.md b/docs/model-preparation.md index 04f79be01..c7ac17a4f 100644 --- a/docs/model-preparation.md +++ b/docs/model-preparation.md @@ -481,8 +481,9 @@ check. GPU weights, KV, registered host buffers, resident embedding tables, compiler workers, and the OS compete for that memory. Set `[memory] reserve` for host activity as well as driver headroom; `reserve = "4G"` leaves four GiB outside the model's cache budget. RAM embedding tables load before cache -sizing. Disk embedding tables use bounded staging and can retain their scale -planes in RAM with `--embedding-table-resident-scales`. The loader accounts for +sizing. Disk embedding tables use bounded staging and, for tables carrying a +scale plane, can retain their scale planes in RAM with +`--embedding-table-resident-scales`. The loader accounts for resident scales and the optional row cache before sizing KV, for both PLE and Engram cores. Disk tables default to a 1 GiB host-RAM row cache per Spark; `--embedding-table-cache-size` overrides it, and `0` disables it. diff --git a/heliopause/src/embedding_tables.rs b/heliopause/src/embedding_tables.rs index 01d2f62f2..d36777ef7 100644 --- a/heliopause/src/embedding_tables.rs +++ b/heliopause/src/embedding_tables.rs @@ -10,8 +10,8 @@ use crate::engram::Binding; #[cfg(unix)] use crate::engram::{PlaneSource, PreparedTables, SourceSegment, TableSource}; #[cfg(unix)] -use pyo3::exceptions::{PyRuntimeError, PyValueError}; -use pyo3::{exceptions::PyKeyError, prelude::*}; +use pyo3::exceptions::{PyKeyError, PyRuntimeError, PyValueError}; +use pyo3::prelude::*; #[cfg(unix)] use std::{collections::HashMap, path::PathBuf}; @@ -38,16 +38,33 @@ fn sources(value: &Bound<'_, PyAny>) -> PyResult<(usize, Vec)> { row_bytes: plane.get_item("row_bytes")?.extract()?, }); } - if planes.len() != 2 { + if planes.is_empty() || planes.len() > 2 { return Err(PyValueError::new_err( - "embedding table requires weight and scale planes", + "embedding table requires weight plane and optional scale plane", )); } + let weights_plane = planes.remove(0); + let scales_plane = (!planes.is_empty()).then(|| planes.remove(0)); + let scales_name: Option = match table.get_item("scales") { + Ok(item) if item.is_none() => None, + Ok(item) => Some(item.extract()?), + Err(error) if error.is_instance_of::(table.py()) => None, + Err(error) => return Err(error), + }; + let scales = match (scales_plane, scales_name) { + (Some(plane), Some(name)) => Some((plane, name)), + (None, None) => None, + _ => { + return Err(PyValueError::new_err( + "embedding table scale plane and scale buffer binding must both be present or both absent", + )); + } + }; tables.push(TableSource { - planes: [planes.remove(0), planes.remove(0)], + weights_plane, heads: table.get_item("heads")?.extract()?, weights: table.get_item("weights")?.extract()?, - scales: table.get_item("scales")?.extract()?, + scales, hashes: table.get_item("hashes")?.extract()?, event: table.get_item("event")?.extract()?, request: table.get_item("request")?.extract()?, diff --git a/heliopause/src/export/binding.rs b/heliopause/src/export/binding.rs index 8c30aae9c..c759973f7 100644 --- a/heliopause/src/export/binding.rs +++ b/heliopause/src/export/binding.rs @@ -886,6 +886,9 @@ fn append_planes( ) -> super::Result<()> { for name in ["weights", "scales"] { if let Some(parts) = value.get_mut(name) { + if parts.is_null() { + continue; + } let sources: Vec = serde_json::from_value(parts.clone())?; *cursor = align(*cursor)?; let start = *cursor; diff --git a/heliopause/src/export/core.rs b/heliopause/src/export/core.rs index bc2aa7f61..b0e2f5379 100644 --- a/heliopause/src/export/core.rs +++ b/heliopause/src/export/core.rs @@ -96,17 +96,18 @@ pub(crate) fn roles(index: &wire::ModelIndex) -> Result> { if let Some(engram) = &index.engram { for table in &engram.tables { if table.shards.is_empty() { - for scales in [false, true] { - result.push(Role { - kind: 4, - owner: None, - span: if scales { - table.scales.clone() - } else { - table.weights.clone() - } + result.push(Role { + kind: 4, + owner: None, + span: table + .weights + .clone() .ok_or_else(|| invalid("embedding table lacks payload plane"))?, - }); + }); + if let Some(scales) = + helios_core::core::schema::engram_scales(table.encoding, &table.scales)? + { + result.push(Role { kind: 4, owner: None, span: scales.clone() }); } } else { if table.weights.is_some() || table.scales.is_some() { @@ -118,16 +119,21 @@ pub(crate) fn roles(index: &wire::ModelIndex) -> Result> { if shard.rank as usize >= index.ranks.len() { return Err(invalid("embedding partition owner outside core ranks")); } - for scales in [false, true] { + result.push(Role { + kind: 4, + owner: Some(shard.rank as usize), + span: shard + .weights + .clone() + .ok_or_else(|| invalid("embedding partition lacks payload plane"))?, + }); + if let Some(scales) = + helios_core::core::schema::engram_scales(table.encoding, &shard.scales)? + { result.push(Role { kind: 4, owner: Some(shard.rank as usize), - span: if scales { - shard.scales.clone() - } else { - shard.weights.clone() - } - .ok_or_else(|| invalid("embedding partition lacks payload plane"))?, + span: scales.clone(), }); } } @@ -407,8 +413,14 @@ pub(crate) fn validate_ranks( if let Some(engram) = &source.index.engram { for table in &engram.tables { if table.shards.is_empty() { - for span in [&table.weights, &table.scales] { - locate(&source.payload, span.as_ref().unwrap_or(&wire::Span::default()))?; + locate( + &source.payload, + table.weights.as_ref().unwrap_or(&wire::Span::default()), + )?; + if let Some(scales) = + helios_core::core::schema::engram_scales(table.encoding, &table.scales)? + { + locate(&source.payload, scales)?; } } else { if table.weights.is_some() || table.scales.is_some() { @@ -417,8 +429,15 @@ pub(crate) fn validate_ranks( )); } for shard in &table.shards { - for span in [&shard.weights, &shard.scales] { - locate(&source.payload, span.as_ref().unwrap_or(&wire::Span::default()))?; + locate( + &source.payload, + shard.weights.as_ref().unwrap_or(&wire::Span::default()), + )?; + if let Some(scales) = helios_core::core::schema::engram_scales( + table.encoding, + &shard.scales, + )? { + locate(&source.payload, scales)?; } } } @@ -1501,8 +1520,11 @@ fn core_engram( } enum TablePlan { - Shared { weights_idx: usize, scales_idx: usize }, - Partitioned(Vec<(u32, u64, u64, usize, usize)>), + Shared { + weights_idx: usize, + scales_idx: Option, + }, + Partitioned(Vec<(u32, u64, u64, usize, Option)>), } let mut jobs = Vec::new(); @@ -1513,22 +1535,22 @@ fn core_engram( .weights .as_ref() .ok_or_else(|| invalid("engram table lacks weights"))?; - let scales_span = table - .scales - .as_ref() - .ok_or_else(|| invalid("engram table lacks scales"))?; let weights_idx = jobs.len(); jobs.push(PlaneJob { span: weights_span, staging_name: format!("engram-{index}-w.payload"), relative: format!("weights/engram-{index}-weights.safetensors"), }); - let scales_idx = jobs.len(); - jobs.push(PlaneJob { - span: scales_span, - staging_name: format!("engram-{index}-s.payload"), - relative: format!("weights/engram-{index}-scales.safetensors"), - }); + let scales_idx = helios_core::core::schema::engram_scales(table.encoding, &table.scales)? + .map(|scales_span| { + let idx = jobs.len(); + jobs.push(PlaneJob { + span: scales_span, + staging_name: format!("engram-{index}-s.payload"), + relative: format!("weights/engram-{index}-scales.safetensors"), + }); + idx + }); plans.push(TablePlan::Shared { weights_idx, scales_idx, @@ -1552,10 +1574,6 @@ fn core_engram( .weights .as_ref() .ok_or_else(|| invalid("engram shard lacks weights"))?; - let scales_span = shard - .scales - .as_ref() - .ok_or_else(|| invalid("engram shard lacks scales"))?; let weights_idx = jobs.len(); jobs.push(PlaneJob { span: weights_span, @@ -1564,14 +1582,20 @@ fn core_engram( "deployments/{deployment}/engram-{index}-shard-{position}-weights.safetensors" ), }); - let scales_idx = jobs.len(); - jobs.push(PlaneJob { - span: scales_span, - staging_name: format!("engram-{index}-shard-{position}-s.payload"), - relative: format!( - "deployments/{deployment}/engram-{index}-shard-{position}-scales.safetensors" - ), - }); + let scales_idx = + helios_core::core::schema::engram_scales(table.encoding, &shard.scales)?.map( + |scales_span| { + let idx = jobs.len(); + jobs.push(PlaneJob { + span: scales_span, + staging_name: format!("engram-{index}-shard-{position}-s.payload"), + relative: format!( + "deployments/{deployment}/engram-{index}-shard-{position}-scales.safetensors" + ), + }); + idx + }, + ); shard_plans.push(( shard.rank, shard.first_row, @@ -1645,24 +1669,26 @@ fn core_engram( scales_idx, } => { let ((w_id, w_len, _), _) = &resolved[weights_idx]; - let ((s_id, s_len, _), _) = &resolved[scales_idx]; - ( - Some(use_of(w_id, *w_len)), - Some(use_of(s_id, *s_len)), - Vec::new(), - ) + let scales = scales_idx.map(|idx| { + let ((s_id, s_len, _), _) = &resolved[idx]; + use_of(s_id, *s_len) + }); + (Some(use_of(w_id, *w_len)), scales, Vec::new()) } TablePlan::Partitioned(shard_plans) => { let mut shards = Vec::with_capacity(shard_plans.len()); for (rank, first_row, rows, weights_idx, scales_idx) in shard_plans { let ((w_id, w_len, _), _) = &resolved[weights_idx]; - let ((s_id, s_len, _), _) = &resolved[scales_idx]; + let scales = scales_idx.map(|idx| { + let ((s_id, s_len, _), _) = &resolved[idx]; + use_of(s_id, *s_len) + }); shards.push(pwire::EngramTableShard { rank, first_row, rows, weights: Some(use_of(w_id, *w_len)), - scales: Some(use_of(s_id, *s_len)), + scales, }); } (None, None, shards) @@ -3066,6 +3092,24 @@ mod payload_export_tests { .unwrap() } + fn verify_published(metadata: &Metadata, signer: &protection::Publisher) -> Result<()> { + let key = helios_core::runtime_core::Publisher { + name: signer.namespace.clone(), + namespace: signer.namespace.clone(), + public_key: signer.public_key().try_into().unwrap(), + development: false, + }; + let verified = helios_core::core::protection::verify_with_bodies( + &metadata.envelope, + Some(metadata.body_store()), + std::slice::from_ref(&key), + helios_core::core::protection::Selection::Deployment { deployment: 0, rank: None }, + )?; + let ids = helios_core::core::reader::required_payloads(&verified)?; + metadata.payloads(verified.catalog(), ids.iter().map(Vec::as_slice))?.verify()?; + Ok(()) + } + fn manifest_ids(root: &Path) -> (Vec, Vec) { let metadata = Metadata::open(root).unwrap(); let envelope = helios_core::core::protection::envelope(&metadata.envelope).unwrap(); @@ -3843,7 +3887,7 @@ mod payload_export_tests { fn reuse_engram_hardlinks_shared_and_partitioned_embedding_planes() -> Result<()> { use crate::export::{CaptureRequest, WeightPayloadGroup, WeightPayloadSources}; use helios_core::core::cache::Root; - for partitioned in [false, true] { + for (partitioned, bf16) in [(false, false), (true, false), (false, true), (true, true)] { let directory = tempfile::tempdir()?; let stages = directory.path().join("stages"); fs::create_dir_all(&stages)?; @@ -3861,28 +3905,54 @@ mod payload_export_tests { ..Default::default() }); } - let mut table = wire::EngramTable { - layer: 1, - rows: world as u64, - embedding_width: 160, - scale_block: 16, - hash: Some(wire::EngramHash { - method: wire::engram_hash::Method::EosXorModulo as i32, + let mut table = if bf16 { + wire::EngramTable { + layer: 0, + rows: world as u64, + embedding_width: 8, + scale_block: 0, + hash: Some(wire::EngramHash { + method: wire::engram_hash::Method::Identity as i32, + ..Default::default() + }), + weight_buffer: "weights".into(), + scale_buffer: String::new(), + hash_buffer: "hashes".into(), + request_buffer: "requests".into(), + ready_event: "ready".into(), + encoding: wire::engram_table::Encoding::Bf16 as i32, + global_scale: 0.0, ..Default::default() - }), - weight_buffer: "weights".into(), - scale_buffer: "scales".into(), - hash_buffer: "hashes".into(), - request_buffer: "requests".into(), - ready_event: "ready".into(), - encoding: wire::engram_table::Encoding::Nvfp4E4m3Global as i32, - global_scale: 1.0, - ..Default::default() + } + } else { + wire::EngramTable { + layer: 1, + rows: world as u64, + embedding_width: 160, + scale_block: 16, + hash: Some(wire::EngramHash { + method: wire::engram_hash::Method::EosXorModulo as i32, + ..Default::default() + }), + weight_buffer: "weights".into(), + scale_buffer: "scales".into(), + hash_buffer: "hashes".into(), + request_buffer: "requests".into(), + ready_event: "ready".into(), + encoding: wire::engram_table::Encoding::Nvfp4E4m3Global as i32, + global_scale: 1.0, + ..Default::default() + } + }; + let plane_specs: &[(&str, usize)] = if bf16 { + &[("weights", 16)] + } else { + &[("weights", 80), ("scales", 10)] }; let mut cursor = 12288; for shard in 0..world { let mut planes = Vec::new(); - for (plane, length) in [("weights", 80), ("scales", 10)] { + for &(plane, length) in plane_specs { let path = stages.join(format!("engram-{shard}-{plane}.bin")); fs::write(&path, vec![shard as u8 + 1; length])?; rank.payload.push(FilePart { @@ -3906,17 +3976,17 @@ mod payload_export_tests { first_row: u64::from(shard), rows: 1, weights: Some(planes[0].clone()), - scales: Some(planes[1].clone()), + scales: planes.get(1).cloned(), }); } else { table.weights = Some(planes[0].clone()); - table.scales = Some(planes[1].clone()); + table.scales = planes.get(1).cloned(); } } rank.index.engram = Some(wire::Engram { token_map: vec![], - pad_token_id: 1, - compressed_vocabulary: 100, + pad_token_id: if bf16 { 0 } else { 1 }, + compressed_vocabulary: if bf16 { world } else { 100 }, tables: vec![table], }); let mut ranks = vec![rank.clone()]; @@ -3950,7 +4020,7 @@ mod payload_export_tests { let mut data = serde_json::to_value(rank.index.engram.as_ref().unwrap())?; data["tables"][0]["weight_buffer"] = "rebound_weights".into(); let set_planes = |value: &mut serde_json::Value| { - for (plane, nbytes) in [("weights", 80), ("scales", 10)] { + for &(plane, nbytes) in plane_specs { value[plane] = serde_json::json!([{"path":stages.join("absent-checkpoint"),"offset":0,"nbytes":nbytes}]); } }; @@ -3968,6 +4038,10 @@ mod payload_export_tests { .unwrap() .engram(&request, &rank, &data)?; assert_eq!(reused.tables[0].weight_buffer, "rebound_weights"); + if bf16 { + assert!(reused.tables[0].scales.is_none()); + assert!(reused.tables[0].shards.iter().all(|s| s.scales.is_none())); + } rank.index.engram = None; for part in rank.payload.drain(3..) { fs::remove_file(part.source.path)?; @@ -4012,6 +4086,7 @@ mod payload_export_tests { )?; let first_meta = Metadata::open(first_entry.directory())?; let second_meta = Metadata::open(second_entry.directory())?; + verify_published(&second_meta, &signer)?; for source in super::super::weight_reuse::engram_uses(&reused) { let id = &source.slice.as_ref().unwrap().payload_id; let locate = |metadata: &Metadata| { @@ -4312,6 +4387,9 @@ mod payload_export_tests { let shard0_scales = vec![0x44; 8]; let shard1_weights = vec![0x55; 256]; let shard1_scales = vec![0x66; 8]; + let bf16_shared_weights = vec![0x77; 32]; + let bf16_shard0_weights = vec![0x88; 16]; + let bf16_shard1_weights = vec![0x99; 16]; for (name, bytes) in [ ("shared-w.bin", &shared_weights), ("shared-s.bin", &shared_scales), @@ -4319,6 +4397,9 @@ mod payload_export_tests { ("shard0-s.bin", &shard0_scales), ("shard1-w.bin", &shard1_weights), ("shard1-s.bin", &shard1_scales), + ("bf16-shared-w.bin", &bf16_shared_weights), + ("bf16-shard0-w.bin", &bf16_shard0_weights), + ("bf16-shard1-w.bin", &bf16_shard1_weights), ] { fs::write(sources.join(name), bytes).unwrap(); } @@ -4415,6 +4496,41 @@ mod payload_export_tests { }, ], }, + wire::EngramTable { + layer: 3, + rows: 2, + embedding_width: 8, + weights: Some(wire::Span { offset: 13000, nbytes: bf16_shared_weights.len() as u64, ..Default::default() }), + hash: Some(wire::EngramHash { method: wire::engram_hash::Method::XorModulo as i32, ..Default::default() }), + weight_buffer: "bf16_shared_weights".into(), + hash_buffer: "bf16_shared_hashes".into(), + ready_event: "bf16_shared_ready".into(), + encoding: wire::engram_table::Encoding::Bf16 as i32, + request_buffer: "bf16_shared_requests".into(), + ..Default::default() + }, + wire::EngramTable { + layer: 4, + rows: 2, + embedding_width: 8, + hash: Some(wire::EngramHash { method: wire::engram_hash::Method::XorModulo as i32, ..Default::default() }), + weight_buffer: "bf16_part_weights".into(), + hash_buffer: "bf16_part_hashes".into(), + ready_event: "bf16_part_ready".into(), + encoding: wire::engram_table::Encoding::Bf16 as i32, + request_buffer: "bf16_part_requests".into(), + shards: vec![ + wire::EngramTableShard { + rank: 0, first_row: 0, rows: 1, scales: None, + weights: Some(wire::Span { offset: 13032, nbytes: bf16_shard0_weights.len() as u64, ..Default::default() }), + }, + wire::EngramTableShard { + rank: 1, first_row: 1, rows: 1, scales: None, + weights: Some(wire::Span { offset: 13048, nbytes: bf16_shard1_weights.len() as u64, ..Default::default() }), + }, + ], + ..Default::default() + }, ], }); for (offset, name, nbytes) in [ @@ -4424,6 +4540,9 @@ mod payload_export_tests { (12704, "shard0-s.bin", shard0_scales.len()), (12712, "shard1-w.bin", shard1_weights.len()), (12968, "shard1-s.bin", shard1_scales.len()), + (13000, "bf16-shared-w.bin", bf16_shared_weights.len()), + (13032, "bf16-shard0-w.bin", bf16_shard0_weights.len()), + (13048, "bf16-shard1-w.bin", bf16_shard1_weights.len()), ] { rank.payload.push(FilePart { offset, @@ -4448,32 +4567,34 @@ mod payload_export_tests { &mut leases, ) .unwrap(); - assert_eq!(installed.len(), 6); + assert_eq!(installed.len(), 9); assert_eq!(fs::read_dir(&assembly).unwrap().count(), 0); for payload in &installed { assert_eq!(payload.source.digest().unwrap(), payload.id); } + for bad_idx in [2usize, 3usize] { + let mut bad_engram = rank.index.engram.clone().unwrap(); + if bad_idx == 2 { + bad_engram.tables[2].scales = bad_engram.tables[2].weights.clone(); + } else { + bad_engram.tables[3].shards[0].scales = + bad_engram.tables[3].shards[0].weights.clone(); + } + assert!(core_engram(&bad_engram, &rank.payload, &assembly, "gb202-tp2-bad", &mut Vec::new(), None, &mut BTreeMap::new()).is_err()); + } let output = base.join("core"); let mut second = rank.clone(); second.index.engram = None; - publish_payload( - &output, - &[rank, second], - vec![], - None, - &publisher(), - None, - false, - "directory", - ) - .unwrap(); + let signer = publisher(); + publish_payload(&output, &[rank, second], vec![], None, &signer, None, false, "directory").unwrap(); let metadata = Metadata::open(&output).unwrap(); + verify_published(&metadata, &signer).unwrap(); let envelope = helios_core::core::protection::envelope(&metadata.envelope).unwrap(); let deployment = pwire::DeploymentBody::decode(envelope.deployments[0].body.as_slice()) .unwrap(); let engram = deployment.engram.unwrap(); - assert_eq!(engram.tables.len(), 2); + assert_eq!(engram.tables.len(), 4); let shared = &engram.tables[0]; assert!(shared.weights.is_some() && shared.scales.is_some()); assert!(shared.shards.is_empty()); @@ -4488,6 +4609,13 @@ mod payload_export_tests { .collect::>(), vec![(0, 0, 1), (1, 1, 1)] ); + let bf16_shared = &engram.tables[2]; + assert!(bf16_shared.weights.is_some() && bf16_shared.scales.is_none()); + assert!(bf16_shared.shards.is_empty()); + let bf16_part = &engram.tables[3]; + assert!(bf16_part.weights.is_none() && bf16_part.scales.is_none()); + assert_eq!(bf16_part.shards.len(), 2); + assert!(bf16_part.shards.iter().all(|s| s.scales.is_none())); let read_use = |use_: &pwire::PayloadUse| -> Vec { assert_eq!(use_.role, pwire::PayloadRole::Weights as i32); @@ -4537,6 +4665,18 @@ mod payload_export_tests { read_use(partitioned.shards[1].scales.as_ref().unwrap()), shard1_scales ); + assert_eq!( + read_use(bf16_shared.weights.as_ref().unwrap()), + bf16_shared_weights + ); + assert_eq!( + read_use(bf16_part.shards[0].weights.as_ref().unwrap()), + bf16_shard0_weights + ); + assert_eq!( + read_use(bf16_part.shards[1].weights.as_ref().unwrap()), + bf16_shard1_weights + ); let _ = fs::remove_dir_all(&base); } @@ -4585,8 +4725,10 @@ mod payload_export_tests { let cached_shared_scales = b"shared-scale-bytes"; let cached_dup_scales = b"duplicate-shard-scales!!"; + let cached_bf16_shard = b"cached-bf16-row!"; let shared_scales_id = PayloadId::of(cached_shared_scales); let dup_scales_id = PayloadId::of(cached_dup_scales); + let bf16_shard_id = PayloadId::of(cached_bf16_shard); root.insert_payload( shared_scales_id, cached_shared_scales.len() as u64, @@ -4599,6 +4741,12 @@ mod payload_export_tests { std::io::Cursor::new(cached_dup_scales), ) .unwrap(); + root.insert_payload( + bf16_shard_id, + cached_bf16_shard.len() as u64, + std::io::Cursor::new(cached_bf16_shard), + ) + .unwrap(); let shared_w = add_fragmented("shared-w", &[0x11; 40], &[0x12; 40]); let shared_s = add_fragmented( @@ -4634,6 +4782,29 @@ mod payload_export_tests { scales: Some(s), }); } + let mut bf16_shards = Vec::new(); + for rank in 0..4u32 { + let w = if rank == 0 { + add_fragmented( + "bf16-shard-0-w", + &cached_bf16_shard[..8], + &cached_bf16_shard[8..], + ) + } else { + add_fragmented( + &format!("bf16-shard-{rank}-w"), + &vec![0x60 + rank as u8; 8], + &vec![0x70 + rank as u8; 8], + ) + }; + bf16_shards.push(wire::EngramTableShard { + rank, + first_row: u64::from(rank), + rows: 1, + weights: Some(w), + scales: None, + }); + } let engram = wire::Engram { token_map: vec![1, 2], @@ -4682,6 +4853,19 @@ mod payload_export_tests { global_scale: 1.0, shards, }, + wire::EngramTable { + layer: 3, + rows: 4, + embedding_width: 8, + hash: Some(wire::EngramHash { method: wire::engram_hash::Method::XorModulo as i32, ..Default::default() }), + weight_buffer: "bf16_part_weights".into(), + hash_buffer: "bf16_part_hashes".into(), + ready_event: "bf16_part_ready".into(), + encoding: wire::engram_table::Encoding::Bf16 as i32, + request_buffer: "bf16_part_requests".into(), + shards: bf16_shards, + ..Default::default() + }, ], }; @@ -4698,16 +4882,20 @@ mod payload_export_tests { ) .unwrap(); - assert_eq!(installed.len(), 10); - assert_eq!(leases.len(), 2); + assert_eq!(installed.len(), 14); + assert_eq!(leases.len(), 3); assert!(leases.contains_key(&shared_scales_id)); assert!(leases.contains_key(&dup_scales_id)); + assert!(leases.contains_key(&bf16_shard_id)); assert!(!assembly.join("engram-0-s.payload").exists()); assert!(!assembly.join("engram-1-shard-0-s.payload").exists()); assert!(!assembly.join("engram-1-shard-1-s.payload").exists()); + assert!(!assembly.join("engram-2-shard-0-w.payload").exists()); assert!(assembly.join("engram-0-w.payload").exists()); assert!(assembly.join("engram-1-shard-2-s.payload").exists()); assert!(assembly.join("engram-1-shard-3-s.payload").exists()); + assert!(assembly.join("engram-2-shard-1-w.payload").exists()); + assert!(assembly.join("engram-2-shard-3-w.payload").exists()); assert!(std::sync::Arc::ptr_eq( installed[3].source.file(), installed[5].source.file() @@ -4716,6 +4904,10 @@ mod payload_export_tests { installed[3].source.file(), leases[&dup_scales_id].slice().file() )); + assert!(std::sync::Arc::ptr_eq( + installed[10].source.file(), + leases[&bf16_shard_id].slice().file() + )); for payload in &installed { assert_eq!(payload.source.digest().unwrap(), payload.id); } @@ -4741,6 +4933,41 @@ mod payload_export_tests { .payload_id, dup_scales_id.as_bytes() ); + assert!(resolved.tables[2].shards.iter().all(|s| s.scales.is_none())); + assert_eq!( + resolved.tables[2].shards[0] + .weights + .as_ref() + .unwrap() + .slice + .as_ref() + .unwrap() + .payload_id, + bf16_shard_id.as_bytes() + ); + for rank in 1..4usize { + let mut actual = vec![0u8; 16]; + installed[10 + rank].source.read_at(0, &mut actual).unwrap(); + let mut expected = vec![0x60 + rank as u8; 8]; + expected.extend(std::iter::repeat_n(0x70 + rank as u8, 8)); + assert_eq!(actual, expected); + } + + let with_engram = RankOutput { + hardware: None, + payload_leases: Default::default(), + index: wire::ModelIndex { version: 4, ranks: vec![wire::BundleIndex::default(); 4], engram: Some(engram), ..Default::default() }, + payload: parts, + allocations: Vec::new(), + module_globals: Vec::new(), + external: Vec::new(), + external_extents: Vec::new(), + staging: None, + weight_payload: None, + }; + let (_, _, uncached_planes) = estimated_export_fds(std::slice::from_ref(&with_engram), 0, false); + let (_, cached_leases, cached_uncached) = estimated_export_fds(std::slice::from_ref(&with_engram), 0, true); + assert_eq!((uncached_planes, cached_leases, cached_uncached), (14, 14, 0)); } #[test] @@ -5152,6 +5379,40 @@ mod payload_export_tests { assert!(!output.exists()); assert_eq!(fs::read(sources.join("duplicate-w.bin")).unwrap(), weights); assert_eq!(fs::read(sources.join("duplicate-s.bin")).unwrap(), scales); + + let (gap_w0, gap_w1) = (vec![0x51; 16], vec![0x52; 32]); + fs::write(sources.join("gap-w0.bin"), &gap_w0).unwrap(); + fs::write(sources.join("gap-w1.bin"), &gap_w1).unwrap(); + let mut gap_rank0 = staged_rank_seeded(&sources, 0x88); + gap_rank0.index.engram = Some(wire::Engram { + compressed_vocabulary: 4, + tables: vec![wire::EngramTable { + rows: 4, + embedding_width: 8, + hash: Some(wire::EngramHash { method: wire::engram_hash::Method::Identity as i32, ..Default::default() }), + weight_buffer: "gap_weights".into(), + hash_buffer: "gap_hashes".into(), + ready_event: "gap_ready".into(), + encoding: wire::engram_table::Encoding::Bf16 as i32, + request_buffer: "gap_requests".into(), + shards: vec![ + wire::EngramTableShard { rank: 0, first_row: 0, rows: 1, scales: None, weights: Some(wire::Span { offset: 12288, nbytes: 16, ..Default::default() }) }, + wire::EngramTableShard { rank: 1, first_row: 2, rows: 2, scales: None, weights: Some(wire::Span { offset: 12304, nbytes: 32, ..Default::default() }) }, + ], + ..Default::default() + }], + ..Default::default() + }); + for (offset, name, nbytes) in [(12288, "gap-w0.bin", 16), (12304, "gap-w1.bin", 32)] { + gap_rank0.payload.push(FilePart { offset, source: FileSource { path: sources.join(name), offset: 0, nbytes } }); + } + let mut gap_rank1 = gap_rank0.clone(); + gap_rank1.index.engram = None; + let gap_output = base.join("gap-core"); + let gap_err = publish_payload(&gap_output, &[gap_rank0, gap_rank1], vec![], None, &publisher(), None, false, "directory") + .expect_err("gapped BF16 shards must fail before publication"); + assert!(gap_err.to_string().contains("must cover table rows in rank order"), "{gap_err}"); + assert!(!gap_output.exists()); let _ = fs::remove_dir_all(&base); } diff --git a/helios/manifest.md b/helios/manifest.md index 06f40381e..5f9242039 100644 --- a/helios/manifest.md +++ b/helios/manifest.md @@ -508,6 +508,13 @@ The index is limited to 128 MiB. The `ModelIndex` includes: Native manifests with Engram tables carry a shared host reader and rank-local readiness events. Each table has two pinned payload frames and ready flags. +Single-plane `BF16` tables store raw `embedding_width * 2`-byte rows without a +scale plane (`scales` absent, `scale_buffer` empty, `scale_block == 0`, +`global_scale == 0`). Tables with `EngramHash.Method.IDENTITY` use one lookup +head (`heads = 1`), empty `token_map` and hash arrays, `compressed_vocabulary == rows`, +and GPU request delivery (`request_buffer`): captured code publishes one `int64` +row ID per token in `[0, stored_rows)` (converting to partition-local indices +when sharded) or `-1` for inactive slots; out-of-range row IDs fail gathering. Each rank queues its readiness wait, compact H2D copies, and event record before launching the consumer. Transfer N+1 waits for the compute-stream start event following graph N, protecting reusable device scratch. A host frame is reusable diff --git a/helios/proto/core.proto b/helios/proto/core.proto index e7e09c38f..cf865a915 100644 --- a/helios/proto/core.proto +++ b/helios/proto/core.proto @@ -264,7 +264,8 @@ message Engram { } message EngramTable { - enum Encoding { UNSPECIFIED = 0; FP8_E4M3_E8M0 = 1; NVFP4_E4M3_GLOBAL = 2; } + // BF16 stores raw bfloat16 rows of nonzero `embedding_width` with no scale plane (`scale_block == 0`, `global_scale == 0`). + enum Encoding { UNSPECIFIED = 0; FP8_E4M3_E8M0 = 1; NVFP4_E4M3_GLOBAL = 2; BF16 = 3; } uint32 layer = 1; uint64 rows = 2; uint32 embedding_width = 3; @@ -298,11 +299,13 @@ message EngramTableShard { } message EngramHash { - enum Method { UNSPECIFIED = 0; XOR_MODULO = 1; EOS_XOR_MODULO = 2; } + // IDENTITY selects 1-head direct indexing without token_map: requires `request_buffer`, empty + // hash arrays, and `compressed_vocabulary == rows`; mailboxes publish row IDs in `[0, stored_rows)` or `-1`. + enum Method { UNSPECIFIED = 0; XOR_MODULO = 1; EOS_XOR_MODULO = 2; IDENTITY = 3; } Method method = 1; - // One order, modulus, and row offset per lookup head, in output-column order. + // One order, modulus, and row offset per lookup head, in output-column order (empty for IDENTITY). repeated uint32 orders = 2; - // Multipliers by lag: current token first, then preceding tokens. Missing history uses pad_token_id. + // Multipliers by lag: current token first, then preceding tokens. Missing history uses pad_token_id (empty for IDENTITY). repeated uint64 multipliers = 3; repeated uint64 primes = 4; repeated uint64 offsets = 5; diff --git a/helios/proto/runtime_core.proto b/helios/proto/runtime_core.proto index 3b0ed0d62..e30a7eee5 100644 --- a/helios/proto/runtime_core.proto +++ b/helios/proto/runtime_core.proto @@ -660,7 +660,8 @@ message Engram { repeated EngramTable tables = 4; } message EngramTable { - enum Encoding { UNSPECIFIED = 0; FP8_E4M3_E8M0 = 1; NVFP4_E4M3_GLOBAL = 2; } + // BF16 stores raw bfloat16 rows of nonzero `embedding_width` with no scale plane (`scale_block == 0`, `global_scale == 0`). + enum Encoding { UNSPECIFIED = 0; FP8_E4M3_E8M0 = 1; NVFP4_E4M3_GLOBAL = 2; BF16 = 3; } uint32 layer = 1; uint64 rows = 2; uint32 embedding_width = 3; @@ -692,11 +693,13 @@ message EngramTableShard { Span scales = 5; } message EngramHash { - enum Method { UNSPECIFIED = 0; XOR_MODULO = 1; EOS_XOR_MODULO = 2; } + // IDENTITY selects 1-head direct indexing without token_map: requires `request_buffer`, empty + // hash arrays, and `compressed_vocabulary == rows`; mailboxes publish row IDs in `[0, stored_rows)` or `-1`. + enum Method { UNSPECIFIED = 0; XOR_MODULO = 1; EOS_XOR_MODULO = 2; IDENTITY = 3; } Method method = 1; - // One order, modulus, and row offset per lookup head, in output-column order. + // One order, modulus, and row offset per lookup head, in output-column order (empty for IDENTITY). repeated uint32 orders = 2; - // Multipliers by lag: current token first, then preceding tokens. Missing history uses pad_token_id. + // Multipliers by lag: current token first, then preceding tokens. Missing history uses pad_token_id (empty for IDENTITY). repeated uint64 multipliers = 3; repeated uint64 primes = 4; repeated uint64 offsets = 5; diff --git a/helios/src/core/reader.rs b/helios/src/core/reader.rs index 270e77fc6..f8734bda8 100644 --- a/helios/src/core/reader.rs +++ b/helios/src/core/reader.rs @@ -234,14 +234,19 @@ pub fn required_payloads(core: &VerifiedCore) -> Result>> { .and_then(|deployment| deployment.engram.as_ref()) { for table in &engram.tables { + let has_scales = super::schema::engram_encoding_has_scales(table.encoding)?; if table.shards.is_empty() { add(table.weights.as_ref())?; - add(table.scales.as_ref())?; + if has_scales { + add(table.scales.as_ref())?; + } } else { for shard in &table.shards { if core.rank(shard.rank).is_some() { add(shard.weights.as_ref())?; - add(shard.scales.as_ref())?; + if has_scales { + add(shard.scales.as_ref())?; + } } } } diff --git a/helios/src/core/schema.rs b/helios/src/core/schema.rs index 0679486e7..0e31b860d 100644 --- a/helios/src/core/schema.rs +++ b/helios/src/core/schema.rs @@ -313,6 +313,33 @@ pub fn validate_deployment(body: &wire::DeploymentBody, catalog: &mut Catalog) - Ok(ranks) } +/// Whether an `EngramTable` encoding carries a separate scale plane. +/// Rejects `Unspecified` and unknown encodings. +pub fn engram_encoding_has_scales(encoding: i32) -> Result { + match wire::engram_table::Encoding::try_from(encoding) { + Ok( + wire::engram_table::Encoding::Fp8E4m3E8m0 + | wire::engram_table::Encoding::Nvfp4E4m3Global, + ) => Ok(true), + Ok(wire::engram_table::Encoding::Bf16) => Ok(false), + _ => Err(invalid("engram table has no encoding")), + } +} + +/// Validate presence or absence of an optional scale plane against `encoding`. +pub fn engram_scales<'a, T>(encoding: i32, scales: &'a Option) -> Result> { + if engram_encoding_has_scales(encoding)? { + scales + .as_ref() + .ok_or_else(|| invalid("engram table has no scales plane")) + .map(Some) + } else if scales.is_some() { + Err(invalid("single-plane engram table cannot carry scales plane")) + } else { + Ok(None) + } +} + fn validate_engram(engram: &wire::Engram, ranks: u32, catalog: &Catalog) -> Result<()> { if engram.tables.is_empty() { return Err(invalid("engram catalog has no tables")); @@ -337,16 +364,19 @@ fn validate_engram(engram: &wire::Engram, ranks: u32, catalog: &Catalog) -> Resu } let roles = [wire::PayloadRole::Weights, wire::PayloadRole::TunedWeights]; for table in &engram.tables { - if wire::engram_table::Encoding::try_from(table.encoding).map_or(true, |value| { - value == wire::engram_table::Encoding::Unspecified - }) { - return Err(invalid("engram table has no encoding")); - } + let has_scales = engram_encoding_has_scales(table.encoding)?; if table.rows == 0 || table.embedding_width == 0 { return Err(invalid("engram table has no rows or width")); } bounded_name(&table.weight_buffer, 64, "engram weight buffer")?; - bounded_name(&table.scale_buffer, 64, "engram scale buffer")?; + if has_scales { + bounded_name(&table.scale_buffer, 64, "engram scale buffer")?; + } else if !table.scale_buffer.is_empty() + || table.scale_block != 0 + || table.global_scale.to_bits() != 0 + { + return Err(invalid("single-plane engram table cannot carry scale metadata")); + } if !table.prefetch_buffer.is_empty() { if table.request_buffer.is_empty() { return Err(invalid( @@ -365,11 +395,13 @@ fn validate_engram(engram: &wire::Engram, ranks: u32, catalog: &Catalog) -> Resu return Err(invalid("engram hash has no method")); } if token_map_empty { - if method != wire::engram_hash::Method::EosXorModulo - || table.request_buffer.is_empty() + if !matches!( + method, + wire::engram_hash::Method::EosXorModulo | wire::engram_hash::Method::Identity + ) || table.request_buffer.is_empty() { return Err(invalid( - "engram without a token map requires EOS XOR hash and request delivery", + "engram without a token map requires request delivery with EOS XOR or identity indexing", )); } } else if method != wire::engram_hash::Method::XorModulo { @@ -377,44 +409,97 @@ fn validate_engram(engram: &wire::Engram, ranks: u32, catalog: &Catalog) -> Resu "engram with a token map requires XOR-modulo hashing", )); } - if !hash.orders.is_empty() + if method == wire::engram_hash::Method::Identity { + if !hash.orders.is_empty() + || !hash.multipliers.is_empty() + || !hash.primes.is_empty() + || !hash.offsets.is_empty() + || engram.compressed_vocabulary as u64 != table.rows + { + return Err(invalid( + "identity engram index cannot carry hash arrays or mismatched vocabulary", + )); + } + } else if !hash.orders.is_empty() && (hash.orders.len() != hash.primes.len() || hash.orders.len() != hash.offsets.len()) { return Err(invalid("engram hash head arrays disagree")); } + let bf16_row_bytes = if table.encoding == wire::engram_table::Encoding::Bf16 as i32 { + Some( + u64::from(table.embedding_width) + .checked_mul(2) + .ok_or_else(|| invalid("BF16 engram row width overflow"))?, + ) + } else { + None + }; if table.shards.is_empty() { - for (plane, label) in [(&table.weights, "weights"), (&table.scales, "scales")] { - let plane = plane - .as_ref() - .ok_or_else(|| invalid(format!("engram table has no {label} plane")))?; - catalog.check_use(plane, &roles)?; + let weights = table + .weights + .as_ref() + .ok_or_else(|| invalid("engram table has no weights plane"))?; + catalog.check_use(weights, &roles)?; + if let Some(row_bytes) = bf16_row_bytes { + let expected = table + .rows + .checked_mul(row_bytes) + .ok_or_else(|| invalid("BF16 engram plane size overflow"))?; + if weights.slice.as_ref().map(|slice| slice.nbytes) != Some(expected) { + return Err(invalid("BF16 engram plane size mismatch")); + } + } + if let Some(scales) = engram_scales(table.encoding, &table.scales)? { + catalog.check_use(scales, &roles)?; } } else { if table.weights.is_some() || table.scales.is_some() { return Err(invalid("partitioned table carries shared planes too")); } + if table.request_buffer.is_empty() { + return Err(invalid( + "partitioned engram table requires GPU request delivery", + )); + } + if table.shards.len() != ranks as usize { + return Err(invalid( + "engram partitions must match the deployment rank count", + )); + } let mut end = 0u64; - for shard in &table.shards { - if shard.rank >= ranks { - return Err(invalid("engram partition names an absent rank")); + for (rank, shard) in table.shards.iter().enumerate() { + if shard.rank as usize != rank || shard.first_row != end || shard.rows == 0 { + return Err(invalid( + "engram partitions must cover table rows in rank order", + )); } - if shard.rows == 0 || shard.first_row < end { - return Err(invalid("engram partitions overlap or are empty")); - } - end = shard - .first_row + end = end .checked_add(shard.rows) .ok_or_else(|| invalid("engram partition overflow"))?; if end > table.rows { return Err(invalid("engram partition exceeds table rows")); } - for (plane, label) in [(&shard.weights, "weights"), (&shard.scales, "scales")] { - let plane = plane - .as_ref() - .ok_or_else(|| invalid(format!("engram partition has no {label} plane")))?; - catalog.check_use(plane, &roles)?; + let weights = shard + .weights + .as_ref() + .ok_or_else(|| invalid("engram partition has no weights plane"))?; + catalog.check_use(weights, &roles)?; + if let Some(row_bytes) = bf16_row_bytes { + let expected = shard + .rows + .checked_mul(row_bytes) + .ok_or_else(|| invalid("BF16 engram partition size overflow"))?; + if weights.slice.as_ref().map(|slice| slice.nbytes) != Some(expected) { + return Err(invalid("BF16 engram partition size mismatch")); + } + } + if let Some(scales) = engram_scales(table.encoding, &shard.scales)? { + catalog.check_use(scales, &roles)?; } } + if end != table.rows { + return Err(invalid("engram partitions must cover all table rows")); + } } } Ok(()) @@ -1720,6 +1805,129 @@ mod tests { assert!(validate_engram(&mapped_xor, 1, &catalog).is_ok()); } + #[test] + fn bf16_identity_single_plane_engram_validation() { + let mut catalog = Catalog::new(); + let rows = 4u64; + let width = 8960u32; + let nbytes = rows * u64::from(width) * 2; + let half = (rows / 2) * u64::from(width) * 2; + catalog.insert(&descriptor(1, nbytes)).unwrap(); + catalog.insert(&descriptor(2, 64)).unwrap(); + catalog.insert(&descriptor(3, half)).unwrap(); + catalog.insert(&descriptor(4, half)).unwrap(); + let use_ = |id: u8, bytes: u64| wire::PayloadUse { + slice: Some(wire::PayloadSlice { + payload_id: vec![id; 32], + offset: 0, + nbytes: bytes, + }), + role: wire::PayloadRole::Weights as i32, + }; + let table = wire::EngramTable { + layer: 0, + rows, + embedding_width: width, + scale_block: 0, + weights: Some(use_(1, nbytes)), + scales: None, + hash: Some(wire::EngramHash { + method: wire::engram_hash::Method::Identity as i32, + ..Default::default() + }), + weight_buffer: "ple_weights".into(), + scale_buffer: String::new(), + hash_buffer: "ple_hashes".into(), + request_buffer: "ple_requests".into(), + ready_event: "ple_ready".into(), + encoding: wire::engram_table::Encoding::Bf16 as i32, + global_scale: 0.0, + ..Default::default() + }; + let engram = wire::Engram { + token_map: vec![], + pad_token_id: 0, + compressed_vocabulary: rows as u32, + tables: vec![table], + }; + assert!(validate_engram(&engram, 1, &catalog).is_ok()); + + let assert_err = |candidate: &wire::Engram, ranks: u32, needle: &str| { + let err = validate_engram(candidate, ranks, &catalog).unwrap_err().to_string(); + assert!(err.contains(needle), "expected {needle:?}, got {err:?}"); + }; + + let mut bad_size = engram.clone(); + bad_size.tables[0].weights = Some(use_(1, 17920)); + assert_err(&bad_size, 1, "plane size mismatch"); + + let mut bad_vocab = engram.clone(); + bad_vocab.compressed_vocabulary = 2; + assert_err(&bad_vocab, 1, "mismatched vocabulary"); + + let mut with_scales = engram.clone(); + with_scales.tables[0].scales = Some(use_(2, 64)); + assert_err(&with_scales, 1, "cannot carry scales plane"); + + let mut with_scale_buf = engram.clone(); + with_scale_buf.tables[0].scale_buffer = "ple_scales".into(); + assert_err(&with_scale_buf, 1, "cannot carry scale metadata"); + + let mut with_hash_arrays = engram.clone(); + with_hash_arrays.tables[0].hash.as_mut().unwrap().orders = vec![1]; + assert_err(&with_hash_arrays, 1, "cannot carry hash arrays"); + + let mut no_request = engram.clone(); + no_request.tables[0].request_buffer.clear(); + assert_err(&no_request, 1, "requires request delivery"); + + let mut neg_zero = engram.clone(); + neg_zero.tables[0].global_scale = -0.0; + assert_err(&neg_zero, 1, "cannot carry scale metadata"); + + let mut partitioned = engram; + partitioned.tables[0].weights = None; + partitioned.tables[0].shards = vec![ + wire::EngramTableShard { + rank: 0, + first_row: 0, + rows: 2, + weights: Some(use_(3, half)), + scales: None, + }, + wire::EngramTableShard { + rank: 1, + first_row: 2, + rows: 2, + weights: Some(use_(4, half)), + scales: None, + }, + ]; + assert!(validate_engram(&partitioned, 2, &catalog).is_ok()); + + let mut gapped = partitioned.clone(); + gapped.tables[0].shards[0].rows = 1; + gapped.tables[0].shards[0].weights = Some(use_(3, u64::from(width) * 2)); + assert_err(&gapped, 2, "must cover table rows in rank order"); + + let mut short_tail = partitioned.clone(); + short_tail.tables[0].shards[1].rows = 1; + short_tail.tables[0].shards[1].weights = Some(use_(4, u64::from(width) * 2)); + assert_err(&short_tail, 2, "must cover all table rows"); + + let mut wrong_order = partitioned.clone(); + wrong_order.tables[0].shards.swap(0, 1); + assert_err(&wrong_order, 2, "must cover table rows in rank order"); + + let mut bad_shard_bytes = partitioned.clone(); + bad_shard_bytes.tables[0].shards[0].weights = Some(use_(3, u64::from(width) * 2)); + assert_err(&bad_shard_bytes, 2, "partition size mismatch"); + + let mut shard_with_scales = partitioned.clone(); + shard_with_scales.tables[0].shards[0].scales = Some(use_(2, 64)); + assert_err(&shard_with_scales, 2, "cannot carry scales plane"); + } + #[test] fn peer_memory_requires_owner_inclusive_unique_readers_and_unique_addresses() { let peer = |owner, address, readers| runtime::PeerMemory { diff --git a/helios/src/engram.rs b/helios/src/engram.rs index 8dc7b959f..963ae1f05 100644 --- a/helios/src/engram.rs +++ b/helios/src/engram.rs @@ -17,7 +17,7 @@ use crate::{ }; #[cfg(unix)] pub use prepared::{PlaneSource, PreparedTables, SourceSegment, TableSource}; -pub(crate) use reader::Plane; +pub(crate) use reader::{Plane, Planes}; #[cfg(feature = "server")] use std::fmt::Write; use std::{ @@ -175,10 +175,12 @@ pub enum Storage { #[derive(Clone, Debug, PartialEq, Eq)] pub(crate) struct Table { - pub(crate) planes: [Plane; 2], + pub(crate) planes: Planes, + /// Owning partition rank (`None` for shared tables); keeps partitioned delivery groups distinct. + pub(crate) partition: Option, pub(crate) heads: usize, pub(crate) weights: String, - pub(crate) scales: String, + pub(crate) scales: Option, pub(crate) hashes: String, pub(crate) event: String, pub(crate) request: Option, @@ -190,6 +192,14 @@ pub(crate) struct Index { pub(crate) tables: Vec, } +impl Index { + /// Two ranks share one delivery group only when every table matches in + /// planes, bindings, and partition ownership (`Table::partition`). + pub(crate) fn shares_delivery_with(&self, other: &Self) -> bool { + self == other + } +} + impl Table { fn staging_payload_bytes(&self, max_tokens: usize) -> Result { self.planes.iter().try_fold(0usize, |total, plane| total.checked_add(plane.row_bytes)) @@ -412,14 +422,14 @@ fn commit_gathered_misses( fn run_reader_worker( reader: &mut reader::Reader, - planes: [Plane; 2], + planes: Planes, prefetch_cap: usize, warm_batch: usize, frames: [WorkerFrame<'_>; STAGING_FRAMES], receiver: &mpsc::Receiver, stop: &AtomicBool, ) { - let row_bytes = planes.iter().map(|plane| plane.row_bytes).sum::(); + let row_bytes = planes.row_bytes(); let warm_batch = warm_batch.max(1); let mut held: Option = None; let mut pending_warm: Vec = Vec::with_capacity(prefetch_cap); @@ -621,14 +631,13 @@ impl Shared { let table_bytes: u128 = index .tables .iter() - .flat_map(|table| &table.planes) - .map(|plane| plane.nbytes as u128) + .map(|table| table.planes.total_nbytes()) .sum(); let readers = index .tables .iter() .map(|table| { - let bytes: u128 = table.planes.iter().map(|plane| plane.nbytes as u128).sum(); + let bytes = table.planes.total_nbytes(); let budget = usize::try_from(cache_bytes as u128 * bytes / table_bytes) .map_err(|_| "embedding row cache exceeds host address range")?; let rows = max_tokens @@ -822,7 +831,7 @@ struct Transfer { stream: Stream, flags: [usize; STAGING_FRAMES], weights: usize, - scales: usize, + scales: Option, event: usize, request: Option<(usize, usize)>, prefetch: Option, @@ -903,7 +912,11 @@ impl Transfers { stream, flags, weights: manifest.buffer(&table.weights)?.address, - scales: manifest.buffer(&table.scales)?.address, + scales: table + .scales + .as_deref() + .map(|name| Ok::<_, Error>(manifest.buffer(name)?.address)) + .transpose()?, event: binding.events[i], request, prefetch, @@ -996,14 +1009,18 @@ impl Transfers { transfer.weights, &staging.data, 0, - rows * table.planes[0].row_bytes, - )?; - transfer.stream.upload( - transfer.scales, - &staging.data, - rows * table.planes[0].row_bytes, - rows * table.planes[1].row_bytes, + rows * table.planes.weights.row_bytes, )?; + if let (Some(scales_dst), Some(scales_plane)) = + (transfer.scales, table.planes.scales) + { + transfer.stream.upload( + scales_dst, + &staging.data, + rows * table.planes.weights.row_bytes, + rows * scales_plane.row_bytes, + )?; + } // The consumer is enqueued before a following submission re-records this event. transfer.stream.record_borrowed(transfer.event)?; } @@ -1046,9 +1063,12 @@ mod tests { #[test] fn staging_budget_covers_two_payloads_and_ready_flags_per_table() { let table = Table { - planes: [Plane { file: 0, offset: 0, nbytes: 1024, row_bytes: 64 }, - Plane { file: 0, offset: 1024, nbytes: 128, row_bytes: 8 }], - heads: 4, weights: "weights".into(), scales: "scales".into(), + planes: Planes::two( + Plane { file: 0, offset: 0, nbytes: 1024, row_bytes: 64 }, + Plane { file: 0, offset: 1024, nbytes: 128, row_bytes: 8 }, + ), + partition: None, + heads: 4, weights: "weights".into(), scales: Some("scales".into()), hashes: "hashes".into(), event: "ready".into(), request: None, prefetch: None, }; @@ -1227,7 +1247,7 @@ mod tests { .map(|i| ((i * 29 + 7) & 0xff) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: 0, @@ -1240,7 +1260,7 @@ mod tests { nbytes: rows * 10, row_bytes: 10, }, - ]; + ); let stats = Arc::new(Stats::default()); let file = Arc::new(crate::os::direct_file(&path, false).unwrap()); let mut reader = reader::Reader::from_files( @@ -1369,7 +1389,7 @@ mod tests { .map(|i| ((i * 19 + 11) & 0xff) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: 0, @@ -1382,7 +1402,7 @@ mod tests { nbytes: rows * 10, row_bytes: 10, }, - ]; + ); let stats = Arc::new(Stats::default()); let file = Arc::new(crate::os::direct_file(&path, false).unwrap()); let mut reader = reader::Reader::from_files( @@ -1470,7 +1490,7 @@ mod tests { .map(|i| ((i * 37 + 5) & 0xff) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: 0, @@ -1483,7 +1503,7 @@ mod tests { nbytes: rows * 10, row_bytes: 10, }, - ]; + ); let file = Arc::new(crate::os::direct_file(&path, false).unwrap()); // Teardown path: when `stop` is already set after staging, `commit_gathered_misses` diff --git a/helios/src/engram/prepared.rs b/helios/src/engram/prepared.rs index 81ba1b0a9..6d9f0b334 100644 --- a/helios/src/engram/prepared.rs +++ b/helios/src/engram/prepared.rs @@ -6,7 +6,7 @@ //! Immutable resident tables shared across preparation-owned rank processes. -use super::{Binding, Index, Plane, Shared, Table, reader}; +use super::{Binding, Index, Plane, Planes, Shared, Table, reader}; use crate::{ Result, execution::{Dtype, ExecutionManifest}, @@ -37,10 +37,10 @@ pub struct PlaneSource { /// Table geometry and the prepared buffers consumed by native row delivery. #[derive(Clone, Debug)] pub struct TableSource { - pub planes: [PlaneSource; 2], + pub weights_plane: PlaneSource, pub heads: usize, pub weights: String, - pub scales: String, + pub scales: Option<(PlaneSource, String)>, pub hashes: String, pub event: String, pub request: Option, @@ -50,7 +50,7 @@ pub struct TableSource { /// delivery staging and CUDA events belong to each rank's native binding. pub struct PreparedTables { index: Arc, - data: Vec<[Arc; 2]>, + data: Vec<(Arc, Option>)>, } impl PreparedTables { @@ -67,16 +67,16 @@ impl PreparedTables { || source.heads > 64 || source.event.is_empty() || !events.insert(source.event.clone()) - || [&source.weights, &source.scales, &source.hashes] + || [&source.weights, &source.hashes] .into_iter() + .chain(source.scales.iter().map(|(_, name)| name)) .chain(source.request.iter()) .any(|name| name.is_empty() || !names.insert(name.clone())) { return Err("invalid embedding table bindings or head count".into()); } - let mut planes = Vec::new(); let mut rows = None; - for plane in &source.planes { + let mut validate_plane = |plane: &PlaneSource| -> Result { if plane.row_bytes == 0 || plane.segments.is_empty() { return Err("invalid embedding table source plane".into()); } @@ -108,18 +108,28 @@ impl PreparedTables { "embedding weight and scale planes have different row counts".into(), ); } - planes.push(Plane { + Ok(Plane { file: 0, offset: 0, nbytes, row_bytes: plane.row_bytes, - }); - } + }) + }; + let weights_plane = validate_plane(&source.weights_plane)?; + let scales_plane = source + .scales + .as_ref() + .map(|(plane, _)| validate_plane(plane)) + .transpose()?; tables.push(Table { - planes: [planes[0], planes[1]], + planes: Planes { + weights: weights_plane, + scales: scales_plane, + }, + partition: None, heads: source.heads, weights: source.weights.clone(), - scales: source.scales.clone(), + scales: source.scales.as_ref().map(|(_, name)| name.clone()), hashes: source.hashes.clone(), event: source.event.clone(), request: source.request.clone(), @@ -133,22 +143,28 @@ impl PreparedTables { /// opens or reads the checkpoint files after this constructor succeeds. pub fn load(vocabulary: usize, sources: &[TableSource]) -> Result { let index = Self::index(vocabulary, sources)?; + let load_plane = |source: &PlaneSource, plane: Plane| -> Result> { + let segments = source + .segments + .iter() + .map(|segment| { + let file = File::open(&segment.path) + .map_err(|error| format!("open embedding source segment: {error}"))?; + Ok((file, segment.offset, segment.nbytes)) + }) + .collect::>>()?; + Ok(Arc::new(reader::Resident::load_segments(plane, &segments)?)) + }; let mut data = Vec::new(); for (source, table) in sources.iter().zip(&index.tables) { - let mut planes = Vec::new(); - for (source, plane) in source.planes.iter().zip(table.planes) { - let segments = source - .segments - .iter() - .map(|segment| { - let file = File::open(&segment.path) - .map_err(|error| format!("open embedding source segment: {error}"))?; - Ok((file, segment.offset, segment.nbytes)) - }) - .collect::>>()?; - planes.push(Arc::new(reader::Resident::load_segments(plane, &segments)?)); - } - data.push([planes.remove(0), planes.remove(0)]); + let weights = load_plane(&source.weights_plane, table.planes.weights)?; + let scales = source + .scales + .as_ref() + .zip(table.planes.scales) + .map(|((src, _), plane)| load_plane(src, plane)) + .transpose()?; + data.push((weights, scales)); } Ok(Self { index, data }) } @@ -161,25 +177,36 @@ impl PreparedTables { descriptors: &[i32], ) -> Result { let index = Self::index(vocabulary, sources)?; - if descriptors.len() != index.tables.len() * 2 { + let expected_descriptors: usize = index + .tables + .iter() + .map(|table| 1 + usize::from(table.planes.scales.is_some())) + .sum(); + if descriptors.len() != expected_descriptors { return Err("shared embedding descriptor count differs from its catalog".into()); } - let mut data = Vec::new(); - for (table, handles) in index.tables.iter().zip(descriptors.chunks_exact(2)) { - let mut planes = Vec::new(); - for (plane, descriptor) in table.planes.into_iter().zip(handles) { - let owned = unsafe { libc::fcntl(*descriptor, libc::F_DUPFD_CLOEXEC, 0) }; - if owned < 0 { - return Err(format!( - "duplicate resident embedding descriptor: {}", - std::io::Error::last_os_error() - ) - .into()); - } - let file = unsafe { File::from_raw_fd(owned) }; - planes.push(Arc::new(reader::Resident::from_shared(file, plane)?)); + let dup_plane = |plane: Plane, descriptor: i32| -> Result> { + let owned = unsafe { libc::fcntl(descriptor, libc::F_DUPFD_CLOEXEC, 0) }; + if owned < 0 { + return Err(format!( + "duplicate resident embedding descriptor: {}", + std::io::Error::last_os_error() + ) + .into()); } - data.push([planes.remove(0), planes.remove(0)]); + let file = unsafe { File::from_raw_fd(owned) }; + Ok(Arc::new(reader::Resident::from_shared(file, plane)?)) + }; + let mut data = Vec::new(); + let mut cursor = descriptors.iter().copied(); + for table in &index.tables { + let weights = dup_plane(table.planes.weights, cursor.next().unwrap())?; + let scales = table + .planes + .scales + .map(|plane| dup_plane(plane, cursor.next().unwrap())) + .transpose()?; + data.push((weights, scales)); } Ok(Self { index, data }) } @@ -188,7 +215,10 @@ impl PreparedTables { pub fn descriptors(&self) -> Vec { self.data .iter() - .flat_map(|planes| planes.iter().map(|plane| plane.descriptor())) + .flat_map(|(weights, scales)| { + std::iter::once(weights.descriptor()) + .chain(scales.as_ref().map(|plane| plane.descriptor())) + }) .collect() } @@ -228,16 +258,19 @@ impl PreparedTables { let rows = tokens .checked_mul(table.heads) .ok_or("embedding row capacity exceeds host range")?; - for (name, dtype, height, width) in [ + let mut required = vec![ ( &table.weights, Dtype::Uint8, rows, - table.planes[0].row_bytes, + table.planes.weights.row_bytes, ), - (&table.scales, Dtype::Uint8, rows, table.planes[1].row_bytes), (&table.hashes, Dtype::Int64, tokens, table.heads), - ] { + ]; + if let (Some(name), Some(plane)) = (&table.scales, table.planes.scales) { + required.push((name, Dtype::Uint8, rows, plane.row_bytes)); + } + for (name, dtype, height, width) in required { let buffer = manifest.buffer(name)?; if buffer.dtype != dtype || buffer.shape.len() != 2 @@ -278,7 +311,9 @@ impl PreparedTables { let readers = self .data .iter() - .map(|data| reader::Reader::resident(data.clone(), stats.clone())) + .map(|(weights, scales)| { + reader::Reader::resident(weights.clone(), scales.clone(), stats.clone()) + }) .collect(); Ok(Binding { shared: Shared::with_readers( @@ -313,22 +348,24 @@ mod tests { std::fs::write(&first, &weights).unwrap(); std::fs::write(&second, &scales).unwrap(); let sources = [TableSource { - planes: [ - PlaneSource { - segments: vec![ - SourceSegment { - path: first.clone(), - offset: 37 + 4096, - nbytes: 4096, - }, - SourceSegment { - path: first, - offset: 37, - nbytes: 4096, - }, - ], - row_bytes: 256, - }, + weights_plane: PlaneSource { + segments: vec![ + SourceSegment { + path: first.clone(), + offset: 37 + 4096, + nbytes: 4096, + }, + SourceSegment { + path: first, + offset: 37, + nbytes: 4096, + }, + ], + row_bytes: 256, + }, + heads: 24, + weights: "weights".into(), + scales: Some(( PlaneSource { segments: vec![ SourceSegment { @@ -344,10 +381,8 @@ mod tests { ], row_bytes: 8, }, - ], - heads: 24, - weights: "weights".into(), - scales: "scales".into(), + "scales".into(), + )), hashes: "hashes".into(), event: "ready".into(), request: Some("requests".into()), @@ -359,7 +394,11 @@ mod tests { assert!(PreparedTables::from_shared(129280, &sources, &owner.descriptors()[..1]).is_err()); std::fs::remove_dir_all(root).unwrap(); drop(owner); - let mut reader = reader::Reader::resident(peer.data[0].clone(), Arc::default()); + let mut reader = reader::Reader::resident( + peer.data[0].0.clone(), + peer.data[0].1.clone(), + Arc::default(), + ); let mut output = vec![0; 3 * (256 + 8)]; reader .gather(&peer.index.tables[0].planes, &[31, -1, 0], &mut output) @@ -376,4 +415,51 @@ mod tests { .is_err() ); } + + #[test] + fn single_plane_table_shares_one_descriptor_and_gathers_rows() { + let root = std::env::temp_dir().join(format!( + "helios-embedding-single-{}", + std::process::id() + )); + std::fs::create_dir_all(&root).unwrap(); + let path = root.join("weights.bin"); + let row_bytes = 512; + let weights: Vec = (0..100 + 16 * row_bytes) + .map(|i| ((i * 19 + i / 64) & 0xFF) as u8) + .collect(); + std::fs::write(&path, &weights).unwrap(); + let sources = [TableSource { + weights_plane: PlaneSource { + segments: vec![SourceSegment { + path, + offset: 37, + nbytes: 16 * row_bytes, + }], + row_bytes, + }, + heads: 1, + weights: "ple_weights".into(), + scales: None, + hashes: "ple_hashes".into(), + event: "ple_ready".into(), + request: Some("ple_requests".into()), + }]; + let owner = PreparedTables::load(16, &sources).unwrap(); + assert_eq!(owner.descriptors().len(), 1); + assert_eq!(owner.nbytes(), 16 * row_bytes); + let peer = PreparedTables::from_shared(16, &sources, &owner.descriptors()).unwrap(); + assert!(PreparedTables::from_shared(16, &sources, &[]).is_err()); + assert!(PreparedTables::from_shared(16, &sources, &[-1, -1]).is_err()); + std::fs::remove_dir_all(root).unwrap(); + drop(owner); + let mut reader = reader::Reader::resident(peer.data[0].0.clone(), None, Arc::default()); + let mut output = vec![0xA5; 3 * row_bytes]; + reader + .gather(&peer.index.tables[0].planes, &[15, -1, 0], &mut output) + .unwrap(); + assert_eq!(&output[..row_bytes], &weights[37 + 15 * row_bytes..37 + 16 * row_bytes]); + assert_eq!(&output[row_bytes..2 * row_bytes], &vec![0u8; row_bytes]); + assert_eq!(&output[2 * row_bytes..], &weights[37..37 + row_bytes]); + } } diff --git a/helios/src/engram/reader.rs b/helios/src/engram/reader.rs index 69a06e71a..2a395ff1c 100644 --- a/helios/src/engram/reader.rs +++ b/helios/src/engram/reader.rs @@ -57,6 +57,50 @@ pub(crate) struct Plane { pub row_bytes: usize, } +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(crate) struct Planes { + pub weights: Plane, + pub scales: Option, +} + +impl Planes { + #[cfg(test)] + pub(crate) fn single(weights: Plane) -> Self { + Self { + weights, + scales: None, + } + } + + #[cfg(test)] + pub(crate) fn two(weights: Plane, scales: Plane) -> Self { + Self { + weights, + scales: Some(scales), + } + } + + pub(crate) fn row_bytes(self) -> usize { + self.weights.row_bytes + self.scales.map_or(0, |plane| plane.row_bytes) + } + + pub(crate) fn scale_row_bytes(self) -> usize { + self.scales.map_or(0, |plane| plane.row_bytes) + } + + pub(crate) fn total_nbytes(self) -> u128 { + self.weights.nbytes as u128 + self.scales.map_or(0, |plane| plane.nbytes as u128) + } + + pub(crate) fn iter(self) -> impl Iterator { + std::iter::once(self.weights).chain(self.scales) + } + + pub(crate) fn iter_mut(&mut self) -> impl Iterator { + std::iter::once(&mut self.weights).chain(self.scales.as_mut()) + } +} + impl Plane { pub(crate) fn resident_bytes(self) -> Result { ((self.offset % BLOCK as u64) as usize) @@ -745,7 +789,7 @@ impl DiskReader { }) } - pub fn gather(&mut self, planes: &[Plane; 2], ids: &[i64], output: &mut [u8]) -> Result<()> { + pub fn gather(&mut self, planes: &Planes, ids: &[i64], output: &mut [u8]) -> Result<()> { let mut timing = DiskTimings { stats: &self.stats, plan: 0, @@ -923,11 +967,13 @@ fn copy_cached_hits_slice( (output_base + target * weights) as *mut u8, weights, ); - std::ptr::copy_nonoverlapping( - row.as_ptr().add(weights), - (output_base + scale_base + target * scales) as *mut u8, - scales, - ); + if scales > 0 { + std::ptr::copy_nonoverlapping( + row.as_ptr().add(weights), + (output_base + scale_base + target * scales) as *mut u8, + scales, + ); + } } } } @@ -962,11 +1008,11 @@ fn copy_cached_hits( } impl CachedReader { - fn new(disk: DiskReader, planes: &[Plane; 2], budget: usize, max_rows: usize) -> Result { + fn new(disk: DiskReader, planes: &Planes, budget: usize, max_rows: usize) -> Result { if max_rows == 0 { return Err("embedding row cache requires a nonzero gather capacity".into()); } - let row_bytes = planes.iter().map(|plane| plane.row_bytes).sum::(); + let row_bytes = planes.row_bytes(); let workspace = max_rows .checked_mul( size_of::<(i64, usize)>() @@ -1003,7 +1049,7 @@ impl CachedReader { let miss_output = allocated(max_rows * row_bytes, 0u8)?; let cache = RowCache::new( payload_budget, - planes[0].nbytes / planes[0].row_bytes, + planes.weights.nbytes / planes.weights.row_bytes, row_bytes, )?; let bytes = cache.bytes() + workspace; @@ -1036,7 +1082,7 @@ impl CachedReader { /// must insert the fetched misses after the caller signals the consumer. fn gather_into_output( &mut self, - planes: &[Plane; 2], + planes: &Planes, ids: &[i64], output: &mut [u8], ) -> Result { @@ -1044,7 +1090,8 @@ impl CachedReader { if ids.len() > self.max_rows { return Err("embedding gather exceeds the row cache workspace capacity".into()); } - let [weights, scales] = planes.map(|plane| plane.row_bytes); + let weights = planes.weights.row_bytes; + let scales = planes.scale_row_bytes(); let scale_base = ids.len() * weights; self.requests.clear(); self.miss_groups.clear(); @@ -1052,7 +1099,9 @@ impl CachedReader { for (row, &id) in ids.iter().enumerate() { if id < 0 { output[row * weights..(row + 1) * weights].fill(0); - output[scale_base + row * scales..scale_base + (row + 1) * scales].fill(0); + if scales > 0 { + output[scale_base + row * scales..scale_base + (row + 1) * scales].fill(0); + } } else { self.requests.push((id, row)); } @@ -1104,8 +1153,10 @@ impl CachedReader { [count * weights + index * scales..count * weights + (index + 1) * scales]; for &(_, row) in &self.requests[begin..end] { output[row * weights..(row + 1) * weights].copy_from_slice(w); - output[scale_base + row * scales..scale_base + (row + 1) * scales] - .copy_from_slice(s); + if scales > 0 { + output[scale_base + row * scales..scale_base + (row + 1) * scales] + .copy_from_slice(s); + } } } self.pending_commit = Some([weights, scales]); @@ -1145,10 +1196,11 @@ impl CachedReader { .fetch_add(evicted, Ordering::Relaxed); } - fn warm(&mut self, planes: &[Plane; 2], ids: &[i64]) -> Result { + fn warm(&mut self, planes: &Planes, ids: &[i64]) -> Result { self.clear_pending_commit(); - let [weights, scales] = planes.map(|plane| plane.row_bytes); - let limit = planes[0].nbytes / weights; + let weights = planes.weights.row_bytes; + let scales = planes.scale_row_bytes(); + let limit = planes.weights.nbytes / weights; let mut total_loaded = 0usize; for chunk in ids.chunks(self.max_rows) { self.miss_ids.clear(); @@ -1214,7 +1266,7 @@ impl CachedReader { enum Data { Disk(DiskReader), - Ram([Arc; 2]), + Ram(Arc, Option>), Cached(Box), } @@ -1264,7 +1316,7 @@ impl Reader { #[cfg(test)] fn open( path: &Path, - planes: &[Plane; 2], + planes: &Planes, resident: bool, cache_bytes: usize, max_rows: usize, @@ -1283,7 +1335,7 @@ impl Reader { } pub fn from_files( files: &[Arc], - planes: &[Plane; 2], + planes: &Planes, resident: bool, cache_bytes: usize, max_rows: usize, @@ -1298,15 +1350,23 @@ impl Reader { return Err("embedding plane references an unknown file".into()); } let data = if resident { - Data::Ram([ - Arc::new(Resident::load(&files[planes[0].file], planes[0])?), - Arc::new(Resident::load(&files[planes[1].file], planes[1])?), - ]) + Data::Ram( + Arc::new(Resident::load(&files[planes.weights.file], planes.weights)?), + planes + .scales + .map(|plane| Resident::load(&files[plane.file], plane).map(Arc::new)) + .transpose()?, + ) } else { let mut disk = DiskReader::from_files(files, stats.clone(), workers)?; if resident_scales { - disk.resident_scales = Some(Resident::load(&files[planes[1].file], planes[1])?); - stats.resident_scale_bytes.fetch_add(planes[1].resident_bytes()? as u64, Ordering::Relaxed); + if let Some(scale_plane) = planes.scales { + disk.resident_scales = Some(Resident::load(&files[scale_plane.file], scale_plane)?); + stats.resident_scale_bytes.fetch_add( + scale_plane.resident_bytes()? as u64, + Ordering::Relaxed, + ); + } } if cache_bytes != 0 { Data::Cached(Box::new(CachedReader::new( @@ -1322,14 +1382,18 @@ impl Reader { Ok(Self { data, stats }) } #[cfg(unix)] - pub(super) fn resident(data: [Arc; 2], stats: Arc) -> Self { + pub(super) fn resident( + weights: Arc, + scales: Option>, + stats: Arc, + ) -> Self { Self { - data: Data::Ram(data), + data: Data::Ram(weights, scales), stats, } } #[cfg(test)] - pub fn gather(&mut self, planes: &[Plane; 2], ids: &[i64], output: &mut [u8]) -> Result<()> { + pub fn gather(&mut self, planes: &Planes, ids: &[i64], output: &mut [u8]) -> Result<()> { if self.gather_into_output(planes, ids, output)? { self.commit_misses(); } @@ -1341,15 +1405,15 @@ impl Reader { /// call [`Self::commit_misses`] after signaling the consumer when this returns `Ok(true)`. pub fn gather_into_output( &mut self, - planes: &[Plane; 2], + planes: &Planes, ids: &[i64], output: &mut [u8], ) -> Result { self.clear_pending_commit(); - if output.len() != ids.len() * planes.iter().map(|p| p.row_bytes).sum::() { + if ids.len().checked_mul(planes.row_bytes()) != Some(output.len()) { return Err("Engram staging size differs from row count".into()); } - for plane in planes { + for plane in planes.iter() { if ids .iter() .any(|id| *id < -1 || (*id >= 0 && *id as usize >= plane.nbytes / plane.row_bytes)) @@ -1361,11 +1425,14 @@ impl Reader { let result = match &mut self.data { Data::Disk(reader) => reader.gather(planes, ids, output).map(|()| false), Data::Cached(reader) => reader.gather_into_output(planes, ids, output), - Data::Ram(data) => { - let mut base = 0; - for (plane, data) in planes.iter().zip(data) { + Data::Ram(weights, scales) => { + if planes.scales.is_some() != scales.is_some() { + return Err("Engram scale plane differs from resident storage".into()); + } + let base = ids.len() * planes.weights.row_bytes; + gather_resident(weights, planes.weights.row_bytes, ids, &mut output[..base]); + if let (Some(plane), Some(data)) = (planes.scales, scales) { gather_resident(data, plane.row_bytes, ids, &mut output[base..]); - base += ids.len() * plane.row_bytes; } Ok(false) } @@ -1379,7 +1446,7 @@ impl Reader { } /// Fetch missing advisory row IDs into the host row cache without staging GPU output. - pub fn warm(&mut self, planes: &[Plane; 2], ids: &[i64]) -> Result { + pub fn warm(&mut self, planes: &Planes, ids: &[i64]) -> Result { let Data::Cached(reader) = &mut self.data else { return Ok(0); }; @@ -1430,10 +1497,10 @@ mod tests { let root = std::env::temp_dir().join(format!("helios-engram-scales-{}", std::process::id())); std::fs::create_dir_all(&root).unwrap(); let rows = 4097; - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: 4093, nbytes: rows * weight_row_bytes, row_bytes: weight_row_bytes }, Plane { file: 1, offset: 4093, nbytes: rows * scale_row_bytes, row_bytes: scale_row_bytes }, - ]; + ); let row_bytes = weight_row_bytes + scale_row_bytes; let data: Vec> = planes.iter().map(|plane| { (0..plane.offset as usize + plane.nbytes).map(|i| (i * 19 + i / 257) as u8).collect() @@ -1447,7 +1514,7 @@ mod tests { } let stats = Arc::new(Stats::default()); let mut reader = Reader::from_files(&files, &planes, false, cache, 8, stats.clone(), 1, true).unwrap(); - assert_eq!(stats.resident_scale_bytes.load(Ordering::Relaxed), planes[1].resident_bytes().unwrap() as u64); + assert_eq!(stats.resident_scale_bytes.load(Ordering::Relaxed), planes.scales.unwrap().resident_bytes().unwrap() as u64); OpenOptions::new().write(true).open(root.join("1")).unwrap().set_len(0).unwrap(); for ids in [vec![0, 4096, -1, 0], vec![4096, 0, -1, 0], vec![17, -1, 19]] { let mut expected = Vec::new(); @@ -1586,7 +1653,7 @@ mod tests { .map(|i| (i * 19 + i / 7) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: 0, @@ -1599,26 +1666,39 @@ mod tests { nbytes: rows * 8, row_bytes: 8, }, - ]; + ); let file = open_file(&path).unwrap(); - let original = planes.map(|plane| Arc::new(Resident::load(&file, plane).unwrap())); - let shared = std::array::from_fn(|i| { + let original = ( + Arc::new(Resident::load(&file, planes.weights).unwrap()), + Some(Arc::new( + Resident::load(&file, planes.scales.unwrap()).unwrap(), + )), + ); + let shared = ( Arc::new( - Resident::from_shared(original[i].file.try_clone().unwrap(), planes[i]).unwrap(), - ) - }); + Resident::from_shared(original.0.file.try_clone().unwrap(), planes.weights) + .unwrap(), + ), + Some(Arc::new( + Resident::from_shared( + original.1.as_ref().unwrap().file.try_clone().unwrap(), + planes.scales.unwrap(), + ) + .unwrap(), + )), + ); std::fs::remove_file(path).unwrap(); let ids: Vec<_> = (0..128).map(|i| ((i * 509 + 17) % rows) as i64).collect(); let mut output = vec![0; ids.len() * 264]; let mut expected = Vec::with_capacity(output.len()); - for plane in &planes { + for plane in planes.iter() { for &id in &ids { let first = plane.offset as usize + id as usize * plane.row_bytes; expected.extend_from_slice(&bytes[first..first + plane.row_bytes]); } } - for data in [original, shared] { - let mut reader = Reader::resident(data, Arc::default()); + for (weights, scales) in [original, shared] { + let mut reader = Reader::resident(weights, scales, Arc::default()); // Prime the copy code and output storage without touching the selected table pages. reader.gather(&planes, &[0], &mut output[..264]).unwrap(); output.fill(0xA5); @@ -1689,7 +1769,7 @@ mod tests { .map(|i| (i * 13 + i / 257) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: first as u64, @@ -1702,9 +1782,9 @@ mod tests { nbytes: rows * 10, row_bytes: 10, }, - ]; + ); let file = open_file(&path).unwrap(); - for plane in planes { + for plane in planes.iter() { let data = Resident::load(&file, plane).unwrap(); let begin = plane.offset as usize; assert_eq!(data.bytes(), &bytes[begin..begin + plane.nbytes]); @@ -1716,7 +1796,7 @@ mod tests { .set_len((first + LOAD_CHUNK + 17) as u64) .unwrap(); assert!( - Resident::load(&file, planes[0]) + Resident::load(&file, planes.weights) .err() .unwrap() .to_string() @@ -1736,7 +1816,7 @@ mod tests { .map(|i| (i * 13 + i / 257) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: first as u64, @@ -1749,13 +1829,13 @@ mod tests { nbytes: rows * 10, row_bytes: 10, }, - ]; + ); let stats = Arc::new(Stats::default()); let mut reader = Reader::open(&path, &planes, false, 65536, 32, stats.clone()).unwrap(); assert!(stats.cache_bytes.load(Ordering::Relaxed) <= 65536); - fn check(reader: &mut Reader, planes: &[Plane; 2], bytes: &[u8], ids: &[i64]) { + fn check(reader: &mut Reader, planes: &Planes, bytes: &[u8], ids: &[i64]) { let mut expected = Vec::new(); - for plane in planes { + for plane in planes.iter() { for &id in ids { if id < 0 { expected.extend(std::iter::repeat_n(0, plane.row_bytes)); @@ -1805,7 +1885,7 @@ mod tests { .map(|i| (i * 13 + i / 257) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: first as u64, @@ -1818,7 +1898,7 @@ mod tests { nbytes: rows * 8, row_bytes: 8, }, - ]; + ); let ids: Vec<_> = (0..8192) .map(|i| { if i % 19 == 0 { @@ -1829,7 +1909,7 @@ mod tests { }) .collect(); let mut expected = Vec::new(); - for plane in &planes { + for plane in planes.iter() { for id in &ids { if *id == -1 { expected.extend(std::iter::repeat_n(0, plane.row_bytes)); @@ -1874,7 +1954,7 @@ mod tests { fn equal_offsets_in_separate_files_never_coalesce() { let root = std::env::temp_dir().join(format!("helios-engram-files-{}", std::process::id())); std::fs::create_dir_all(&root).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: 4093, @@ -1887,7 +1967,7 @@ mod tests { nbytes: 10 * 128, row_bytes: 10, }, - ]; + ); let mut files = Vec::new(); for (i, plane) in planes.iter().enumerate() { let path = root.join(i.to_string()); @@ -1929,7 +2009,7 @@ mod tests { .map(|i| (i * 31 + i / 127) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: first as u64, @@ -1942,7 +2022,7 @@ mod tests { nbytes: rows * 8, row_bytes: 8, }, - ]; + ); let ids: Vec = (0..PARALLEL_GATHER_MIN_ROWS * 3 + 77) .map(|i| { if i % 23 == 0 { @@ -1954,7 +2034,10 @@ mod tests { .collect(); let mut expected = vec![0u8; ids.len() * 264]; let file = open_file(&path).unwrap(); - let resident = planes.map(|plane| Arc::new(Resident::load(&file, plane).unwrap())); + let resident = [ + Arc::new(Resident::load(&file, planes.weights).unwrap()), + Arc::new(Resident::load(&file, planes.scales.unwrap()).unwrap()), + ]; gather_resident_slice( resident[0].bytes(), 256, @@ -1987,7 +2070,7 @@ mod tests { .map(|i| (i * 17 + i / 131) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: first as u64, @@ -2000,7 +2083,7 @@ mod tests { nbytes: rows * 8, row_bytes: 8, }, - ]; + ); // Exceed PARALLEL_GATHER_MIN_ROWS unique cached hits with duplicates and -1 padding. let ids: Vec = (0..PARALLEL_GATHER_MIN_ROWS * 2 + 113) .map(|i| { @@ -2012,7 +2095,7 @@ mod tests { }) .collect(); let mut expected = Vec::with_capacity(ids.len() * 264); - for plane in &planes { + for plane in planes.iter() { for &id in &ids { if id < 0 { expected.extend(std::iter::repeat_n(0, plane.row_bytes)); @@ -2054,7 +2137,7 @@ mod tests { .map(|i| (i * 19 + i / 257) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: first as u64, @@ -2067,7 +2150,7 @@ mod tests { nbytes: rows * 8, row_bytes: 8, }, - ]; + ); // Stride 300 rows = 76.8 KiB (> 64 KiB CHUNK), producing 150+ distinct disk reads (> DEPTH). let ids: Vec = (0..160) .flat_map(|i| { @@ -2080,7 +2163,7 @@ mod tests { }) .collect(); let mut expected = Vec::with_capacity(ids.len() * 264); - for plane in &planes { + for plane in planes.iter() { for &id in &ids { if id < 0 { expected.extend(std::iter::repeat_n(0, plane.row_bytes)); @@ -2226,7 +2309,7 @@ mod tests { .map(|i| (i * 23 + i / 97) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: first as u64, @@ -2239,7 +2322,7 @@ mod tests { nbytes: rows * 10, row_bytes: 10, }, - ]; + ); let stats = Arc::new(Stats::default()); let mut reader = Reader::open(&path, &planes, false, 65536, 32, stats.clone()).unwrap(); // Warm deduplicates, ignores out-of-range/negative sentinels, and loads misses into cache. @@ -2251,7 +2334,7 @@ mod tests { // Subsequent real gather hits 100% in RowCache with zero additional disk reads. let ids = [42, -1, 5, 19, 5]; let mut expected = Vec::new(); - for plane in &planes { + for plane in planes.iter() { for &id in &ids { if id < 0 { expected.extend(std::iter::repeat_n(0, plane.row_bytes)); @@ -2294,7 +2377,7 @@ mod tests { .map(|i| (i * 29 + i / 61) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: first as u64, @@ -2307,7 +2390,7 @@ mod tests { nbytes: rows * 10, row_bytes: 10, }, - ]; + ); let stats = Arc::new(Stats::default()); // Workspace max_rows = 8, but warm receives 24 unique IDs (3 workspace chunks). let mut reader = Reader::open(&path, &planes, false, 128 << 10, 8, stats.clone()).unwrap(); @@ -2356,7 +2439,7 @@ mod tests { .map(|i| (i * 17 + i / 251) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: first as u64, @@ -2369,13 +2452,13 @@ mod tests { nbytes: rows * 8, row_bytes: 8, }, - ]; + ); // Stride 300 rows = 76.8 KiB (> 64 KiB CHUNK). With resident scales, 80 IDs // produce 80 reads: above lane_depth = 32 (workers = 4) and 16 (workers = 8), // yet <= DEPTH (128). let ids: Vec = (0..80).map(|i| (i * 300) as i64).collect(); let mut expected = Vec::with_capacity(ids.len() * 264); - for plane in &planes { + for plane in planes.iter() { for &id in &ids { let start = plane.offset as usize + id as usize * plane.row_bytes; expected.extend_from_slice(&bytes[start..start + plane.row_bytes]); @@ -2448,4 +2531,70 @@ mod tests { Some(libc::EACCES) ); } + + #[test] + fn single_plane_bf16_gathers_across_disk_cache_ram_and_warm() { + let path = + std::env::temp_dir().join(format!("helios-engram-single-{}.bin", std::process::id())); + let rows = 32; + let row_bytes = 17920; // 8960 BF16 elements + let offset = 4093usize; + let bytes: Vec = (0..offset + rows * row_bytes) + .map(|i| ((i * 29 + i / 251) & 0xFF) as u8) + .collect(); + std::fs::write(&path, &bytes).unwrap(); + let planes = Planes::single(Plane { + file: 0, + offset: offset as u64, + nbytes: rows * row_bytes, + row_bytes, + }); + let ids = [0i64, 31, -1, 7, 31, 0]; + let mut expected = Vec::with_capacity(ids.len() * row_bytes); + for &id in &ids { + if id < 0 { + expected.extend(std::iter::repeat_n(0u8, row_bytes)); + } else { + let start = offset + id as usize * row_bytes; + expected.extend_from_slice(&bytes[start..start + row_bytes]); + } + } + + let files = [Arc::new(open_file(&path).unwrap())]; + for resident_scales in [false, true] { + let stats = Arc::new(Stats::default()); + let mut reader = + Reader::from_files(&files, &planes, false, 0, 8, stats.clone(), 2, resident_scales) + .unwrap(); + assert_eq!(stats.resident_scale_bytes.load(Ordering::Relaxed), 0); + let mut actual = vec![0xA5u8; expected.len()]; + reader.gather(&planes, &ids, &mut actual).unwrap(); + assert_eq!(actual, expected); + assert!(reader.gather(&planes, &[rows as i64], &mut vec![0; row_bytes]).is_err()); + assert!(reader.gather(&planes, &[-2], &mut vec![0; row_bytes]).is_err()); + } + + let stats = Arc::new(Stats::default()); + let mut cached = + Reader::from_files(&files, &planes, false, 2 << 20, 8, stats.clone(), 1, false) + .unwrap(); + assert_eq!(cached.warm(&planes, &[-1, 7, 31, 999]).unwrap(), 2); + let mut actual = vec![0xA5u8; expected.len()]; + cached.gather(&planes, &ids, &mut actual).unwrap(); + assert_eq!(actual, expected); + assert_eq!(stats.hits.load(Ordering::Relaxed), 2); + assert_eq!(stats.misses.load(Ordering::Relaxed), 1); + let misses_before = stats.misses.load(Ordering::Relaxed); + cached.gather(&planes, &ids, &mut actual).unwrap(); + assert_eq!(actual, expected); + assert_eq!(stats.misses.load(Ordering::Relaxed), misses_before); + + let mut ram = + Reader::from_files(&files, &planes, true, 0, 8, Arc::default(), 1, false).unwrap(); + let mut actual = vec![0xA5u8; expected.len()]; + ram.gather(&planes, &ids, &mut actual).unwrap(); + assert_eq!(actual, expected); + + std::fs::remove_file(path).unwrap(); + } } diff --git a/helios/src/engram/reader/windows.rs b/helios/src/engram/reader/windows.rs index 6b630dd8d..17fbd3d5f 100644 --- a/helios/src/engram/reader/windows.rs +++ b/helios/src/engram/reader/windows.rs @@ -207,6 +207,7 @@ impl Lane { #[cfg(test)] mod tests { use super::*; + use super::super::Planes; #[test] fn parallel_gathers_preserve_rows_and_recover_after_truncation() { @@ -223,7 +224,7 @@ mod tests { .map(|i| (i * 13 + i / 257) as u8) .collect(); std::fs::write(&path, &bytes).unwrap(); - let planes = [ + let planes = Planes::two( Plane { file: 0, offset: first as u64, @@ -236,7 +237,7 @@ mod tests { nbytes: rows * scale, row_bytes: scale, }, - ]; + ); let ids: Vec = (0..1025) .map(|i| { if i % 17 == 0 { @@ -266,7 +267,7 @@ mod tests { drop(file); let check = |reader: &mut Reader, ids: &[i64]| { let mut expected = Vec::new(); - for plane in planes { + for plane in planes.iter() { for &id in ids { if id < 0 { expected.extend(std::iter::repeat_n(0, plane.row_bytes)); @@ -318,12 +319,20 @@ mod tests { let rows = 2048; let width = 4109; let offset = 4093; - let planes = std::array::from_fn(|file| Plane { - file, - offset: offset as u64, - nbytes: rows * width, - row_bytes: width, - }); + let planes = Planes::two( + Plane { + file: 0, + offset: offset as u64, + nbytes: rows * width, + row_bytes: width, + }, + Plane { + file: 1, + offset: offset as u64, + nbytes: rows * width, + row_bytes: width, + }, + ); let paths: Vec<_> = (0..2) .map(|file| { std::env::temp_dir().join(format!( @@ -362,7 +371,7 @@ mod tests { drop(files); let check = |reader: &mut Reader, ids: &[i64]| { let mut expected = Vec::new(); - for plane in planes { + for plane in planes.iter() { for &id in ids { if id < 0 { expected.extend(std::iter::repeat_n(0, width)); diff --git a/helios/src/execution/threaded.rs b/helios/src/execution/threaded.rs index 61dbbe96b..fb7bbe365 100644 --- a/helios/src/execution/threaded.rs +++ b/helios/src/execution/threaded.rs @@ -1454,15 +1454,24 @@ mod tests { Shared::layout_fixture( Index { tables: vec![Table { - planes: [256, 8].map(|row_bytes| Plane { - file: rank, - offset: rank as u64 * 4096, - nbytes: (100 + rank) * row_bytes, - row_bytes, - }), + planes: crate::engram::Planes::two( + Plane { + file: rank, + offset: rank as u64 * 4096, + nbytes: (100 + rank) * 256, + row_bytes: 256, + }, + Plane { + file: rank, + offset: rank as u64 * 4096, + nbytes: (100 + rank) * 8, + row_bytes: 8, + }, + ), + partition: partitioned.then_some(rank), heads: 24, weights: "weights".into(), - scales: "scales".into(), + scales: Some("scales".into()), hashes: "hashes".into(), event: "ready".into(), request: Some("requests".into()), @@ -1587,15 +1596,24 @@ mod tests { Shared::layout_fixture( Index { tables: vec![Table { - planes: [256, 8].map(|row_bytes| Plane { - file: rank, - offset: rank as u64 * 4096, - nbytes: (100 + rank) * row_bytes, - row_bytes, - }), + planes: crate::engram::Planes::two( + Plane { + file: rank, + offset: rank as u64 * 4096, + nbytes: (100 + rank) * 256, + row_bytes: 256, + }, + Plane { + file: rank, + offset: rank as u64 * 4096, + nbytes: (100 + rank) * 8, + row_bytes: 8, + }, + ), + partition: partitioned.then_some(rank), heads: 24, weights: "weights".into(), - scales: "scales".into(), + scales: Some("scales".into()), hashes: "hashes".into(), event: "ready".into(), request: Some("requests".into()), diff --git a/helios/src/runtime_core/engram.rs b/helios/src/runtime_core/engram.rs index d45f187f7..a23144014 100644 --- a/helios/src/runtime_core/engram.rs +++ b/helios/src/runtime_core/engram.rs @@ -10,7 +10,7 @@ use super::{ }; use crate::{ Result, - engram::{Index, Plane, Table}, + engram::{Index, Plane, Planes, Table}, execution::GraphKind, }; use std::collections::HashSet; @@ -26,24 +26,39 @@ pub(super) fn spans( .map_or(index.ranks.len(), |c| c.world as usize); let mut result = Vec::new(); for table in index.engram.iter().flat_map(|e| &e.tables) { - validate_shards(table, world)?; + // Legacy pre-encoding `ModelIndex` fixtures leave `encoding == 0` with two planes. + let encoding = if table.encoding == wire::engram_table::Encoding::Unspecified as i32 { + wire::engram_table::Encoding::Fp8E4m3E8m0 as i32 + } else { + table.encoding + }; + let has_scales = crate::core::schema::engram_encoding_has_scales(encoding)?; + validate_shards(table, world, has_scales)?; if table.shards.is_empty() { - for span in [&table.weights, &table.scales] { - result.push(( - None, - span.as_ref() - .ok_or_else(|| invalid("missing table plane"))?, - )); + result.push(( + None, + table + .weights + .as_ref() + .ok_or_else(|| invalid("missing table plane"))?, + )); + if let Some(scales) = crate::core::schema::engram_scales(encoding, &table.scales)? { + result.push((None, scales)); } } else { for shard in &table.shards { if selected.is_none_or(|rank| rank == shard.rank as usize) { - for span in [&shard.weights, &shard.scales] { - result.push(( - Some(shard.rank as usize), - span.as_ref() - .ok_or_else(|| invalid("missing table partition plane"))?, - )); + result.push(( + Some(shard.rank as usize), + shard + .weights + .as_ref() + .ok_or_else(|| invalid("missing table partition plane"))?, + )); + if let Some(scales) = + crate::core::schema::engram_scales(encoding, &shard.scales)? + { + result.push((Some(shard.rank as usize), scales)); } } } @@ -52,7 +67,7 @@ pub(super) fn spans( Ok(result) } -fn validate_shards(table: &wire::EngramTable, world: usize) -> Result<()> { +fn validate_shards(table: &wire::EngramTable, world: usize, has_scales: bool) -> Result<()> { if table.shards.is_empty() { return Ok(()); } @@ -73,10 +88,16 @@ fn validate_shards(table: &wire::EngramTable, world: usize) -> Result<()> { end = end .checked_add(shard.rows) .ok_or_else(|| invalid("embedding partition overflow"))?; - // Sibling partitions absent from a rank-selective copy carry neither plane; the - // owning rank still requires both (decode and `spans` reject a missing plane). - if shard.weights.is_none() != shard.scales.is_none() { - return Err(invalid("missing embedding partition plane")); + if has_scales { + // Sibling partitions absent from a rank-selective copy carry neither plane; the + // owning rank still requires both (decode and `spans` reject a missing plane). + if shard.weights.is_none() != shard.scales.is_none() { + return Err(invalid("missing embedding partition plane")); + } + } else if shard.scales.is_some() { + return Err(invalid( + "single-plane embedding partition cannot carry scales", + )); } } if end != table.rows { @@ -112,12 +133,11 @@ pub(super) fn decode( let mut events = HashSet::new(); let mut tables = Vec::new(); for table in value.tables { - validate_shards(&table, world)?; let gpu = !table.request_buffer.is_empty(); let encoding = wire::engram_table::Encoding::try_from(table.encoding) .map_err(|_| invalid("unknown n-gram encoding"))?; let (width, block, row_bytes, scale_bytes) = match encoding { - wire::engram_table::Encoding::Fp8E4m3E8m0 => (256, 32, 256, 8), + wire::engram_table::Encoding::Fp8E4m3E8m0 => (256, 32, 256usize, Some(8usize)), wire::engram_table::Encoding::Nvfp4E4m3Global if table.global_scale.is_finite() && table.global_scale > 0.0 @@ -125,36 +145,56 @@ pub(super) fn decode( && table.embedding_width % 16 == 0 => { let width = table.embedding_width; - (width, 16, (width / 2) as usize, (width / 16) as usize) + (width, 16, (width / 2) as usize, Some((width / 16) as usize)) + } + wire::engram_table::Encoding::Bf16 + if table.embedding_width > 0 && table.global_scale.to_bits() == 0 => + { + let row_bytes = usize::try_from(table.embedding_width) + .ok() + .and_then(|width| width.checked_mul(2)) + .ok_or_else(|| invalid("BF16 embedding row width overflow"))?; + (table.embedding_width, 0, row_bytes, None) } _ => return Err(invalid("invalid n-gram encoding or global scale")), }; + let has_scales = scale_bytes.is_some(); + validate_shards(&table, world, has_scales)?; let geometry = table .hash .as_ref() .ok_or_else(|| invalid("n-gram table lacks hash geometry"))?; - let order = match wire::engram_hash::Method::try_from(geometry.method) { - Ok(wire::engram_hash::Method::XorModulo) if !value.token_map.is_empty() => 4, - Ok(wire::engram_hash::Method::EosXorModulo) if gpu && value.token_map.is_empty() => 3, + let method = wire::engram_hash::Method::try_from(geometry.method) + .map_err(|_| invalid("unsupported n-gram hash method or request source"))?; + let (order, heads) = match method { + wire::engram_hash::Method::XorModulo if !value.token_map.is_empty() => (Some(4usize), 24usize), + wire::engram_hash::Method::EosXorModulo if gpu && value.token_map.is_empty() => { + (Some(3usize), 16usize) + } + wire::engram_hash::Method::Identity if gpu && value.token_map.is_empty() => { + (None, 1usize) + } _ => return Err(invalid("unsupported n-gram hash method or request source")), }; - let heads = (order - 1) * 8; if !layers.insert(table.layer) || table.rows == 0 || table.embedding_width != width || table.scale_block != block || !events.insert(table.ready_event.clone()) || table.ready_event.is_empty() - || [ - &table.weight_buffer, - &table.scale_buffer, - &table.hash_buffer, - ] - .iter() - .any(|name| name.is_empty() || !buffers.insert((*name).clone())) + || [&table.weight_buffer, &table.hash_buffer] + .iter() + .any(|name| name.is_empty() || !buffers.insert((*name).clone())) { return Err(invalid("invalid Engram table encoding or bindings")); } + if has_scales { + if table.scale_buffer.is_empty() || !buffers.insert(table.scale_buffer.clone()) { + return Err(invalid("invalid Engram table encoding or bindings")); + } + } else if !table.scale_buffer.is_empty() || table.scales.is_some() { + return Err(invalid("single-plane Engram table cannot carry scale bindings")); + } if gpu && !buffers.insert(table.request_buffer.clone()) { return Err(invalid("n-gram mailbox aliases another binding")); } @@ -170,22 +210,31 @@ pub(super) fn decode( let geometry = table .hash .ok_or_else(|| invalid("Engram table lacks hash geometry"))?; - if geometry.orders != (2..=order as u32).flat_map(|n| [n; 8]).collect::>() - || geometry.multipliers.len() != order - || geometry.primes.len() != heads - || geometry.offsets.len() != heads - || geometry.multipliers.iter().any(|m| { - *m == 0 - || m.checked_mul(value.compressed_vocabulary as u64) - .is_none_or(|n| n > i64::MAX as u64) - }) - || geometry.primes.iter().zip(&geometry.offsets).any(|(p, o)| { - *p < 2 - || o.checked_add(*p) - .is_none_or(|n| n > table.rows || n > i64::MAX as u64) - }) + if let Some(order) = order { + if geometry.orders != (2..=order as u32).flat_map(|n| [n; 8]).collect::>() + || geometry.multipliers.len() != order + || geometry.primes.len() != heads + || geometry.offsets.len() != heads + || geometry.multipliers.iter().any(|m| { + *m == 0 + || m.checked_mul(value.compressed_vocabulary as u64) + .is_none_or(|n| n > i64::MAX as u64) + }) + || geometry.primes.iter().zip(&geometry.offsets).any(|(p, o)| { + *p < 2 + || o.checked_add(*p) + .is_none_or(|n| n > table.rows || n > i64::MAX as u64) + }) + { + return Err(invalid("invalid Engram hash geometry")); + } + } else if !geometry.orders.is_empty() + || !geometry.multipliers.is_empty() + || !geometry.primes.is_empty() + || !geometry.offsets.is_empty() + || value.compressed_vocabulary as u64 != table.rows { - return Err(invalid("invalid Engram hash geometry")); + return Err(invalid("invalid identity Engram geometry")); } let (stored_rows, weights, scales) = if table.shards.is_empty() { (table.rows, table.weights.clone(), table.scales.clone()) @@ -209,7 +258,10 @@ pub(super) fn decode( row_bytes, }) }; - let planes = [plane(weights, row_bytes)?, plane(scales, scale_bytes)?]; + let planes = Planes { + weights: plane(weights, row_bytes)?, + scales: scale_bytes.map(|bytes| plane(scales, bytes)).transpose()?, + }; let compact_heads = (gpu && !table.shards.is_empty() && world > 1 && heads % world == 0) .then_some(heads / world); let mut table_heads = heads; @@ -247,13 +299,16 @@ pub(super) fn decode( .checked_mul(core_heads as u64) .ok_or_else(|| invalid("Engram staging row count overflow"))?; let validate_buffer = |buffer: &wire::Buffer, dtype: &str, rows: u64, columns: u64| { + let [buf_rows, buf_cols] = match buffer.shape.as_slice() { + [r, c] => [*r, *c], + _ => return Err(invalid("invalid Engram buffer layout")), + }; let expected_nbytes = columns .checked_mul(if dtype == "int64" { 8 } else { 1 }) - .and_then(|row_bytes| buffer.shape[0].checked_mul(row_bytes)); + .and_then(|row_bytes| buf_rows.checked_mul(row_bytes)); if buffer.dtype != dtype - || buffer.shape.len() != 2 - || buffer.shape[0] < rows - || buffer.shape[1] != columns + || buf_rows < rows + || buf_cols != columns || buffer.strides != [columns, 1] || expected_nbytes != Some(buffer.nbytes) { @@ -262,10 +317,11 @@ pub(super) fn decode( Ok(()) }; validate_buffer(hash_buffer, "int64", tokens, core_heads as u64)?; - for (name, dtype, columns) in [ - (&table.weight_buffer, "uint8", row_bytes as u64), - (&table.scale_buffer, "uint8", scale_bytes as u64), - ] { + let mut required_buffers = vec![(&table.weight_buffer, "uint8", row_bytes as u64)]; + if let Some(bytes) = scale_bytes { + required_buffers.push((&table.scale_buffer, "uint8", bytes as u64)); + } + for (name, dtype, columns) in required_buffers { let buffer = execution .buffers .iter() @@ -352,9 +408,10 @@ pub(super) fn decode( } tables.push(Table { planes, + partition: (!table.shards.is_empty()).then_some(rank), heads: table_heads, weights: table.weight_buffer, - scales: table.scale_buffer, + scales: has_scales.then_some(table.scale_buffer), hashes: table.hash_buffer, event: table.ready_event, request: gpu.then_some(table.request_buffer), @@ -395,8 +452,8 @@ mod tests { #[test] fn table_partitions_cover_rows_exactly_once() { let table = partitioned(); - assert!(validate_shards(&table, 4).is_ok()); - assert!(validate_shards(&table, 2).is_err()); + assert!(validate_shards(&table, 4, true).is_ok()); + assert!(validate_shards(&table, 2, true).is_err()); for change in 0..7 { let mut invalid = table.clone(); match change { @@ -408,7 +465,10 @@ mod tests { 5 => invalid.shards[1].scales = None, _ => invalid.request_buffer.clear(), } - assert!(validate_shards(&invalid, 4).is_err(), "mutation {change}"); + assert!( + validate_shards(&invalid, 4, true).is_err(), + "mutation {change}" + ); } } @@ -419,13 +479,13 @@ mod tests { table.shards[rank].weights = None; table.shards[rank].scales = None; } - assert!(validate_shards(&table, 4).is_ok()); + assert!(validate_shards(&table, 4, true).is_ok()); let mut one_plane = table.clone(); one_plane.shards[0].weights = Some(wire::Span::default()); - assert!(validate_shards(&one_plane, 4).is_err()); + assert!(validate_shards(&one_plane, 4, true).is_err()); let mut gap = table; gap.shards[2].first_row += 1; - assert!(validate_shards(&gap, 4).is_err()); + assert!(validate_shards(&gap, 4, true).is_err()); } #[test] @@ -436,7 +496,7 @@ mod tests { ]; let table = wire::EngramTable::decode(bytes.as_slice()).unwrap(); assert!(table.shards.is_empty()); - assert!(validate_shards(&table, 4).is_ok()); + assert!(validate_shards(&table, 4, true).is_ok()); let index = wire::ModelIndex { ranks: vec![wire::BundleIndex::default(); 4], engram: Some(wire::Engram { @@ -795,6 +855,249 @@ mod tests { assert!(decode(gpu_cat, &archive, &[gpu_core], 0, 4).is_err()); } + #[test] + fn bf16_identity_single_plane_decodes_and_enforces_strict_contract() { + let archive = StubFiles::new(); + let rows = 64u64; + let width = 8960u32; + let row_bytes = width as u64 * 2; + let make = || { + let table = wire::EngramTable { + layer: 0, + rows, + embedding_width: width, + scale_block: 0, + weights: Some(wire::Span { + offset: 0, + nbytes: rows * row_bytes, + ..Default::default() + }), + scales: None, + hash: Some(wire::EngramHash { + method: wire::engram_hash::Method::Identity as i32, + ..Default::default() + }), + weight_buffer: "ple_weights".into(), + scale_buffer: String::new(), + hash_buffer: "ple_hashes".into(), + request_buffer: "ple_requests".into(), + prefetch_buffer: "ple_prefetch".into(), + ready_event: "ple_ready".into(), + encoding: wire::engram_table::Encoding::Bf16 as i32, + global_scale: 0.0, + ..Default::default() + }; + let catalog = wire::Engram { + token_map: vec![], + pad_token_id: 0, + compressed_vocabulary: rows as u32, + tables: vec![table], + }; + let core = Core { + resources: Default::default(), + architecture: [12, 0], + allocations: vec![ + super::super::format::Allocation { + name: "requests_alloc".into(), + nbytes: (128 + 1) * 8, + alignment: 4096, + file: None, + data_spans: vec![], + sources: vec![], + relocations: vec![], + address: None, + memory: Memory::MappedHost, + sizing: None, + }, + super::super::format::Allocation { + name: "prefetch_alloc".into(), + nbytes: (128 + 2) * 8, + alignment: 4096, + file: None, + data_spans: vec![], + sources: vec![], + relocations: vec![], + address: None, + memory: Memory::MappedHost, + sizing: None, + }, + ], + modules: vec![], + functions: vec![], + graphs: vec![], + reservations: vec![], + execution: Some(wire::Execution { + abi_version: 1, + completion_token_capacity: 8, + max_active: 1, + input_frame_bytes: 64, + buffers: vec![ + wire::Buffer { + name: "ple_hashes".into(), + dtype: "int64".into(), + shape: vec![128, 1], + strides: vec![1, 1], + nbytes: 128 * 8, + reference: None, + }, + wire::Buffer { + name: "ple_weights".into(), + dtype: "uint8".into(), + shape: vec![128, row_bytes], + strides: vec![row_bytes, 1], + nbytes: 128 * row_bytes, + reference: None, + }, + wire::Buffer { + name: "ple_requests".into(), + dtype: "int64".into(), + shape: vec![129], + strides: vec![1], + nbytes: 129 * 8, + reference: Some(wire::Reference { + allocation: "requests_alloc".into(), + offset: 0, + }), + }, + wire::Buffer { + name: "ple_prefetch".into(), + dtype: "int64".into(), + shape: vec![130], + strides: vec![1], + nbytes: 130 * 8, + reference: Some(wire::Reference { + allocation: "prefetch_alloc".into(), + offset: 0, + }), + }, + ], + graphs: vec![wire::ExecutionGraph { + name: "prefill128".into(), + kind: "prefill".into(), + batch_capacity: 1, + token_capacity: 128, + packed_token_capacity: 128, + ..Default::default() + }], + tuning_graphs: vec![], + persistent_workers: vec![], + async_transfers: vec![], + }), + context: Default::default(), + events: vec!["ple_ready".into()], + external_extents: vec![], + }; + (catalog, core) + }; + + let (catalog, core) = make(); + let decoded = decode(catalog.clone(), &archive, &[core], 0, 1).unwrap(); + assert_eq!(decoded.tables.len(), 1); + assert_eq!(decoded.tables[0].heads, 1); + assert_eq!(decoded.tables[0].planes.weights.row_bytes, row_bytes as usize); + assert!(decoded.tables[0].planes.scales.is_none()); + assert!(decoded.tables[0].scales.is_none()); + assert_eq!( + decoded.tables[0].prefetch, + Some(("ple_prefetch".into(), 128)) + ); + + let index = wire::ModelIndex { + ranks: vec![wire::BundleIndex::default()], + engram: Some(catalog), + ..Default::default() + }; + assert_eq!(spans(&index, Some(0)).unwrap().len(), 1); + + for (bad, needle) in [ + (0, "invalid Engram table encoding or bindings"), + (1, "invalid n-gram encoding or global scale"), + (2, "cannot carry scale bindings"), + (3, "cannot carry scale bindings"), + (4, "invalid identity Engram geometry"), + (5, "invalid n-gram encoding or global scale"), + (6, "invalid identity Engram geometry"), + ] { + let (mut cat, core) = make(); + match bad { + 0 => cat.tables[0].scale_block = 16, + 1 => cat.tables[0].global_scale = 1.0, + 2 => cat.tables[0].scale_buffer = "ple_scales".into(), + 3 => cat.tables[0].scales = Some(wire::Span { nbytes: 8, ..Default::default() }), + 4 => cat.tables[0].hash.as_mut().unwrap().primes = vec![61], + 5 => cat.tables[0].global_scale = -0.0, + _ => cat.compressed_vocabulary = 32, + } + let err = decode(cat, &archive, &[core], 0, 1).unwrap_err().to_string(); + assert!(err.contains(needle), "bad={bad}: expected {needle:?}, got {err:?}"); + } + + let (mut pcat, pcore) = make(); + let half_rows = rows / 2; + let half_bytes = half_rows * row_bytes; + pcat.tables[0].weights = None; + pcat.tables[0].shards = vec![ + wire::EngramTableShard { + rank: 0, + first_row: 0, + rows: half_rows, + weights: Some(wire::Span { + offset: 0, + nbytes: half_bytes, + ..Default::default() + }), + scales: None, + }, + wire::EngramTableShard { + rank: 1, + first_row: half_rows, + rows: half_rows, + weights: Some(wire::Span { + offset: half_bytes, + nbytes: half_bytes, + ..Default::default() + }), + scales: None, + }, + ]; + assert!(validate_shards(&pcat.tables[0], 2, false).is_ok()); + for rank in 0..2 { + let decoded = decode(pcat.clone(), &archive, std::slice::from_ref(&pcore), rank, 2).unwrap(); + assert_eq!(decoded.tables[0].partition, Some(rank)); + assert_eq!(decoded.tables[0].planes.weights.nbytes, half_bytes as usize); + assert!(decoded.tables[0].planes.scales.is_none()); + let pindex = wire::ModelIndex { + ranks: vec![wire::BundleIndex::default(); 2], + engram: Some(pcat.clone()), + ..Default::default() + }; + let rank_spans = spans(&pindex, Some(rank)).unwrap(); + assert_eq!(rank_spans.len(), 1); + assert_eq!(rank_spans[0].0, Some(rank)); + } + + // Identical shard spans on two ranks must remain distinct delivery groups. + let mut identical = pcat.clone(); + identical.tables[0].shards[1].weights = identical.tables[0].shards[0].weights.clone(); + let r0 = decode(identical.clone(), &archive, std::slice::from_ref(&pcore), 0, 2).unwrap(); + let r1 = decode(identical, &archive, std::slice::from_ref(&pcore), 1, 2).unwrap(); + assert!(!r0.shares_delivery_with(&r1)); + + let mut selective = pcat.clone(); + selective.tables[0].shards[1].weights = None; + assert!(validate_shards(&selective.tables[0], 2, false).is_ok()); + assert!(decode(selective, &archive, std::slice::from_ref(&pcore), 0, 2).is_ok()); + + let mut shard_scales = pcat.clone(); + shard_scales.tables[0].shards[0].scales = Some(wire::Span { nbytes: 8, ..Default::default() }); + assert!(validate_shards(&shard_scales.tables[0], 2, false).unwrap_err().to_string().contains("cannot carry scales")); + assert!(decode(shard_scales, &archive, std::slice::from_ref(&pcore), 0, 2).unwrap_err().to_string().contains("cannot carry scales")); + + let mut shard_bad_size = pcat; + shard_bad_size.tables[0].shards[1].weights.as_mut().unwrap().nbytes -= row_bytes; + assert!(decode(shard_bad_size, &archive, &[pcore], 1, 2).unwrap_err().to_string().contains("payload geometry mismatch")); + } + #[test] fn nvfp4_tables_accept_width_128_and_160_and_reject_unaligned_widths() { let archive = StubFiles::new(); @@ -833,8 +1136,8 @@ mod tests { for (width, row_bytes, scale_bytes) in [(128u32, 64u64, 8u64), (160, 80, 10)] { let (catalog, core) = make(width, row_bytes, scale_bytes); let decoded = decode(catalog, &archive, &[core], 0, 1).unwrap(); - assert_eq!(decoded.tables[0].planes[0].row_bytes, row_bytes as usize); - assert_eq!(decoded.tables[0].planes[1].row_bytes, scale_bytes as usize); + assert_eq!(decoded.tables[0].planes.weights.row_bytes, row_bytes as usize); + assert_eq!(decoded.tables[0].planes.scales.as_ref().unwrap().row_bytes, scale_bytes as usize); } for bad_width in [0u32, 8, 120] { diff --git a/helios/src/runtime_core/event_tests.rs b/helios/src/runtime_core/event_tests.rs index f81557e52..46fd759ff 100644 --- a/helios/src/runtime_core/event_tests.rs +++ b/helios/src/runtime_core/event_tests.rs @@ -126,7 +126,7 @@ fn disk_cached_and_resident_tables_feed_native_b12x_graphs() { .collect::>>() .unwrap(); if fail_read { - let file = tables.tables[0].planes[0].file; + let file = tables.tables[0].planes.weights.file; std::fs::copy(&weight_source, &failed_source).unwrap(); // Corrupt the private copy; snapshot payloads themselves remain read-only. #[cfg(unix)] diff --git a/helios/src/runtime_core/model.rs b/helios/src/runtime_core/model.rs index b8a48cb44..3a72c768c 100644 --- a/helios/src/runtime_core/model.rs +++ b/helios/src/runtime_core/model.rs @@ -455,7 +455,9 @@ impl NativeModel { rank, world, )?; - if let Some((_, ranks)) = engram.iter_mut().find(|(existing, _)| existing == &index) + if let Some((_, ranks)) = engram + .iter_mut() + .find(|(existing, _)| existing.shares_delivery_with(&index)) { ranks.push(local); } else { @@ -472,11 +474,11 @@ impl NativeModel { "embedding row cache requires an embedding table catalog", )); } - if options.embedding_table_resident_scales == Some(true) && engram.is_empty() { - return Err(invalid( - "resident embedding scales require an embedding table catalog", - )); - } + let has_scale_planes = engram + .iter() + .flat_map(|(index, _)| &index.tables) + .any(|table| table.planes.scales.is_some()); + options.validate_embedding_resident_scales(!engram.is_empty(), has_scale_planes)?; let ram = options.embedding_table_storage == Some(crate::engram::Storage::Ram); let engram_tokens = engram.iter().map(|(_, ranks)| { ranks.iter().flat_map(|rank| cores[*rank].execution.as_ref().unwrap().graphs.iter()) @@ -727,16 +729,17 @@ impl NativeModel { .collect::>>()?; agree.after_gpu_init(&pci_bus_ids)?; let embedding_table_resident_scales = options.embedding_resident_scales( - !engram.is_empty(), + has_scale_planes, model.ranks.iter().any(|rank| rank.integrated), ); let resident_bytes = engram .iter() .flat_map(|(index, _)| &index.tables) - .flat_map(|table| table.planes.iter().enumerate()) - .filter(|(ordinal, _)| { - ram || (embedding_table_resident_scales && *ordinal == 1) + .flat_map(|table| { + std::iter::once((false, table.planes.weights)) + .chain(table.planes.scales.map(|plane| (true, plane))) }) + .filter(|(is_scale, _)| ram || (embedding_table_resident_scales && *is_scale)) .try_fold(0u64, |bytes, (_, plane)| { bytes .checked_add(plane.resident_bytes()? as u64) @@ -854,7 +857,7 @@ impl NativeModel { let mut direct_files = Vec::new(); for (index, _) in &mut engram { for table in &mut index.tables { - for plane in &mut table.planes { + for plane in table.planes.iter_mut() { let target = match mapped_files.entry(plane.file) { std::collections::btree_map::Entry::Occupied(entry) => { *entry.get() diff --git a/helios/src/runtime_core/selection.rs b/helios/src/runtime_core/selection.rs index 8edcc624c..cc9bf23f1 100644 --- a/helios/src/runtime_core/selection.rs +++ b/helios/src/runtime_core/selection.rs @@ -53,8 +53,28 @@ impl LoadOptions { .unwrap_or(if cfg!(windows) { 4 } else { 1 }) } - pub(super) fn embedding_resident_scales(&self, has_tables: bool, integrated: bool) -> bool { - has_tables + pub(super) fn validate_embedding_resident_scales( + &self, + has_tables: bool, + has_scale_planes: bool, + ) -> Result<()> { + if self.embedding_table_resident_scales == Some(true) { + if !has_tables { + return Err(invalid( + "resident embedding scales require an embedding table catalog", + )); + } + if !has_scale_planes { + return Err(invalid( + "resident embedding scales require an embedding table with a scale plane", + )); + } + } + Ok(()) + } + + pub(super) fn embedding_resident_scales(&self, has_scale_planes: bool, integrated: bool) -> bool { + has_scale_planes && self.embedding_table_storage.unwrap_or_default() == crate::engram::Storage::Disk && self.embedding_table_resident_scales.unwrap_or(!integrated) } @@ -1036,6 +1056,15 @@ mod tests { storage != Some(Storage::Ram) && override_value.unwrap_or(!integrated) ); } + assert_eq!( + options.validate_embedding_resident_scales(false, false).is_ok(), + override_value != Some(true) + ); + assert_eq!( + options.validate_embedding_resident_scales(true, false).is_ok(), + override_value != Some(true) + ); + assert!(options.validate_embedding_resident_scales(true, true).is_ok()); } } } diff --git a/ignition/preparation/rank_group.py b/ignition/preparation/rank_group.py index 43c8c4084..7ece425d0 100644 --- a/ignition/preparation/rank_group.py +++ b/ignition/preparation/rank_group.py @@ -41,6 +41,25 @@ def minimum_across_ranks(value, group): return result.item() +def _receive_embedding_tables(control, model, catalog, count): + from multiprocessing.reduction import recv_handle + + expected = sum(len(table["planes"]) for table in catalog["tables"]) + if count != expected: + raise ValueError("shared embedding descriptor count differs from its catalog") + descriptors = [] + try: + for _ in range(count): + descriptors.append(recv_handle(control)) + # Equal catalogs share physical RAM. Disjoint table partitions load their + # own checkpoint spans and have independent delivery mailboxes. + model.prepare_embedding_tables(descriptors=descriptors if catalog == model.embedding_catalog else None) + finally: + for descriptor in descriptors: + os.close(descriptor) + control.send("embedding_tables_ready") + + def _peer(parent, snapshot, config, rank, rendezvous, connection, control, prepare, exporting, recording, extra_roots=()): import flare_heliopause @@ -79,22 +98,8 @@ def _peer(parent, snapshot, config, rank, rendezvous, connection, control, prepa control.send(model.memory_report) command = control.recv() if isinstance(command, tuple) and command[0] == "embedding_tables": - from multiprocessing.reduction import recv_handle - _, catalog, count = command - if count != 2 * len(catalog["tables"]): - raise ValueError("shared embedding descriptor count differs from its catalog") - descriptors = [] - try: - for _ in range(count): - descriptors.append(recv_handle(control)) - # Equal catalogs share physical RAM. Disjoint table partitions load their - # own checkpoint spans and have independent delivery mailboxes. - model.prepare_embedding_tables(descriptors=descriptors if catalog == model.embedding_catalog else None) - finally: - for descriptor in descriptors: - os.close(descriptor) - control.send("embedding_tables_ready") + _receive_embedding_tables(control, model, catalog, count) command = control.recv() release_export = False if isinstance(command, tuple) and command[0] == "export": diff --git a/ignition/preparation/runtime_core_pb2.py b/ignition/preparation/runtime_core_pb2.py index 3bac9c05e..43a69ec0a 100644 --- a/ignition/preparation/runtime_core_pb2.py +++ b/ignition/preparation/runtime_core_pb2.py @@ -2,7 +2,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # NO CHECKED-IN PROTOBUF GENCODE # source: runtime_core.proto -# Protobuf Python Version: 7.36.1 +# Protobuf Python Version: 7.35.1 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -12,7 +12,7 @@ _runtime_version.ValidateProtobufRuntimeVersion( _runtime_version.Domain.PUBLIC, 7, - 36, + 35, 1, '', 'runtime_core.proto' @@ -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\"\x88\x01\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\x12\x0c\n\x04open\x18\x04 \x01(\t\x12\r\n\x05\x63lose\x18\x05 \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\"\xf0\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\x12\x35\n\x0f\x61sync_transfers\x18\t \x03(\x0b\x32\x1c.flare.runtime.AsyncTransfer\"\xb1\x02\n\rAsyncTransfer\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x0b\x64\x65vice_pool\x18\x02 \x01(\t\x12)\n\x07\x63ontrol\x18\x03 \x01(\x0b\x32\x18.flare.runtime.Reference\x12\x15\n\rcontrol_bytes\x18\x04 \x01(\x04\x12\x34\n\x12\x64\x65vice_completions\x18\x05 \x01(\x0b\x32\x18.flare.runtime.Reference\x12\x18\n\x10\x63ompletion_slots\x18\x06 \x01(\r\x12\x15\n\rring_capacity\x18\x07 \x01(\r\x12\x1b\n\x13max_host_pool_bytes\x18\x08 \x01(\x04\x12\x11\n\talignment\x18\t \x01(\r\x12$\n\x07\x65xtents\x18\n \x03(\x0b\x32\x13.flare.runtime.Span\"\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*\xb2\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\x12\x0f\n\x0bTAGGED_JSON\x10\t*\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*9\n\x08\x43\x61pacity\x12\x0e\n\nSTATE_ROWS\x10\x00\x12\x0c\n\x08KV_PAGES\x10\x01\x12\x0f\n\x0b\x44\x45VICE_POOL\x10\x02*-\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\"\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\"\x88\x01\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\x12\x0c\n\x04open\x18\x04 \x01(\t\x12\r\n\x05\x63lose\x18\x05 \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\"\xa3\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\"O\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\x12\x08\n\x04\x42\x46\x31\x36\x10\x03\"\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\"\xd1\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\"K\n\x06Method\x12\x0f\n\x0bUNSPECIFIED\x10\x00\x12\x0e\n\nXOR_MODULO\x10\x01\x12\x12\n\x0e\x45OS_XOR_MODULO\x10\x02\x12\x0c\n\x08IDENTITY\x10\x03\"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\"\xf0\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\x12\x35\n\x0f\x61sync_transfers\x18\t \x03(\x0b\x32\x1c.flare.runtime.AsyncTransfer\"\xb1\x02\n\rAsyncTransfer\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x0b\x64\x65vice_pool\x18\x02 \x01(\t\x12)\n\x07\x63ontrol\x18\x03 \x01(\x0b\x32\x18.flare.runtime.Reference\x12\x15\n\rcontrol_bytes\x18\x04 \x01(\x04\x12\x34\n\x12\x64\x65vice_completions\x18\x05 \x01(\x0b\x32\x18.flare.runtime.Reference\x12\x18\n\x10\x63ompletion_slots\x18\x06 \x01(\r\x12\x15\n\rring_capacity\x18\x07 \x01(\r\x12\x1b\n\x13max_host_pool_bytes\x18\x08 \x01(\x04\x12\x11\n\talignment\x18\t \x01(\r\x12$\n\x07\x65xtents\x18\n \x03(\x0b\x32\x13.flare.runtime.Span\"\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*\xb2\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\x12\x0f\n\x0bTAGGED_JSON\x10\t*\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*9\n\x08\x43\x61pacity\x12\x0e\n\nSTATE_ROWS\x10\x00\x12\x0c\n\x08KV_PAGES\x10\x01\x12\x0f\n\x0b\x44\x45VICE_POOL\x10\x02*-\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=16736 - _globals['_PREPARATIONPARAMETERSCOPE']._serialized_end=16986 - _globals['_HISTORYKIND']._serialized_start=16989 - _globals['_HISTORYKIND']._serialized_end=17131 - _globals['_VALUESOURCE']._serialized_start=17134 - _globals['_VALUESOURCE']._serialized_end=18101 - _globals['_INPUTINDEXING']._serialized_start=18103 - _globals['_INPUTINDEXING']._serialized_end=18227 - _globals['_STATEACCESSKIND']._serialized_start=18229 - _globals['_STATEACCESSKIND']._serialized_end=18313 - _globals['_GRAPHOPERATION']._serialized_start=18316 - _globals['_GRAPHOPERATION']._serialized_end=18583 - _globals['_TOOLPARSERKIND']._serialized_start=18586 - _globals['_TOOLPARSERKIND']._serialized_end=18764 - _globals['_REASONINGPARSERKIND']._serialized_start=18767 - _globals['_REASONINGPARSERKIND']._serialized_end=18933 - _globals['_IMAGEPREPARATIONKIND']._serialized_start=18936 - _globals['_IMAGEPREPARATIONKIND']._serialized_end=19308 - _globals['_IMAGELAYOUTKIND']._serialized_start=19311 - _globals['_IMAGELAYOUTKIND']._serialized_end=19621 - _globals['_PROMPTENCODER']._serialized_start=19623 - _globals['_PROMPTENCODER']._serialized_end=19703 - _globals['_TEMPLATEENCODING']._serialized_start=19705 - _globals['_TEMPLATEENCODING']._serialized_end=19771 - _globals['_MEMORY']._serialized_start=19773 - _globals['_MEMORY']._serialized_end=19820 - _globals['_CAPACITY']._serialized_start=19822 - _globals['_CAPACITY']._serialized_end=19879 - _globals['_RELOCATIONKIND']._serialized_start=19881 - _globals['_RELOCATIONKIND']._serialized_end=19926 - _globals['_DRAFTSOURCE']._serialized_start=19928 - _globals['_DRAFTSOURCE']._serialized_end=19980 + _globals['_PREPARATIONPARAMETERSCOPE']._serialized_start=16760 + _globals['_PREPARATIONPARAMETERSCOPE']._serialized_end=17010 + _globals['_HISTORYKIND']._serialized_start=17013 + _globals['_HISTORYKIND']._serialized_end=17155 + _globals['_VALUESOURCE']._serialized_start=17158 + _globals['_VALUESOURCE']._serialized_end=18125 + _globals['_INPUTINDEXING']._serialized_start=18127 + _globals['_INPUTINDEXING']._serialized_end=18251 + _globals['_STATEACCESSKIND']._serialized_start=18253 + _globals['_STATEACCESSKIND']._serialized_end=18337 + _globals['_GRAPHOPERATION']._serialized_start=18340 + _globals['_GRAPHOPERATION']._serialized_end=18607 + _globals['_TOOLPARSERKIND']._serialized_start=18610 + _globals['_TOOLPARSERKIND']._serialized_end=18788 + _globals['_REASONINGPARSERKIND']._serialized_start=18791 + _globals['_REASONINGPARSERKIND']._serialized_end=18957 + _globals['_IMAGEPREPARATIONKIND']._serialized_start=18960 + _globals['_IMAGEPREPARATIONKIND']._serialized_end=19332 + _globals['_IMAGELAYOUTKIND']._serialized_start=19335 + _globals['_IMAGELAYOUTKIND']._serialized_end=19645 + _globals['_PROMPTENCODER']._serialized_start=19647 + _globals['_PROMPTENCODER']._serialized_end=19727 + _globals['_TEMPLATEENCODING']._serialized_start=19729 + _globals['_TEMPLATEENCODING']._serialized_end=19795 + _globals['_MEMORY']._serialized_start=19797 + _globals['_MEMORY']._serialized_end=19844 + _globals['_CAPACITY']._serialized_start=19846 + _globals['_CAPACITY']._serialized_end=19903 + _globals['_RELOCATIONKIND']._serialized_start=19905 + _globals['_RELOCATIONKIND']._serialized_end=19950 + _globals['_DRAFTSOURCE']._serialized_start=19952 + _globals['_DRAFTSOURCE']._serialized_end=20004 _globals['_PROTECTEDINDEX']._serialized_start=38 _globals['_PROTECTEDINDEX']._serialized_end=191 _globals['_SIGNEDGROUP']._serialized_start=193 @@ -178,81 +178,81 @@ _globals['_ENGRAM']._serialized_start=10948 _globals['_ENGRAM']._serialized_end=11072 _globals['_ENGRAMTABLE']._serialized_start=11075 - _globals['_ENGRAMTABLE']._serialized_end=11612 + _globals['_ENGRAMTABLE']._serialized_end=11622 _globals['_ENGRAMTABLE_ENCODING']._serialized_start=11543 - _globals['_ENGRAMTABLE_ENCODING']._serialized_end=11612 - _globals['_ENGRAMTABLESHARD']._serialized_start=11615 - _globals['_ENGRAMTABLESHARD']._serialized_end=11755 - _globals['_ENGRAMHASH']._serialized_start=11758 - _globals['_ENGRAMHASH']._serialized_end=11953 - _globals['_ENGRAMHASH_METHOD']._serialized_start=11892 - _globals['_ENGRAMHASH_METHOD']._serialized_end=11953 - _globals['_ASSET']._serialized_start=11955 - _globals['_ASSET']._serialized_end=12030 - _globals['_BUNDLEINDEX']._serialized_start=12033 - _globals['_BUNDLEINDEX']._serialized_end=12628 - _globals['_BUNDLEINDEX_RESOURCESENTRY']._serialized_start=12559 - _globals['_BUNDLEINDEX_RESOURCESENTRY']._serialized_end=12628 - _globals['_ROCETRANSPORT']._serialized_start=12631 - _globals['_ROCETRANSPORT']._serialized_end=12879 - _globals['_GRAPHINDEX']._serialized_start=12881 - _globals['_GRAPHINDEX']._serialized_end=12999 - _globals['_PEERMEMORY']._serialized_start=13001 - _globals['_PEERMEMORY']._serialized_end=13078 - _globals['_CONTEXT']._serialized_start=13080 - _globals['_CONTEXT']._serialized_end=13157 - _globals['_LIMIT']._serialized_start=13159 - _globals['_LIMIT']._serialized_end=13193 - _globals['_RESERVATION']._serialized_start=13195 - _globals['_RESERVATION']._serialized_end=13241 - _globals['_SPAN']._serialized_start=13243 - _globals['_SPAN']._serialized_end=13299 - _globals['_ALLOCATION']._serialized_start=13302 - _globals['_ALLOCATION']._serialized_end=13592 - _globals['_SIZING']._serialized_start=13594 - _globals['_SIZING']._serialized_end=13682 - _globals['_MODULE']._serialized_start=13684 - _globals['_MODULE']._serialized_end=13760 - _globals['_GLOBAL']._serialized_start=13762 - _globals['_GLOBAL']._serialized_end=13864 - _globals['_FUNCTION']._serialized_start=13866 - _globals['_FUNCTION']._serialized_end=13987 - _globals['_FUNCTIONATTRIBUTE']._serialized_start=13989 - _globals['_FUNCTIONATTRIBUTE']._serialized_end=14035 - _globals['_REFERENCE']._serialized_start=14037 - _globals['_REFERENCE']._serialized_end=14084 - _globals['_RELOCATION']._serialized_start=14086 - _globals['_RELOCATION']._serialized_end=14201 - _globals['_BLOB']._serialized_start=14203 - _globals['_BLOB']._serialized_end=14271 - _globals['_ATTRIBUTE']._serialized_start=14273 - _globals['_ATTRIBUTE']._serialized_end=14332 - _globals['_KERNEL']._serialized_start=14335 - _globals['_KERNEL']._serialized_end=14492 - _globals['_MEMSET']._serialized_start=14495 - _globals['_MEMSET']._serialized_end=14633 - _globals['_COPY']._serialized_start=14635 - _globals['_COPY']._serialized_end=14746 - _globals['_EMPTY']._serialized_start=14748 - _globals['_EMPTY']._serialized_end=14755 - _globals['_EVENTWAIT']._serialized_start=14757 - _globals['_EVENTWAIT']._serialized_end=14783 - _globals['_NODE']._serialized_start=14786 - _globals['_NODE']._serialized_end=15011 - _globals['_EDGE']._serialized_start=15013 - _globals['_EDGE']._serialized_end=15070 - _globals['_EXECUTION']._serialized_start=15073 - _globals['_EXECUTION']._serialized_end=15441 - _globals['_ASYNCTRANSFER']._serialized_start=15444 - _globals['_ASYNCTRANSFER']._serialized_end=15749 - _globals['_PERSISTENTWORKER']._serialized_start=15752 - _globals['_PERSISTENTWORKER']._serialized_end=15921 - _globals['_TUNINGGRAPH']._serialized_start=15923 - _globals['_TUNINGGRAPH']._serialized_end=15990 - _globals['_BUFFER']._serialized_start=15993 - _globals['_BUFFER']._serialized_end=16123 - _globals['_EXECUTIONGRAPH']._serialized_start=16126 - _globals['_EXECUTIONGRAPH']._serialized_end=16659 - _globals['_INPUTBINDING']._serialized_start=16661 - _globals['_INPUTBINDING']._serialized_end=16733 + _globals['_ENGRAMTABLE_ENCODING']._serialized_end=11622 + _globals['_ENGRAMTABLESHARD']._serialized_start=11625 + _globals['_ENGRAMTABLESHARD']._serialized_end=11765 + _globals['_ENGRAMHASH']._serialized_start=11768 + _globals['_ENGRAMHASH']._serialized_end=11977 + _globals['_ENGRAMHASH_METHOD']._serialized_start=11902 + _globals['_ENGRAMHASH_METHOD']._serialized_end=11977 + _globals['_ASSET']._serialized_start=11979 + _globals['_ASSET']._serialized_end=12054 + _globals['_BUNDLEINDEX']._serialized_start=12057 + _globals['_BUNDLEINDEX']._serialized_end=12652 + _globals['_BUNDLEINDEX_RESOURCESENTRY']._serialized_start=12583 + _globals['_BUNDLEINDEX_RESOURCESENTRY']._serialized_end=12652 + _globals['_ROCETRANSPORT']._serialized_start=12655 + _globals['_ROCETRANSPORT']._serialized_end=12903 + _globals['_GRAPHINDEX']._serialized_start=12905 + _globals['_GRAPHINDEX']._serialized_end=13023 + _globals['_PEERMEMORY']._serialized_start=13025 + _globals['_PEERMEMORY']._serialized_end=13102 + _globals['_CONTEXT']._serialized_start=13104 + _globals['_CONTEXT']._serialized_end=13181 + _globals['_LIMIT']._serialized_start=13183 + _globals['_LIMIT']._serialized_end=13217 + _globals['_RESERVATION']._serialized_start=13219 + _globals['_RESERVATION']._serialized_end=13265 + _globals['_SPAN']._serialized_start=13267 + _globals['_SPAN']._serialized_end=13323 + _globals['_ALLOCATION']._serialized_start=13326 + _globals['_ALLOCATION']._serialized_end=13616 + _globals['_SIZING']._serialized_start=13618 + _globals['_SIZING']._serialized_end=13706 + _globals['_MODULE']._serialized_start=13708 + _globals['_MODULE']._serialized_end=13784 + _globals['_GLOBAL']._serialized_start=13786 + _globals['_GLOBAL']._serialized_end=13888 + _globals['_FUNCTION']._serialized_start=13890 + _globals['_FUNCTION']._serialized_end=14011 + _globals['_FUNCTIONATTRIBUTE']._serialized_start=14013 + _globals['_FUNCTIONATTRIBUTE']._serialized_end=14059 + _globals['_REFERENCE']._serialized_start=14061 + _globals['_REFERENCE']._serialized_end=14108 + _globals['_RELOCATION']._serialized_start=14110 + _globals['_RELOCATION']._serialized_end=14225 + _globals['_BLOB']._serialized_start=14227 + _globals['_BLOB']._serialized_end=14295 + _globals['_ATTRIBUTE']._serialized_start=14297 + _globals['_ATTRIBUTE']._serialized_end=14356 + _globals['_KERNEL']._serialized_start=14359 + _globals['_KERNEL']._serialized_end=14516 + _globals['_MEMSET']._serialized_start=14519 + _globals['_MEMSET']._serialized_end=14657 + _globals['_COPY']._serialized_start=14659 + _globals['_COPY']._serialized_end=14770 + _globals['_EMPTY']._serialized_start=14772 + _globals['_EMPTY']._serialized_end=14779 + _globals['_EVENTWAIT']._serialized_start=14781 + _globals['_EVENTWAIT']._serialized_end=14807 + _globals['_NODE']._serialized_start=14810 + _globals['_NODE']._serialized_end=15035 + _globals['_EDGE']._serialized_start=15037 + _globals['_EDGE']._serialized_end=15094 + _globals['_EXECUTION']._serialized_start=15097 + _globals['_EXECUTION']._serialized_end=15465 + _globals['_ASYNCTRANSFER']._serialized_start=15468 + _globals['_ASYNCTRANSFER']._serialized_end=15773 + _globals['_PERSISTENTWORKER']._serialized_start=15776 + _globals['_PERSISTENTWORKER']._serialized_end=15945 + _globals['_TUNINGGRAPH']._serialized_start=15947 + _globals['_TUNINGGRAPH']._serialized_end=16014 + _globals['_BUFFER']._serialized_start=16017 + _globals['_BUFFER']._serialized_end=16147 + _globals['_EXECUTIONGRAPH']._serialized_start=16150 + _globals['_EXECUTIONGRAPH']._serialized_end=16683 + _globals['_INPUTBINDING']._serialized_start=16685 + _globals['_INPUTBINDING']._serialized_end=16757 # @@protoc_insertion_point(module_scope) diff --git a/tests/preparation/test_embedding_table_handoff.py b/tests/preparation/test_embedding_table_handoff.py index c47c4d943..019f27b7a 100644 --- a/tests/preparation/test_embedding_table_handoff.py +++ b/tests/preparation/test_embedding_table_handoff.py @@ -4,16 +4,22 @@ """Every peer must acknowledge resident table setup before native graph handoff.""" from types import SimpleNamespace +import os -from ignition.preparation.rank_group import PreparedRankGroup +import pytest + +from ignition.preparation.rank_group import PreparedRankGroup, _receive_embedding_tables def test_rank_setup_waits_for_all_table_mappings_before_starting_execution(monkeypatch): import multiprocessing.reduction actions = [] - catalog = {"vocabulary": 32, "tables": [object()]} - resident = SimpleNamespace(descriptors=[31, 32], nbytes=2048) + catalog = { + "vocabulary": 32, + "tables": [{"planes": [{}, {}]}, {"planes": [{}]}], + } + resident = SimpleNamespace(descriptors=[31, 32, 33], nbytes=3072) class Control: def __init__(self, rank): @@ -55,5 +61,29 @@ def unexpected_abort(message): mapped = [actions.index((rank, "mapped")) for rank in (1, 2)] for rank in (1, 2): assert actions.index((rank, "serve")) > max(mapped) + assert (rank, ("embedding_tables", catalog, 3)) in actions + assert [item for r, item in actions if r == rank and isinstance(item, tuple) and len(item) == 2] == [ + (31, 100 + rank), + (32, 100 + rank), + (33, 100 + rank), + ] assert actions.index((0, "executing")) > max(mapped) assert actions[0] == (0, "loaded") + + received = [] + closed = [] + queued = iter([41, 42, 43]) + peer_sent = [] + peer_control = SimpleNamespace(send=peer_sent.append) + peer_model = SimpleNamespace( + embedding_catalog=catalog, + prepare_embedding_tables=lambda descriptors=None: received.append(list(descriptors)), + ) + monkeypatch.setattr(multiprocessing.reduction, "recv_handle", lambda _ctrl: next(queued)) + monkeypatch.setattr(os, "close", closed.append) + _receive_embedding_tables(peer_control, peer_model, catalog, 3) + assert received == [[41, 42, 43]] + assert closed == [41, 42, 43] + assert peer_sent == ["embedding_tables_ready"] + with pytest.raises(ValueError, match="descriptor count differs"): + _receive_embedding_tables(peer_control, peer_model, catalog, 4)