Skip to content

Commit bf5353d

Browse files
kyonjovaclaude
andauthored
Report conversion phases while ignition convert verifies and writes a core (#223)
`ignition convert` printed nothing until it finished. Converting a two-host core of about 178 GB to packed form hashes every payload and copies every byte, so the command stayed silent for minutes with no sign of whether it was verifying, writing, or stuck, while `ignition export` reports each of its native steps as a phase row with elapsed time and byte counts. Conversion also read the stored payloads twice before writing: opening the verified core hashed every payload, and pack and unpack then hashed the same payloads again. Reporting verification as its own phase requires the hashing to happen in one place, and the second pass checked nothing the first had not. Native pack and unpack gain `pack_with` and `unpack_with`, which take a `StartupProgress` and report four phases. `Verify core` validates the metadata structure, the commitment digests, and the presence of every selected payload, and finishes with the detail `metadata and commitments`. It authenticates no signature: conversion needs no key, and the loader authenticates signatures before serving. `Verify stored data` hashes each located payload once against its signed identity and counts payload bytes. `Write packed core` and `Write core companions` count every byte written to the destination. A forwarding writer reports each write of the primary container and of each companion, and the expected total comes from the layout planner that `Writer::finish` itself uses, so the total includes the header length field, the padded header, and the alignment padding as well as the payloads. The last phase publishes the destination. The convert binding passes the standard error row reporter that export uses. `pack`, `unpack`, and their selected variants keep their signatures and report silently; the cache, combine, and promote paths are unchanged. In unit-test builds a progress observation also records the final snapshot of each completed phase; other builds retain the latest snapshot only. `docs/cli-design.md` states what each phase checks and counts. The core format, the metadata, and the bytes the container writer emits are unchanged. A terminal shows a redrawing bar for each phase and a redirected log gets a progress line every ten seconds. A finished write phase reports a total, a completed count, and a detail that all equal the size of the files it produced. Verification reads the stored payloads once instead of twice: on a DGX Spark a core of 180.5 GB verified in 47 s, where a core of 178.1 GB took 45 s and 47 s in the two passes of an earlier revision. On an x86 host without a GPU, `cargo test --locked --lib --features runtime-core,server core::conversion::` passes its 52 tests. One packs and unpacks a signed fixture under an observed reporter and asserts each phase's label and detail, that the stored-data total and completed count equal the located payload bytes, and that each write phase's total, completed count, and detail equal the size on disk of the packed file or of the unpacked directory. A second repeats the write assertions for tensors whose lengths force alignment padding. A third confirms that the reporting forms write the same bytes as the silent forms. A container written from five tensors with misaligned lengths, and four companion headers, hashed identically before and after the writer moved to the shared planner. On a DGX Spark (GB10), a build that contains this change converted a two-rank GLM 5.3 Flash export to packed form. `Verify core` finished in under 0.1 s with the detail `metadata and commitments`, `Verify stored data` hashed 180,523,902,823 source bytes in 47.2 s, `Write packed core` wrote 180,528,104,976 bytes in 146.7 s, and publication took 6.9 s. The command's summary line reported the same 180,528,104,976 bytes. The earlier two-pass timing comes from a different core, a two-rank MiMo V2.6 Flash RL export of 178,122,320,431 source bytes, so the comparison is between cores of similar size and not a repeat of one conversion. Unpack to directory form at that size, and conversion of a core whose signature is invalid, have not been run on hardware. Design-Signed-Off-By: Claude Fable 5.2 (Claude Code); design-review=ed22 Signed-off-by: Kyonjova <kyonjova@pm.me> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 949966b commit bf5353d

6 files changed

Lines changed: 551 additions & 100 deletions

File tree

‎docs/cli-design.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,16 @@ Export always writes the directory canonical form in the cache.
10631063
single-file core; `ignition convert CACHE_ENTRY --output DIR` writes a
10641064
standalone directory. `CACHE_ENTRY` is the path printed by export. Both forms use
10651065
the same metadata, payloads, signatures, and location records. Converting between them
1066-
needs no signing key or GPU. `--output` refuses an existing destination. A
1066+
needs no signing key or GPU. Conversion reports its work as the export does, on
1067+
standard error with elapsed time and byte counts: `Verify core`, `Verify stored
1068+
data`, `Write packed core` or `Write core companions`, and the final
1069+
publication of the destination. `Verify core` checks the metadata structure,
1070+
the commitment digests, and that every selected payload is present; conversion
1071+
does not authenticate signatures, which the loader does. `Verify stored data`
1072+
hashes each payload once against its signed identity and counts payload bytes.
1073+
The write phases count every byte written to the destination, including
1074+
container headers and alignment padding, so a finished write phase reports the
1075+
size of the files it produced. `--output` refuses an existing destination. A
10671076
destination on another filesystem is assembled by copying bytes, so those files
10681077
share no storage with the cache; a destination on the cache's filesystem shares
10691078
inodes where it can. Payload-format cores keep the semantic payload boundaries their export declared. No

‎heliopause/src/export/conversion.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ fn export_payload_convert(
4141
) -> PyResult<String> {
4242
py.detach(|| {
4343
let (source, destination) = (Path::new(&source), Path::new(&destination));
44+
// Verification and copying of a large core take minutes; report them as the
45+
// export does, on standard error, and keep standard output for the result lines.
46+
let progress = helios_core::startup::StartupProgress::stderr_rows();
4447
match form.as_str() {
45-
"packed" => helios_core::core::conversion::pack(source, destination)?,
46-
"directory" => helios_core::core::conversion::unpack(source, destination)?,
48+
"packed" => helios_core::core::conversion::pack_with(source, destination, None, &progress)?,
49+
"directory" => {
50+
helios_core::core::conversion::unpack_with(source, destination, None, &progress)?
51+
}
4752
other => {
4853
return Err(super::invalid(format!(
4954
"unknown payload core form {other:?}"

‎helios/src/core/container.rs‎

Lines changed: 176 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -399,60 +399,140 @@ impl<'a, W: Write> Writer<'a, W> {
399399
}
400400

401401
pub fn finish(mut self) -> Result<()> {
402-
let mut cursor = 0u64;
403-
let mut layout: Vec<(String, u64, u64, Source<'a>)> =
404-
Vec::with_capacity(self.entries.len());
405-
let mut padding = 0usize;
406-
for (name, len, source) in std::mem::take(&mut self.entries) {
407-
let pad = (ALIGNMENT - cursor % ALIGNMENT) % ALIGNMENT;
408-
if pad > 0 {
409-
let name = loop {
410-
let candidate = format!("{ALIGNMENT_PREFIX}{padding:06}");
411-
padding += 1;
412-
if !self.names.contains(&candidate) {
413-
break candidate;
414-
}
415-
};
416-
self.names.insert(name.clone());
417-
layout.push((name, cursor, pad, Source::Zero(pad)));
418-
cursor += pad;
402+
let names: Vec<(String, u64)> = self
403+
.entries
404+
.iter()
405+
.map(|(name, len, _)| (name.clone(), *len))
406+
.collect();
407+
let planned = planned_layout(&self.format, &names, &mut self.names)?;
408+
let mut writes: Vec<(String, u64, Source<'a>)> = Vec::with_capacity(planned.entries.len());
409+
let mut sources = std::mem::take(&mut self.entries).into_iter();
410+
for entry in planned.entries {
411+
if entry.alignment {
412+
writes.push((entry.name, entry.len, Source::Zero(entry.len)));
413+
} else {
414+
let source = sources
415+
.next()
416+
.map(|(_, _, source)| source)
417+
.ok_or_else(|| invalid("container layout lost a tensor source"))?;
418+
writes.push((entry.name, entry.len, source));
419419
}
420-
layout.push((name, cursor, len, source));
421-
cursor = cursor
422-
.checked_add(len)
423-
.ok_or_else(|| invalid("container payload overflow"))?;
424-
}
425-
if cursor == 0 {
426-
return Err(invalid("container requires at least one payload tensor"));
427420
}
428-
let header = header_bytes(&self.format, &layout)?;
429421
self.output
430-
.write_all(&((header.len() as u64).to_le_bytes()))
422+
.write_all(&(planned.header.len() as u64).to_le_bytes())
431423
.map_err(|e| io("write container header length", e))?;
432424
self.output
433-
.write_all(&header)
425+
.write_all(&planned.header)
434426
.map_err(|e| io("write container header", e))?;
435427
let mut buffer = vec![0u8; IO_CHUNK];
436-
for (name, _, len, mut source) in layout {
428+
for (name, len, mut source) in writes {
437429
write_source(&mut self.output, &name, len, &mut source, &mut buffer)?;
438430
}
439431
self.output.flush().map_err(|e| io("flush container", e))
440432
}
441433
}
442434

443-
fn header_json(format: &str, layout: &[(String, u64, u64, Source<'_>)]) -> Result<Vec<u8>> {
435+
/// One tensor in the deterministic write order of a container.
436+
struct PlannedEntry {
437+
name: String,
438+
offset: u64,
439+
len: u64,
440+
/// Whether the writer inserts this entry as zero padding between payloads.
441+
alignment: bool,
442+
}
443+
444+
struct PlannedLayout {
445+
entries: Vec<PlannedEntry>,
446+
/// The padded header, whose length the container stores in its first
447+
/// eight bytes.
448+
header: Vec<u8>,
449+
/// Every byte the writer emits: the header length field, the padded
450+
/// header, and all tensor bytes.
451+
total: u64,
452+
}
453+
454+
/// The deterministic write order and size of a container with these tensors in
455+
/// this order. Shared by the writer and by callers that must predict a
456+
/// container's written size exactly; a caller passes the tensor names it will
457+
/// add, in the order it will add them. Padding entries take names outside
458+
/// `reserved`. `Writer::add` rejects tensor names with the alignment prefix, so
459+
/// the padding names, and with them the header length, are the same whether
460+
/// `reserved` holds the tensor names or is empty.
461+
fn planned_layout(
462+
format: &str,
463+
entries: &[(String, u64)],
464+
reserved: &mut BTreeSet<String>,
465+
) -> Result<PlannedLayout> {
466+
let mut cursor = 0u64;
467+
let mut layout: Vec<PlannedEntry> = Vec::with_capacity(entries.len() + 1);
468+
let mut padding = 0usize;
469+
for (name, len) in entries {
470+
let pad = (ALIGNMENT - cursor % ALIGNMENT) % ALIGNMENT;
471+
if pad > 0 {
472+
let name = loop {
473+
let candidate = format!("{ALIGNMENT_PREFIX}{padding:06}");
474+
padding += 1;
475+
if !reserved.contains(&candidate) {
476+
break candidate;
477+
}
478+
};
479+
reserved.insert(name.clone());
480+
layout.push(PlannedEntry {
481+
name,
482+
offset: cursor,
483+
len: pad,
484+
alignment: true,
485+
});
486+
cursor = cursor
487+
.checked_add(pad)
488+
.ok_or_else(|| invalid("container payload overflow"))?;
489+
}
490+
layout.push(PlannedEntry {
491+
name: name.clone(),
492+
offset: cursor,
493+
len: *len,
494+
alignment: false,
495+
});
496+
cursor = cursor
497+
.checked_add(*len)
498+
.ok_or_else(|| invalid("container payload overflow"))?;
499+
}
500+
if cursor == 0 {
501+
return Err(invalid("container requires at least one payload tensor"));
502+
}
503+
let header = header_bytes(format, &layout)?;
504+
let total = 8u64
505+
.checked_add(header.len() as u64)
506+
.and_then(|prefix| prefix.checked_add(cursor))
507+
.ok_or_else(|| invalid("container payload overflow"))?;
508+
Ok(PlannedLayout {
509+
entries: layout,
510+
header,
511+
total,
512+
})
513+
}
514+
515+
/// The exact number of bytes `Writer::finish` writes for these tensors in this
516+
/// order: the header length field, the padded header, and every tensor byte
517+
/// including the alignment padding the writer inserts.
518+
pub(crate) fn written_size(format: &str, tensors: &[(String, u64)]) -> Result<u64> {
519+
planned_layout(format, tensors, &mut BTreeSet::new()).map(|planned| planned.total)
520+
}
521+
522+
fn header_json(format: &str, layout: &[PlannedEntry]) -> Result<Vec<u8>> {
444523
let mut tensors: BTreeMap<String, serde_json::Value> = BTreeMap::new();
445524
tensors.insert(
446525
"__metadata__".into(),
447526
serde_json::json!({ "format": format }),
448527
);
449-
for (name, offset, len, _) in layout {
450-
let end = offset
451-
.checked_add(*len)
528+
for entry in layout {
529+
let end = entry
530+
.offset
531+
.checked_add(entry.len)
452532
.ok_or_else(|| invalid("container tensor overflow"))?;
453533
tensors.insert(
454-
name.clone(),
455-
serde_json::json!({ "dtype": "U8", "shape": [len], "data_offsets": [offset, end] }),
534+
entry.name.clone(),
535+
serde_json::json!({ "dtype": "U8", "shape": [entry.len], "data_offsets": [entry.offset, end] }),
456536
);
457537
}
458538
serde_json::to_vec(&tensors).map_err(|e| invalid(format!("encode container header: {e}")))
@@ -471,7 +551,7 @@ fn padded_header_len(json: u64) -> Result<u64> {
471551
Ok(length)
472552
}
473553

474-
fn header_bytes(format: &str, layout: &[(String, u64, u64, Source<'_>)]) -> Result<Vec<u8>> {
554+
fn header_bytes(format: &str, layout: &[PlannedEntry]) -> Result<Vec<u8>> {
475555
let mut header = header_json(format, layout)?;
476556
let length = padded_header_len(header.len() as u64)?;
477557
header.resize(length as usize, b' ');
@@ -484,10 +564,10 @@ pub(crate) fn companion_prefix(nbytes: u64) -> Result<Vec<u8>> {
484564
if nbytes == 0 {
485565
return Err(invalid("core payload tensors must not be empty"));
486566
}
487-
let layout = [(COMPANION_TENSOR.to_owned(), 0, nbytes, Source::Zero(nbytes))];
488-
let header = header_bytes(PAYLOAD_FORMAT, &layout)?;
489-
let mut prefix = (header.len() as u64).to_le_bytes().to_vec();
490-
prefix.extend_from_slice(&header);
567+
let layout = [(COMPANION_TENSOR.to_owned(), nbytes)];
568+
let planned = planned_layout(PAYLOAD_FORMAT, &layout, &mut BTreeSet::new())?;
569+
let mut prefix = (planned.header.len() as u64).to_le_bytes().to_vec();
570+
prefix.extend_from_slice(&planned.header);
491571
Ok(prefix)
492572
}
493573

@@ -544,9 +624,14 @@ fn write_source<W: Write>(
544624
}
545625
}
546626

547-
/// Writes the deterministic one-payload companion wrapper for `payload`.
548-
pub fn write_companion(output: &mut impl Write, payload: &Slice) -> Result<()> {
549-
let mut writer = Writer::new(&mut *output, PAYLOAD_FORMAT)?;
627+
/// Writes the deterministic one-payload companion wrapper for `payload`,
628+
/// reporting the size of every write to `report`.
629+
pub fn write_companion_with(
630+
output: &mut impl Write,
631+
payload: &Slice,
632+
report: &mut dyn FnMut(u64),
633+
) -> Result<()> {
634+
let mut writer = Writer::new(Reporting::new(&mut *output, report), PAYLOAD_FORMAT)?;
550635
writer.add(
551636
COMPANION_TENSOR,
552637
payload.len(),
@@ -555,6 +640,41 @@ pub fn write_companion(output: &mut impl Write, payload: &Slice) -> Result<()> {
555640
writer.finish()
556641
}
557642

643+
/// Writes the deterministic one-payload companion wrapper for `payload`.
644+
pub fn write_companion(output: &mut impl Write, payload: &Slice) -> Result<()> {
645+
write_companion_with(output, payload, &mut |_| {})
646+
}
647+
648+
/// The exact number of bytes the companion wrapper for `nbytes` payload bytes
649+
/// occupies on disk: the padded header and the payload itself.
650+
pub(crate) fn companion_written_size(nbytes: u64) -> Result<u64> {
651+
written_size(PAYLOAD_FORMAT, &[(COMPANION_TENSOR.to_owned(), nbytes)])
652+
}
653+
654+
/// Forwards writes to `inner` and reports the size of each write.
655+
pub(crate) struct Reporting<W: Write, F: FnMut(u64)> {
656+
inner: W,
657+
report: F,
658+
}
659+
660+
impl<W: Write, F: FnMut(u64)> Reporting<W, F> {
661+
pub(crate) fn new(inner: W, report: F) -> Self {
662+
Self { inner, report }
663+
}
664+
}
665+
666+
impl<W: Write, F: FnMut(u64)> Write for Reporting<W, F> {
667+
fn write(&mut self, buffer: &[u8]) -> io::Result<usize> {
668+
let count = self.inner.write(buffer)?;
669+
(self.report)(count as u64);
670+
Ok(count)
671+
}
672+
673+
fn flush(&mut self) -> io::Result<()> {
674+
self.inner.flush()
675+
}
676+
}
677+
558678
/// Maps a companion path to its packed tensor name.
559679
pub fn packed_tensor_name(relative: &str) -> Result<String> {
560680
validate_relative_path(relative)?;
@@ -979,16 +1099,27 @@ pub fn pack(
9791099
writer.finish()
9801100
}
9811101

982-
/// Write one payload slice as a canonical companion at `relative`.
983-
pub fn write_payload_companion(root: &Path, relative: &str, payload: &Slice) -> Result<()> {
1102+
/// Write one payload slice as a canonical companion at `relative`, reporting
1103+
/// the size of every write to `report`.
1104+
pub fn write_payload_companion_with(
1105+
root: &Path,
1106+
relative: &str,
1107+
payload: &Slice,
1108+
report: &mut dyn FnMut(u64),
1109+
) -> Result<()> {
9841110
validate_relative_path(relative)?;
9851111
let (_, mut file) = create_relative(root, relative)?;
986-
write_companion(&mut file, payload)?;
1112+
write_companion_with(&mut file, payload, report)?;
9871113
file.sync_all()
9881114
.map_err(|e| io("sync core companion", e))?;
9891115
Ok(())
9901116
}
9911117

1118+
/// Write one payload slice as a canonical companion at `relative`.
1119+
pub fn write_payload_companion(root: &Path, relative: &str, payload: &Slice) -> Result<()> {
1120+
write_payload_companion_with(root, relative, payload, &mut |_| {})
1121+
}
1122+
9921123
/// Writes deterministic companion files extracted from a packed container.
9931124
///
9941125
/// `files` maps a packed tensor name to its core-relative companion path.

0 commit comments

Comments
 (0)