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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/cli-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ 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
in the catalog carries a scale plane (such as single-plane `BF16` or `FP8_E4M3_GLOBAL` 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
Expand Down
2 changes: 1 addition & 1 deletion docs/core-format-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ for byte-distinct layouts required by selected deployments.
Offloaded DeepSeek Engram and Qwen PLE tables are stored separately from ordinary
weight groups. Each full two-plane table uses `weights/engram-<index>-weights.safetensors`
and `weights/engram-<index>-scales.safetensors`, with checkpoint row ordering
independent of TP size; single-plane encodings such as `BF16` omit the `-scales`
independent of TP size; single-plane encodings (`BF16`, `FP8_E4M3_GLOBAL`) 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
Expand Down
68 changes: 64 additions & 4 deletions heliopause/src/export/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4409,6 +4409,9 @@ mod payload_export_tests {
let shard1_scales = vec![0x66; 8];
let bf16_shared_weights = vec![0x77; 32];
let bf16_shard0_weights = vec![0x88; 16];
let fp8_global_shared_weights = vec![34u8; 16];
let fp8_global_shard0_weights = vec![35u8; 8];
let fp8_global_shard1_weights = vec![36u8; 8];
let bf16_shard1_weights = vec![0x99; 16];
for (name, bytes) in [
("shared-w.bin", &shared_weights),
Expand All @@ -4420,6 +4423,9 @@ mod payload_export_tests {
("bf16-shared-w.bin", &bf16_shared_weights),
("bf16-shard0-w.bin", &bf16_shard0_weights),
("bf16-shard1-w.bin", &bf16_shard1_weights),
("fp8-global-shared-w.bin", &fp8_global_shared_weights),
("fp8-global-shard0-w.bin", &fp8_global_shard0_weights),
("fp8-global-shard1-w.bin", &fp8_global_shard1_weights),
] {
fs::write(sources.join(name), bytes).unwrap();
}
Expand Down Expand Up @@ -4551,6 +4557,43 @@ mod payload_export_tests {
],
..Default::default()
},
wire::EngramTable {
layer: 5,
rows: 2,
embedding_width: 8,
weights: Some(wire::Span { offset: 13064, nbytes: fp8_global_shared_weights.len() as u64, ..Default::default() }),
hash: Some(wire::EngramHash { method: wire::engram_hash::Method::XorModulo as i32, ..Default::default() }),
weight_buffer: "fp8_global_shared_weights".into(),
hash_buffer: "fp8_global_shared_hashes".into(),
ready_event: "fp8_global_shared_ready".into(),
encoding: wire::engram_table::Encoding::Fp8E4m3Global as i32,
request_buffer: "fp8_global_shared_requests".into(),
global_scale: 0.015625,
..Default::default()
},
wire::EngramTable {
layer: 6,
rows: 2,
embedding_width: 8,
hash: Some(wire::EngramHash { method: wire::engram_hash::Method::XorModulo as i32, ..Default::default() }),
weight_buffer: "fp8_global_part_weights".into(),
hash_buffer: "fp8_global_part_hashes".into(),
ready_event: "fp8_global_part_ready".into(),
encoding: wire::engram_table::Encoding::Fp8E4m3Global as i32,
request_buffer: "fp8_global_part_requests".into(),
global_scale: 0.015625,
shards: vec![
wire::EngramTableShard {
rank: 0, first_row: 0, rows: 1, scales: None,
weights: Some(wire::Span { offset: 13080, nbytes: fp8_global_shard0_weights.len() as u64, ..Default::default() }),
},
wire::EngramTableShard {
rank: 1, first_row: 1, rows: 1, scales: None,
weights: Some(wire::Span { offset: 13088, nbytes: fp8_global_shard1_weights.len() as u64, ..Default::default() }),
},
],
..Default::default()
},
],
});
for (offset, name, nbytes) in [
Expand All @@ -4563,6 +4606,9 @@ mod payload_export_tests {
(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()),
(13064, "fp8-global-shared-w.bin", fp8_global_shared_weights.len()),
(13080, "fp8-global-shard0-w.bin", fp8_global_shard0_weights.len()),
(13088, "fp8-global-shard1-w.bin", fp8_global_shard1_weights.len()),
] {
rank.payload.push(FilePart {
offset,
Expand All @@ -4587,18 +4633,23 @@ mod payload_export_tests {
&mut leases,
)
.unwrap();
assert_eq!(installed.len(), 9);
assert_eq!(installed.len(), 12);
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] {
for bad_idx in [2usize, 3usize, 4usize, 5usize] {
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 {
} else if bad_idx == 3 {
bad_engram.tables[3].shards[0].scales =
bad_engram.tables[3].shards[0].weights.clone();
} else if bad_idx == 4 {
bad_engram.tables[4].scales = bad_engram.tables[4].weights.clone();
} else {
bad_engram.tables[5].shards[0].scales =
bad_engram.tables[5].shards[0].weights.clone();
}
assert!(core_engram(&bad_engram, &rank.payload, &assembly, "gb202-tp2-bad", &mut Vec::new(), None, &mut BTreeMap::new()).is_err());
}
Expand All @@ -4614,7 +4665,7 @@ mod payload_export_tests {
let deployment = pwire::DeploymentBody::decode(envelope.deployments[0].body.as_slice())
.unwrap();
let engram = deployment.engram.unwrap();
assert_eq!(engram.tables.len(), 4);
assert_eq!(engram.tables.len(), 6);
let shared = &engram.tables[0];
assert!(shared.weights.is_some() && shared.scales.is_some());
assert!(shared.shards.is_empty());
Expand All @@ -4636,6 +4687,15 @@ mod payload_export_tests {
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 fp8_shared = &engram.tables[4];
assert!(fp8_shared.weights.is_some() && fp8_shared.scales.is_none());
assert!(fp8_shared.shards.is_empty());
assert_eq!(fp8_shared.global_scale, 0.015625);
let fp8_part = &engram.tables[5];
assert!(fp8_part.weights.is_none() && fp8_part.scales.is_none());
assert_eq!(fp8_part.shards.len(), 2);
assert!(fp8_part.shards.iter().all(|s| s.scales.is_none()));
assert_eq!(fp8_part.global_scale, 0.015625);

let read_use = |use_: &pwire::PayloadUse| -> Vec<u8> {
assert_eq!(use_.role, pwire::PayloadRole::Weights as i32);
Expand Down
4 changes: 3 additions & 1 deletion helios/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,9 @@ 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
`global_scale == 0`). Single-plane `FP8_E4M3_GLOBAL` tables store raw
`embedding_width`-byte FP8 E4M3 rows without a scale plane (`scales` absent,
`scale_buffer` empty, `scale_block == 0`, finite positive `global_scale`). 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
Expand Down
3 changes: 2 additions & 1 deletion helios/proto/core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ message Engram {

message EngramTable {
// 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; }
// FP8_E4M3_GLOBAL stores raw float8_e4m3 rows of nonzero `embedding_width` with no scale plane (`scale_block == 0`, finite positive `global_scale`).
enum Encoding { UNSPECIFIED = 0; FP8_E4M3_E8M0 = 1; NVFP4_E4M3_GLOBAL = 2; BF16 = 3; FP8_E4M3_GLOBAL = 4; }
uint32 layer = 1;
uint64 rows = 2;
uint32 embedding_width = 3;
Expand Down
3 changes: 2 additions & 1 deletion helios/proto/runtime_core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ message Engram {
}
message EngramTable {
// 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; }
// FP8_E4M3_GLOBAL stores raw float8_e4m3 rows of nonzero `embedding_width` with no scale plane (`scale_block == 0`, finite positive `global_scale`).
enum Encoding { UNSPECIFIED = 0; FP8_E4M3_E8M0 = 1; NVFP4_E4M3_GLOBAL = 2; BF16 = 3; FP8_E4M3_GLOBAL = 4; }
uint32 layer = 1;
uint64 rows = 2;
uint32 embedding_width = 3;
Expand Down
133 changes: 121 additions & 12 deletions helios/src/core/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,9 @@ pub fn engram_encoding_has_scales(encoding: i32) -> Result<bool> {
wire::engram_table::Encoding::Fp8E4m3E8m0
| wire::engram_table::Encoding::Nvfp4E4m3Global,
) => Ok(true),
Ok(wire::engram_table::Encoding::Bf16) => Ok(false),
Ok(wire::engram_table::Encoding::Bf16 | wire::engram_table::Encoding::Fp8E4m3Global) => {
Ok(false)
}
_ => Err(invalid("engram table has no encoding")),
}
}
Expand Down Expand Up @@ -498,11 +500,14 @@ fn validate_engram(engram: &wire::Engram, ranks: u32, catalog: &Catalog) -> Resu
bounded_name(&table.weight_buffer, 64, "engram weight 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
{
} else if !table.scale_buffer.is_empty() || table.scale_block != 0 {
return Err(invalid("single-plane engram table cannot carry scale metadata"));
} else if table.encoding == wire::engram_table::Encoding::Bf16 as i32 {
if table.global_scale.to_bits() != 0 {
return Err(invalid("single-plane engram table cannot carry scale metadata"));
}
} else if !table.global_scale.is_finite() || table.global_scale <= 0.0 {
return Err(invalid("FP8 global engram table requires a finite positive global scale"));
}
if !table.prefetch_buffer.is_empty() {
if table.request_buffer.is_empty() {
Expand Down Expand Up @@ -552,12 +557,14 @@ fn validate_engram(engram: &wire::Engram, ranks: u32, catalog: &Catalog) -> Resu
{
return Err(invalid("engram hash head arrays disagree"));
}
let bf16_row_bytes = if table.encoding == wire::engram_table::Encoding::Bf16 as i32 {
let single_plane_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 if table.encoding == wire::engram_table::Encoding::Fp8E4m3Global as i32 {
Some(u64::from(table.embedding_width))
} else {
None
};
Expand All @@ -567,13 +574,13 @@ fn validate_engram(engram: &wire::Engram, ranks: u32, catalog: &Catalog) -> Resu
.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 {
if let Some(row_bytes) = single_plane_row_bytes {
let expected = table
.rows
.checked_mul(row_bytes)
.ok_or_else(|| invalid("BF16 engram plane size overflow"))?;
.ok_or_else(|| invalid("single-plane engram plane size overflow"))?;
if weights.slice.as_ref().map(|slice| slice.nbytes) != Some(expected) {
return Err(invalid("BF16 engram plane size mismatch"));
return Err(invalid("single-plane engram plane size mismatch"));
}
}
if let Some(scales) = engram_scales(table.encoding, &table.scales)? {
Expand Down Expand Up @@ -611,13 +618,13 @@ fn validate_engram(engram: &wire::Engram, ranks: u32, catalog: &Catalog) -> Resu
.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 {
if let Some(row_bytes) = single_plane_row_bytes {
let expected = shard
.rows
.checked_mul(row_bytes)
.ok_or_else(|| invalid("BF16 engram partition size overflow"))?;
.ok_or_else(|| invalid("single-plane engram partition size overflow"))?;
if weights.slice.as_ref().map(|slice| slice.nbytes) != Some(expected) {
return Err(invalid("BF16 engram partition size mismatch"));
return Err(invalid("single-plane engram partition size mismatch"));
}
}
if let Some(scales) = engram_scales(table.encoding, &shard.scales)? {
Expand Down Expand Up @@ -2056,6 +2063,108 @@ mod tests {
assert_err(&shard_with_scales, 2, "cannot carry scales plane");
}

#[test]
fn validate_engram_accepts_and_checks_single_plane_fp8_global() {
let rows = 4u64;
let width = 160u32;
let nbytes = rows * u64::from(width);
let half = (rows / 2) * u64::from(width);
let mut catalog = Catalog::new();
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: 1,
rows,
embedding_width: width,
scale_block: 0,
weights: Some(use_(1, nbytes)),
scales: None,
hash: Some(wire::EngramHash {
method: wire::engram_hash::Method::EosXorModulo as i32,
orders: vec![2],
multipliers: vec![1, 3],
primes: vec![3],
offsets: vec![0],
}),
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::Fp8E4m3Global as i32,
global_scale: 0.015625,
..Default::default()
};
let engram = wire::Engram {
token_map: vec![],
pad_token_id: 0,
compressed_vocabulary: 256,
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, nbytes / 2));
assert_err(&bad_size, 1, "plane size mismatch");

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_block = engram.clone();
with_block.tables[0].scale_block = 16;
assert_err(&with_block, 1, "cannot carry scale metadata");

for bad_scale in [0.0f32, -0.5, f32::NAN, f32::INFINITY] {
let mut bad = engram.clone();
bad.tables[0].global_scale = bad_scale;
assert_err(&bad, 1, "finite positive global scale");
}

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 bad_shard_bytes = partitioned.clone();
bad_shard_bytes.tables[0].shards[0].weights = Some(use_(3, u64::from(width)));
assert_err(&bad_shard_bytes, 2, "partition size mismatch");
}

#[test]
fn peer_memory_requires_owner_inclusive_unique_readers_and_unique_addresses() {
let peer = |owner, address, readers| runtime::PeerMemory {
Expand Down
Loading