Skip to content

Commit 74c41cb

Browse files
kyonjovaclaude
andcommitted
Report conversion phases while ignition convert verifies and writes a package
`ignition convert` printed nothing until it finished. Converting a 178 GB two-Spark package to packed form hashes every payload and copies every byte, so the command sat 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. Native pack and unpack now take a `StartupProgress` and report four phases through it: `Verify package` (signatures), `Verify stored data` with the source bytes hashed, `Write packed package` or `Write package companions` with the bytes written against the expected total, and the publication of the destination. A small forwarding writer counts the packed container's writes; companions count per file. The convert binding passes the standard error reporter the export uses, so a terminal shows a redrawing bar and a redirected log gets a progress line every ten seconds. `pack`, `unpack`, and their selected variants keep their signatures and report silently, as do the cache, combine, and promote paths, which this change leaves alone. Validation on an x86 host without a GPU: the `package::conversion` unit tests pass (45, including a forwarding-writer count test and a round trip whose reported pack and unpack write the same bytes as the silent forms); the same round trip run with the standard error reporter printed the eight phase rows in order. On a DGX Spark (GB10), converting a two-rank MiMo V2.6 Flash RL export of 178,122,320,431 source bytes to packed form printed the four rows with their byte counts: signatures verified in 45 s, stored data in 47 s, 178,159,426,040 bytes written in 194 s, and publication in 1 s. The packed file serves at TP2 through Orbit. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Design-Signed-Off-By: Claude Fable 5.1 (Claude Code); design-review=4d3a Signed-off-by: Kyonjova <kyonjova@pm.me>
1 parent 91cfb36 commit 74c41cb

3 files changed

Lines changed: 170 additions & 20 deletions

File tree

