Skip to content

heliopause, helios: parallelize Engram plane assembly in core export - #586

Draft
FujitsuPolycom wants to merge 1 commit into
NVIDIA:mainfrom
FujitsuPolycom:perf/heliopause-engram-parallel-assembly
Draft

FujitsuPolycom wants to merge 1 commit into
NVIDIA:mainfrom
FujitsuPolycom:perf/heliopause-engram-parallel-assembly

Conversation

@FujitsuPolycom

@FujitsuPolycom FujitsuPolycom commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Why

Core export must resolve every host-resident Engram weight and scale plane declared by a prepared model. Resolving independent planes in sequence leaves host storage idle during assembly, and single-worker fallback in payload worker scheduling lacked the catch_unwind cleanup guarantee used by threaded workers.

What changed

  • helios/src/core/export.rs:
    • Before: install_phase_payloads and install_cache_phase_payloads maintained separate worker loops, and single-worker execution did not share threaded catch_unwind handling.
    • After: run_payload_workers schedules up to eight workers (MAX_PAYLOAD_INSTALL_WORKERS) largest-first with catch_unwind parity across both single-worker (workers == 1) and multi-worker paths, halting new items on the first error, panic, or thread-spawn failure and returning results in declared order.
  • heliopause/src/export/core.rs & docs/runtime-core-design.md:
    • Before: core_engram resolved each shared or partitioned plane sequentially; materialize, materialize_payload_spans, and materialize_span wrote unbuffered staged files without unlinking failed flushes or checking multi-span u64 byte-total overflow; and estimated_export_fds omitted concurrent Engram assembly descriptors.
    • After: core_engram resolves planes concurrently across up to eight workers: single-file planes pin their checkpoint range and share the process-wide read-ahead digest pool (bounded to sixteen concurrent digests / 1 GiB across workers), multi-file planes stream-hash pieces through 4 MiB buffers (ring::digest::SHA256) to reuse verified cache objects or materialize uncached planes, and newly opened PayloadObject handles are eagerly .take()n into leases by digest in declaration order so duplicate cache descriptors close immediately rather than surviving until core_engram returns. Worker failures or panics unlink staged sibling .payload files, and estimated_export_fds budgets concurrent worker descriptors. materialize_payload_spans (with checked u64 byte-total accumulation returning an explicit overflow error) and materialize_span also migrate to materialize_pieces (4 MiB BufWriter, sync_all(), and staged-file removal on error), replacing fn materialize. Skipping standalone digests and fsync on disposable cubin and graph spans is split into heliopause: skip digest and fsync on disposable export spans #587.
  • Compatibility: Existing signed runtime cores, container layouts, and Protobuf schemas remain unchanged.

Claimed benefit and result

  • Expected effect: Engram plane assembly overlaps host reads and hashing across up to eight workers while preserving deterministic manifest order, deduplicated cache leases without retained duplicate descriptors, and staging cleanup on error or panic.
  • Draft status: This PR remains in Draft pending live multi-host 188.8 GiB Engram export timing and RSS/page-cache measurements on a four-host DGX Spark TP4 setup to verify that eight workers sharing the read-ahead digest pool do not contend on a single NVMe or crowd unified 128 GiB DRAM page cache.

Supporting evidence and limitations

Tested at candidate commit daba5bfc92576bbaff8bb9468f3b29dc590287a7 on main (ba3afb13a7e9836080c23eadf8e1c17ee96e6e7a) in non-root Linux (uid=1000):

Discord: Dooner

@voipmonitor voipmonitor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Draft Review & Test Report (commit e43b2563)

Verdict: Approve once out of draft (minor items below) — thread-safe, deterministic, bounded in heap memory, and clean pre-worker validation.

Automated Test Results

  • cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib core:: — 482 passed (1 pre-existing uid=0 chmod test skipped/failed only as root).
  • cargo test --locked --release --manifest-path heliopause/Cargo.toml --lib (default parallel threads) — 210 passed, 0 failed.

Audit Notes

  • run_payload_workers (helios/src/core/export.rs:1047-1141) uses std::thread::scope, atomic cursor, catch_unwind parity, and clean stop propagation; single-file planes use stateless pread, multi-file planes use independent FDs, and concurrent Root::payload() hits use per-OFD shared locks. Outputs assemble sequentially in declared order, and staged files unlink cleanly on error (handle closed before remove_file).
  • Heap is bounded to ≤512 MiB for 8 single-file digest workers (via READ_AHEAD_SLOTS) and ≤64 MiB for multi-file workers.

