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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/core-format-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ 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`
file. Every host receives the full table; local ranks share
independent of TP size; single-plane encodings such as `BF16` and
`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
its graph requests use canonical full-table row IDs on every rank. A core
Expand Down
81 changes: 74 additions & 7 deletions heliopause/src/export/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4410,6 +4410,9 @@ mod payload_export_tests {
let bf16_shared_weights = vec![0x77; 32];
let bf16_shard0_weights = vec![0x88; 16];
let bf16_shard1_weights = vec![0x99; 16];
let fp8_shared_weights = vec![0xaa; 16];
let fp8_shard0_weights = vec![0xbb; 8];
let fp8_shard1_weights = vec![0xcc; 8];
for (name, bytes) in [
("shared-w.bin", &shared_weights),
("shared-s.bin", &shared_scales),
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-shared-w.bin", &fp8_shared_weights),
("fp8-shard0-w.bin", &fp8_shard0_weights),
("fp8-shard1-w.bin", &fp8_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,
global_scale: 0.005126953125,
weights: Some(wire::Span { offset: 13064, nbytes: fp8_shared_weights.len() as u64, ..Default::default() }),
hash: Some(wire::EngramHash { method: wire::engram_hash::Method::XorModulo as i32, ..Default::default() }),
weight_buffer: "fp8_shared_weights".into(),
hash_buffer: "fp8_shared_hashes".into(),
ready_event: "fp8_shared_ready".into(),
encoding: wire::engram_table::Encoding::Fp8E4m3Global as i32,
request_buffer: "fp8_shared_requests".into(),
..Default::default()
},
wire::EngramTable {
layer: 6,
rows: 2,
embedding_width: 8,
global_scale: 0.005126953125,
hash: Some(wire::EngramHash { method: wire::engram_hash::Method::XorModulo as i32, ..Default::default() }),
weight_buffer: "fp8_part_weights".into(),
hash_buffer: "fp8_part_hashes".into(),
ready_event: "fp8_part_ready".into(),
encoding: wire::engram_table::Encoding::Fp8E4m3Global as i32,
request_buffer: "fp8_part_requests".into(),
shards: vec![
wire::EngramTableShard {
rank: 0, first_row: 0, rows: 1, scales: None,
weights: Some(wire::Span { offset: 13080, nbytes: fp8_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_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-shared-w.bin", fp8_shared_weights.len()),
(13080, "fp8-shard0-w.bin", fp8_shard0_weights.len()),
(13088, "fp8-shard1-w.bin", fp8_shard1_weights.len()),
] {
rank.payload.push(FilePart {
offset,
Expand All @@ -4587,18 +4633,18 @@ 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();
if bad_idx % 2 == 0 {
bad_engram.tables[bad_idx].scales = bad_engram.tables[bad_idx].weights.clone();
} else {
bad_engram.tables[3].shards[0].scales =
bad_engram.tables[3].shards[0].weights.clone();
bad_engram.tables[bad_idx].shards[0].scales =
bad_engram.tables[bad_idx].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 +4660,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 +4682,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.005126953125);
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.005126953125);

let read_use = |use_: &pwire::PayloadUse| -> Vec<u8> {
assert_eq!(use_.role, pwire::PayloadRole::Weights as i32);
Expand Down Expand Up @@ -4697,6 +4752,18 @@ mod payload_export_tests {
read_use(bf16_part.shards[1].weights.as_ref().unwrap()),
bf16_shard1_weights
);
assert_eq!(
read_use(fp8_shared.weights.as_ref().unwrap()),
fp8_shared_weights
);
assert_eq!(
read_use(fp8_part.shards[0].weights.as_ref().unwrap()),
fp8_shard0_weights
);
assert_eq!(
read_use(fp8_part.shards[1].weights.as_ref().unwrap()),
fp8_shard1_weights
);
let _ = fs::remove_dir_all(&base);
}

Expand Down
5 changes: 4 additions & 1 deletion helios/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,10 @@ 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`) and a 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 FP8 E4M3 rows of nonzero `embedding_width` with no scale plane (`scale_block == 0`) and a 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 FP8 E4M3 rows of nonzero `embedding_width` with no scale plane (`scale_block == 0`) and a 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
134 changes: 122 additions & 12 deletions helios/src/core/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,10 @@ 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 +501,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 +558,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 +575,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 +619,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 +2064,108 @@ mod tests {
assert_err(&shard_with_scales, 2, "cannot carry scales plane");
}

#[test]
fn validates_single_plane_fp8_global_engram_table() {
let mut catalog = Catalog::new();
let rows = 4u64;
let width = 128u32;
let nbytes = rows * u64::from(width);
let half = (rows / 2) * u64::from(width);
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; 16],
multipliers: vec![1, 3, 5],
primes: vec![2; 16],
offsets: vec![0; 16],
}),
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.25,
..Default::default()
};
let engram = wire::Engram {
token_map: vec![],
pad_token_id: 248044,
compressed_vocabulary: 248320,
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:?}");
};

for bad_scale in [0.0f32, -0.25, 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 bad_block = engram.clone();
bad_block.tables[0].scale_block = 16;
assert_err(&bad_block, 1, "cannot carry scale metadata");

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_scales = engram.clone();
with_scales.tables[0].scales = Some(use_(2, 64));
assert_err(&with_scales, 1, "cannot carry scales plane");

let mut bad_size = engram.clone();
bad_size.tables[0].weights = Some(use_(1, nbytes - 1));
assert_err(&bad_size, 1, "plane size mismatch");

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;
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
Loading