‎docs/cli-design.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,10 @@ Export always writes the directory canonical form in the cache.
975975
single-file package; `ignition convert CACHE_ENTRY --output DIR` writes a
976976
standalone directory. `CACHE_ENTRY` is the path printed by export. Both forms use
977977
the same metadata, payloads, signatures, and location records. Converting between them
978-
needs no signing key or GPU. `--output` refuses an existing destination. A
978+
needs no signing key or GPU. Conversion reports its work as the export does, on
979+
standard error with elapsed time and byte counts: `Verify package`, `Verify stored
980+
data`, `Write packed package` or `Write package companions`, and the final
981+
publication of the destination. `--output` refuses an existing destination. A
979982
destination on another filesystem is assembled by copying bytes, so those files
980983
share no storage with the cache; a destination on the cache's filesystem shares
981984
inodes where it can. Payload-format packages 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 package 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::package::conversion::pack(source, destination)?,
46-
"directory" => helios_core::package::conversion::unpack(source, destination)?,
48+
"packed" => helios_core::package::conversion::pack_with(source, destination, None, &progress)?,
49+
"directory" => {
50+
helios_core::package::conversion::unpack_with(source, destination, None, &progress)?
51+
}
4752
other => {
4853
return Err(super::invalid(format!(
4954
"unknown payload package form {other:?}"

‎helios/src/package/conversion.rs‎

Lines changed: 159 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
//! conversion.
1616
1717
use std::{
18+
cell::Cell,
1819
collections::{BTreeMap, BTreeSet},
1920
fs::{self, File, OpenOptions},
20-
io::Write as _,
21+
io::{self, Write},
2122
path::{Path, PathBuf},
2223
};
2324

@@ -30,7 +31,7 @@ use super::{
3031
reader::{self, Metadata},
3132
schema::{self, Catalog, wire},
3233
};
33-
use crate::{Result, runtime_package::wire as runtime};
34+
use crate::{Result, runtime_package::wire as runtime, startup::StartupProgress};
3435
use ring::digest::{Context as DigestContext, SHA256};
3536

3637
/// Container form of a payload-format package.
@@ -145,12 +146,24 @@ fn packed_tensor_for(
145146
/// for a ready cache entry holding a subset. Unselected payloads may be absent;
146147
/// signed bodies and locations for them are preserved when present.
147148
pub fn pack_selected(source: &Path, output: &Path, selected: Option<&[usize]>) -> Result<()> {
149+
pack_with(source, output, selected, &StartupProgress::silent())
150+
}
151+
152+
/// Packs the selected deployments, reporting verification, writing, and publication phases.
153+
pub fn pack_with(
154+
source: &Path,
155+
output: &Path,
156+
selected: Option<&[usize]>,
157+
progress: &StartupProgress,
158+
) -> Result<()> {
159+
let phase = progress.phase("Verify package", None);
148160
let verified = Verified::open(source, selected)?;
149161
if !directory_form(source, &verified.metadata) {
150162
return Err(invalid("package is already in packed form"));
151163
}
152164
let payloads = verified.payloads()?;
153-
payloads.verify()?;
165+
phase.finish("signatures");
166+
verify_stored_data(&payloads, progress)?;
154167

155168
let mut locations = Vec::with_capacity(verified.locations.locations.len());
156169
let mut packed = Vec::new();
@@ -202,15 +215,33 @@ pub fn pack_selected(source: &Path, output: &Path, selected: Option<&[usize]>) -
202215
.open(&staging)
203216
.map_err(|e| invalid(format!("create packed package: {e}")))?;
204217
let guard = TempFile::new(&staging);
205-
let mut writer = Writer::new(file, verified.metadata.primary().format())?;
206-
for name in verified.metadata.primary().tensor_names() {
207-
if name == reader::LOCATIONS || name.starts_with(container::ALIGNMENT_PREFIX) {
208-
continue;
209-
}
218+
let locations = rewritten.encode_to_vec();
219+
let primary: Vec<&str> = verified
220+
.metadata
221+
.primary()
222+
.tensor_names()
223+
.filter(|name| *name != reader::LOCATIONS && !name.starts_with(container::ALIGNMENT_PREFIX))
224+
.collect();
225+
let mut total = locations.len() as u64;
226+
for name in &primary {
227+
total = add_bytes(total, verified.metadata.primary().tensor(name)?.len())?;
228+
}
229+
for (_, id) in &packed {
230+
total = add_bytes(total, payloads.get(id)?.len())?;
231+
}
232+
let phase = progress.phase("Write packed package", Some(total));
233+
let written = Cell::new(0u64);
234+
let mut writer = Writer::new(
235+
Reporting::new(file, |bytes| {
236+
written.set(written.get() + bytes);
237+
phase.advance_bytes(bytes);
238+
}),
239+
verified.metadata.primary().format(),
240+
)?;
241+
for name in primary {
210242
let slice = verified.metadata.primary().tensor(name)?;
211243
writer.add(name, slice.len(), Source::Slice(slice))?;
212244
}
213-
let locations = rewritten.encode_to_vec();
214245
writer.add(
215246
reader::LOCATIONS,
216247
locations.len() as u64,
@@ -221,24 +252,80 @@ pub fn pack_selected(source: &Path, output: &Path, selected: Option<&[usize]>) -
221252
writer.add(&name, slice.len(), Source::Slice(slice))?;
222253
}
223254
writer.finish()?;
255+
phase.finish(format!("{} bytes written", written.get()));
256+
let phase = progress.phase("Publish packed package", None);
224257
publish_staged_file(&staging, output)?;
225258
guard.keep();
259+
phase.finish(output.display().to_string());
226260
Ok(())
227261
}
228262

263+
fn add_bytes(total: u64, bytes: u64) -> Result<u64> {
264+
total
265+
.checked_add(bytes)
266+
.ok_or_else(|| invalid("package byte count overflow"))
267+
}
268+
269+
/// Hashes every stored payload as one phase whose detail counts the bytes read.
270+
fn verify_stored_data(payloads: &reader::PayloadFiles, progress: &StartupProgress) -> Result<()> {
271+
let total = payloads
272+
.iter()
273+
.try_fold(0u64, |total, (_, slice)| add_bytes(total, slice.len()))?;
274+
let phase = progress.phase("Verify stored data", Some(total));
275+
payloads.verify_with_progress(&|bytes| phase.advance_bytes(bytes))?;
276+
phase.finish(format!("{total} source bytes verified"));
277+
Ok(())
278+
}
279+
280+
/// Forwards writes to `inner` and reports the count of each write.
281+
struct Reporting<W: Write, F: FnMut(u64)> {
282+
inner: W,
283+
report: F,
284+
}
285+
286+
impl<W: Write, F: FnMut(u64)> Reporting<W, F> {
287+
fn new(inner: W, report: F) -> Self {
288+
Self { inner, report }
289+
}
290+
}
291+
292+
impl<W: Write, F: FnMut(u64)> Write for Reporting<W, F> {
293+
fn write(&mut self, buffer: &[u8]) -> io::Result<usize> {
294+
let count = self.inner.write(buffer)?;
295+
(self.report)(count as u64);
296+
Ok(count)
297+
}
298+
299+
fn flush(&mut self) -> io::Result<()> {
300+
self.inner.flush()
301+
}
302+
}
303+
229304
/// Rewrites a packed package as a directory with deterministic companions.
230305
pub fn unpack(source: &Path, output: &Path) -> Result<()> {
231306
unpack_selected(source, output, None)
232307
}
233308

234309
/// Unpacks only the closure of the selected deployments.
235310
pub fn unpack_selected(source: &Path, output: &Path, selected: Option<&[usize]>) -> Result<()> {
311+
unpack_with(source, output, selected, &StartupProgress::silent())
312+
}
313+
314+
/// Unpacks the selected deployments, reporting verification, writing, and publication phases.
315+
pub fn unpack_with(
316+
source: &Path,
317+
output: &Path,
318+
selected: Option<&[usize]>,
319+
progress: &StartupProgress,
320+
) -> Result<()> {
321+
let phase = progress.phase("Verify package", None);
236322
let verified = Verified::open(source, selected)?;
237323
if directory_form(source, &verified.metadata) {
238324
return Err(invalid("package is already in directory form"));
239325
}
240326
let payloads = verified.payloads()?;
241-
payloads.verify()?;
327+
phase.finish("signatures");
328+
verify_stored_data(&payloads, progress)?;
242329

243330
let mut locations = Vec::with_capacity(verified.locations.locations.len());
244331
let mut companions = Vec::new();
@@ -285,30 +372,52 @@ pub fn unpack_selected(source: &Path, output: &Path, selected: Option<&[usize]>)
285372
let staging = unique_staging(output, "unpack")?;
286373
fs::create_dir(&staging).map_err(|e| invalid(format!("create package staging: {e}")))?;
287374
let result = (|| {
375+
let locations = rewritten.encode_to_vec();
376+
let primary_names: Vec<&str> = verified
377+
.metadata
378+
.primary()
379+
.tensor_names()
380+
.filter(|name| *name != reader::LOCATIONS && primary_payload(name))
381+
.collect();
382+
let mut total = locations.len() as u64;
383+
for (_, _, slice) in &companions {
384+
total = add_bytes(total, slice.len())?;
385+
}
386+
for name in &primary_names {
387+
total = add_bytes(total, verified.metadata.primary().tensor(name)?.len())?;
388+
}
389+
let phase = progress.phase("Write package companions", Some(total));
390+
let written = Cell::new(0u64);
288391
for (_tensor, relative, slice) in &companions {
289392
container::write_payload_companion(&staging, relative, slice)?;
393+
written.set(written.get() + slice.len());
394+
phase.advance_bytes(slice.len());
290395
}
291396
let primary = staging.join("model.safetensors");
292397
let file = OpenOptions::new()
293398
.write(true)
294399
.create_new(true)
295400
.open(&primary)
296401
.map_err(|e| invalid(format!("create package primary: {e}")))?;
297-
let mut writer = Writer::new(file, verified.metadata.primary().format())?;
298-
for name in verified.metadata.primary().tensor_names() {
299-
if name == reader::LOCATIONS || !primary_payload(name) {
300-
continue;
301-
}
402+
let mut writer = Writer::new(
403+
Reporting::new(file, |bytes| {
404+
written.set(written.get() + bytes);
405+
phase.advance_bytes(bytes);
406+
}),
407+
verified.metadata.primary().format(),
408+
)?;
409+
for name in primary_names {
302410
let slice = verified.metadata.primary().tensor(name)?;
303411
writer.add(name, slice.len(), Source::Slice(slice))?;
304412
}
305-
let locations = rewritten.encode_to_vec();
306413
writer.add(
307414
reader::LOCATIONS,
308415
locations.len() as u64,
309416
Source::Bytes(locations),
310417
)?;
311418
writer.finish()?;
419+
phase.finish(format!("{} bytes written", written.get()));
420+
let phase = progress.phase("Publish package directory", None);
312421
container::sync_file(&primary)
313422
.map_err(|e| invalid(format!("sync package primary: {e}")))?;
314423
// Companion entries must be durable before the directory becomes visible,
@@ -321,7 +430,9 @@ pub fn unpack_selected(source: &Path, output: &Path, selected: Option<&[usize]>)
321430
invalid(format!("publish package directory: {e}"))
322431
}
323432
})?;
324-
sync_parent(output)
433+
sync_parent(output)?;
434+
phase.finish(output.display().to_string());
435+
Ok(())
325436
})();
326437
if result.is_err() {
327438
let _ = fs::remove_dir_all(&staging);
@@ -4343,6 +4454,37 @@ mod tests {
43434454
assert!(rank.compressed_prepared_weights.is_none());
43444455
}
43454456

4457+
#[test]
4458+
fn reporting_writer_forwards_bytes_and_reports_each_write() {
4459+
let mut written = 0u64;
4460+
let mut sink = Vec::new();
4461+
{
4462+
let mut writer = Reporting::new(&mut sink, |count| written += count);
4463+
writer.write_all(b"abc").unwrap();
4464+
writer.write_all(b"defgh").unwrap();
4465+
writer.flush().unwrap();
4466+
}
4467+
assert_eq!(sink, b"abcdefgh");
4468+
assert_eq!(written, 8);
4469+
}
4470+
4471+
#[test]
4472+
fn reported_pack_and_unpack_write_the_same_bytes_as_the_silent_forms() {
4473+
let scratch = Scratch::new("reported-roundtrip");
4474+
let fixture = fixture(&scratch);
4475+
let silent = scratch.join("silent.safetensors");
4476+
pack(&fixture.directory, &silent).unwrap();
4477+
let reported = scratch.join("reported.safetensors");
4478+
pack_with(&fixture.directory, &reported, None, &StartupProgress::silent()).unwrap();
4479+
assert_eq!(fs::read(&silent).unwrap(), fs::read(&reported).unwrap());
4480+
4481+
let unpacked = scratch.join("unpacked");
4482+
unpack_with(&reported, &unpacked, None, &StartupProgress::silent()).unwrap();
4483+
let again = scratch.join("repacked.safetensors");
4484+
pack(&unpacked, &again).unwrap();
4485+
assert_eq!(fs::read(&silent).unwrap(), fs::read(&again).unwrap());
4486+
}
4487+
43464488
#[test]
43474489
fn out_of_bounds_recipe_is_rejected_before_any_publication() {
43484490
let scratch = Scratch::new("recipe-bounds");

0 commit comments

Comments
 (0)