Minor Items Before Ready/Merge

  1. [Minor] Replace internal fork PR reference (Disposable cubin/graph span extraction is split into #35.) in the PR description with #587, and mention that materialize_payload_spans/materialize_span were also migrated to materialize_pieces.
  2. [Minor] Use checked_add for total += piece.nbytes in materialize_payload_spans (heliopause/src/export/core.rs:2192).
  3. [Minor] Eagerly .take() opened from resolved when moving into leases (heliopause/src/export/core.rs:1596-1613) instead of cloning and retaining duplicate PayloadObject FDs until core_engram returns.
  4. [Minor] When moving out of draft, please include real export timing + RSS/page-cache numbers on a large Engram model (e.g., 188.8 GiB) to confirm 8 workers × 4 read-ahead threads (40 threads) doesn't regress single-NVMe contention or 128 GiB Spark page cache.
  5. [Nit] Move engram_and_span_materialization_clean_up_staged_files_on_flush_enospc_and_sibling_failure from mod packing_metadata_tests to mod payload_export_tests.

Note: Directly conflicts with #587 in docs/runtime-core-design.md:323 and heliopause/src/export/core.rs (materialize_span + test module); coordinate rebase when landing both.

Why:
Resolving host-resident Engram weight and scale planes serially leaves host
I/O idle during core export, and single-worker execution in
`run_payload_workers` lacked panic-catching parity with threaded workers.

What:
Before: `core_engram` resolved each table and shard plane sequentially,
`materialize` / `materialize_payload_spans` / `materialize_span` wrote
unbuffered staged files without unlinking failed flushes or checking
multi-span byte-total overflow, `estimated_export_fds` omitted concurrent
Engram worker descriptors, and `install_phase_payloads` /
`install_cache_phase_payloads` duplicated worker loops.
After: `helios::core::export::run_payload_workers` schedules up to eight
workers largest-first with `catch_unwind` parity across both single-worker
(`workers == 1`) and multi-worker paths. `core_engram` resolves planes
concurrently—sharing the bounded read-ahead digest pool for single-file
ranges, stream-hashing multi-file planes through 4 MiB buffers, and eagerly
taking newly opened cache objects into `leases` by digest in declaration
order without retaining duplicate descriptors—while cleaning up staged
sibling files on failure and accounting for worker FDs in
`estimated_export_fds`. `materialize_payload_spans` (with checked `u64`
byte-total accumulation) and `materialize_span` delegate to
`materialize_pieces`, replacing `fn materialize`. Existing signed runtime
cores and wire schemas remain unchanged.

Result:
Engram payload resolution overlaps host reads and hashing across up to eight
workers while preserving deterministic manifest order, deduplicated cache
leases, and staging cleanup on error or panic. Live multi-host GPU export
and 188.8 GiB Engram timing and RSS/page-cache measurements have not yet
been run on this revision.

Evidence:
- `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib core::`: 484 passed, 11 ignored, 0 failed.
- `cargo test --locked --release --manifest-path heliopause/Cargo.toml --lib`: 211 passed, 5 ignored, 0 failed.
- `pytest -q -rs tests/preparation/test_core_boundary.py tests/test_design_review_hook.py`: 22 passed.
- Multi-host Spark TP4 188.8 GiB Engram export timing, RSS/page-cache headroom, and Windows native export remain unverified on this revision.

Discord: Dooner

Design-Signed-Off-By: Antigravity (Gemini 4); design-review=c3a9
Signed-off-by: FujitsuPolycom <[email protected]>
@FujitsuPolycom
FujitsuPolycom force-pushed the perf/heliopause-engram-parallel-assembly branch from e43b256 to daba5bf Compare November 28, 2026 23:42
@FujitsuPolycom

Copy link
Copy Markdown
Contributor Author

@voipmonitor Addressed at daba5bfc92576bbaff8bb9468f3b29dc590287a7 (rebased onto main ba3afb13). The PR description has also been updated so the changes, Draft hold criteria, and merge coordination with #587 stand on their own.

  1. PR description reference to #587 and materialize_pieces migration:

    • Fix: Replaced the internal fork reference with #587 and documented in both the commit message and PR description that materialize_payload_spans and materialize_span now delegate to materialize_pieces (replacing fn materialize).
    • Remaining limit: None.
  2. checked_add for total in materialize_payload_spans (heliopause/src/export/core.rs:2190):

    • Fix: Replaced total += piece.nbytes with total.checked_add(piece.nbytes).ok_or_else(|| invalid("payload length overflow"))? and added materialize_payload_spans_rejects_u64_total_overflow_before_staging in mod payload_export_tests to verify multi-span u64 overflow fails with "payload length overflow" before creating a staged file.
    • Verification (daba5bfc): cargo test --locked --release --manifest-path heliopause/Cargo.toml --lib -> 211 passed, 5 ignored, 0 failed (0 warnings).
    • Remaining limit: None within the declared contract.
  3. Eagerly .take() opened into leases (heliopause/src/export/core.rs:1596-1611):

    • Fix: Made resolved mutable, moved opened.take() directly into leases.entry(*id).or_insert(object), and updated *slice in resolved to the leased Slice so duplicate PayloadObject data and lock descriptors drop immediately inside the loop rather than surviving until core_engram returns.
    • Verification (daba5bfc): core_engram_parallel_assembly_reuses_fragmented_cache_and_deduplicates_leases in cargo test --locked --release --manifest-path heliopause/Cargo.toml --lib -> 211 passed, 5 ignored, 0 failed.
    • Remaining limit: None.
  4. Large Engram export timing and RSS/page-cache measurement before leaving Draft:

  5. Move cleanup test into mod payload_export_tests:

Could you take another look at daba5bfc while this remains in Draft pending the Spark TP4 Engram export benchmark?

@flare-autobot flare-autobot added area:caching Prefix/KV reuse, cache retention, and model or payload cache behavior. area:engram Engram row gathering, disk I/O, and embedding-row caching. area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. performance Performance, latency, throughput, or memory-efficiency investigation or improvement. labels Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:caching Prefix/KV reuse, cache retention, and model or payload cache behavior. area:engram Engram row gathering, disk I/O, and embedding-row caching. area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. performance Performance, latency, throughput, or memory-efficiency investigation or improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants