Skip to content

Fix silent export corruption in AOT lowering, zero-init downloads, and drafter scope - #593

Merged
lukealonso merged 1 commit into
mainfrom
flare-export-silent-corruption-compi
Nov 29, 2026
Merged

lukealonso merged 1 commit into
mainfrom
flare-export-silent-corruption-compi

Conversation

@lukealonso

Copy link
Copy Markdown
Collaborator

Why

Three silent corruption defects affect the core export pipeline:

  1. Ignition AOT storage lowering reorders mutations ahead of reads and defers temporary copies (ignition/preparation/compilation.py):
    • _reads_across_mutations determines which computed values must be materialized with flare::snapshot before an in-place mutation overwrites their source storage. It restricted taint propagation to single-tensor aten OpOverload nodes (node in keys) and skipped operator.getitem during backward last_use propagation. Multi-output aten operations (split, chunk, unbind, topk, var_mean) return lists or tuples that are absent from keys, so their outputs dropped taint and let Inductor fuse or reorder mutations ahead of reads (on CUDA, x = buf + 5; a, b = split(x, 4); overwrite(buf, 1000); out.copy_(a + b) produced [2010.0] instead of [16.0, 18.0, 20.0, 22.0]).
    • _lower_storage leaves eligible aten.copy_ calls as plain copies (which AOTAutograd defers to the post-graph writeback) unless a source storage key in accesses[source] is mutated later (last_write[key] > positions[node]). Because accesses[node] was seeded only for persistent regions (get_attr buffers), temporary allocations such as torch.empty(...) had empty accesses, allowing dst.copy_(tmp * 2) to defer past a later tmp.fill_(99.0) (on CUDA, producing [198.0] instead of [10.0]).
  2. Heliopause cached export persists dirty bytes from zero-initialized allocations (heliopause/src/export/capture.rs):
    • On the uncached export path, write_allocation returns early for allocation.initialize == "zero", so RetainedReader reconstructs zeros. On the default cached export path (cache_scan), resolve_weight_payload passed only request.zero_ranges to weight_payload::extract_retained (leaving retained initialize == "zero" allocations in catalog.state.spans), and WeightDownload::queue ignored allocation.initialize == "zero" (defaulting snapshot_spans: None to (0, allocation.nbytes)). As a result, cuMemcpyDtoHAsync_v2 and mapped-host copies persisted dirty post-warmup GPU or host bytes into initial-state.safetensors and broke deterministic payload hashes.
  3. speculation.method bypasses drafter compatibility checks (ignition/parameters.py, helios/src/runtime_core/preparation.rs):
    • SpeculationParameters.manifest_parameters emitted speculation.method with ParameterScope.DEPLOYMENT. Because compatible_for_combine and compatible_for_weight_reuse ignore DEPLOYMENT-scoped parameters, --reuse-weights and ignition combine allowed mixing incompatible drafter architectures (such as mtp vs dflash2 or dspark vs dfly2).

What changed

  • ignition/preparation/compilation.py:
    • Before: _reads_across_mutations propagated last_use only through immutable aten OpOverload nodes and tracked live/fresh taint only for single-tensor aten nodes (node in keys). _lower_storage seeded accesses[node] only when keys[node] in regions.
    • After:
      • _lower_storage hoists operator.getitem(source, int_index) extractions adjacent to immutable multi-output aten producers so snapshots of extracted fresh tensors precede any later mutation of their inputs.
      • _reads_across_mutations propagates last_use backward through operator.getitem, propagates live taint forward through immutable multi-output aten producers (recording their input storage keys) and their getitem outputs, and marks extracted tensor elements fresh only when their storage key is absent from the producer's input keys (so views of mutable storage such as split(buf)[0] continue observing subsequent writes).
      • _lower_storage adds keys[node] to accesses[node] for non-region tensor nodes alongside the union of their input accesses, blocking aten.copy_ deferral whenever any persistent or temporary source key is mutated later.
  • heliopause/src/export/capture.rs:
    • Before: WeightDownload::queue defaulted snapshot_spans: None to (0, allocation.nbytes) regardless of allocation.initialize, always issued CUDA tail-fence/event operations for non-mapped_host allocations, and resolve_weight_payload passed only request.zero_ranges to weight_payload::extract_retained.
    • After:
      • WeightDownload::queue passes empty recorded ranges &[] to copy_recorded_ranges when allocation.initialize == "zero", zero-filling the slot buffer with bounds checking while issuing no D2H or host copies. Both WeightDownload::queue and WeightDownload::read_into skip flush_d2h_tail, cuEventRecord, and cuEventSynchronize for initialize == "zero" allocations.
      • resolve_weight_payload appends retained non-peer, non-dynamic initialize == "zero" allocation ranges to zero_ranges before weight_payload::extract_retained, omitting them from catalog.state.spans.
  • ignition/parameters.py, helios/src/runtime_core/preparation.rs, helios/src/core/conversion.rs, docs/runtime-core-design.md:
    • Before: SpeculationParameters.manifest_parameters emitted speculation.method with ParameterScope.DEPLOYMENT, and from_legacy_rebuild_manifest omitted speculation.method.
    • After: SpeculationParameters.manifest_parameters emits speculation.method with ParameterScope.DRAFT_WEIGHT, from_legacy_rebuild_manifest projects non-empty speculation.method as Scope::DraftWeight, and docs/runtime-core-design.md lists speculation.method under PREPARATION_PARAMETER_SCOPE_DRAFT_WEIGHT. Cross-version combine and weight reuse between legacy RebuildManifest cores and current PreparationManifest cores continue to succeed when speculation.method matches and reject mismatches; target-only --no-mtp exports emit no DRAFT_WEIGHT parameters and continue to reuse target weights from draft-bearing caches.

Claimed benefit and result

  • Compiled forwards preserve eager semantics across mutations through multi-output aten operations (split, chunk, unbind, topk, var_mean) and temporary copies. On SM120 CUDA, the split-across-overwrite reproducer changed from [2010.0] to exact eager [16.0, 18.0, 20.0, 22.0], and the deferred temporary copy_ reproducer changed from [198.0] to exact eager [10.0].
  • Cached Heliopause exports perform zero D2H or host copies for initialize == "zero" allocations and produce initial-state.safetensors payloads byte-identical to the uncached staged path even when GPU or host memory holds nonzero post-warmup bytes.
  • ignition combine and draft-bearing --reuse-weights reject mismatched drafter methods across both current and legacy manifests while preserving target-only --no-mtp weight reuse.

Supporting evidence and limitations

  • Python CPU suite (after rebuilding flare-heliopause from this branch into the worktree .venv with uv pip install --python .venv/bin/python --no-deps ./heliopause):
    • .venv/bin/python -m pytest tests/preparation/test_source_identity.py tests/preparation/test_storage_lifetimes.py tests/preparation/test_core_boundary.py tests/cli -q: 377 passed, 0 failed (covers 200 randomized storage-graph seeds extended with split/topk + getitem, delayed getitem hoisting, temporary copy_ non-deferral, DRAFT_WEIGHT scope for speculation.method, and flare_heliopause source identity).
  • Python CUDA regression suite (NVIDIA RTX PRO 6000 Blackwell, SM120):
    • FLARE_RUN_CUDA_TESTS=1 CUDA_VISIBLE_DEVICES=0 .venv/bin/python -m pytest tests/preparation/test_storage_lifetimes_cuda.py -q: 6 passed, 0 failed (covers split, chunk, unbind, mutable-view observation after mutation, var_mean with delayed indexing + topk, and temporary copy_ before mutation).
  • Rust heliopause CPU and CUDA suites:
    • cargo test --locked --release --manifest-path heliopause/Cargo.toml --lib --target-dir flare-cli/target: 210 passed, 0 failed, 6 ignored (includes zero_init_allocations_skip_weight_download_and_match_staged_state, verifying zero copies/bytes downloaded and byte-identical cached vs staged resolution on dirty mapped_host and device zero-init allocations).
    • CUDA_VISIBLE_DEVICES=0 cargo test --locked --release --manifest-path heliopause/Cargo.toml --lib --target-dir flare-cli/target -- --ignored weight_payload_zero_init_device_allocation_matches_staged_bytes weight_payload_device_materialization_matches_staged_bytes: 2 passed, 0 failed on SM120 (poisons a live GPU initialize == "zero" allocation with 0xCC via cuMemsetD8_v2 and verifies 0 D2H transfers and byte-identical cached vs staged WeightPayloadSources).
  • Rust helios preparation and conversion suites:
    • cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib --target-dir flare-cli/target -- runtime_core:: core::: 487 passed, 0 failed, 11 ignored (verifies from_legacy_rebuild_manifest projection, cross-version combine compatibility when speculation.method matches, rejection when speculation.method disagrees, and preserved --no-mtp target-only weight reuse).
  • Unrun checks / limitations:
    • Full-model checkpoint export (ignition export followed by flare run) and the remaining 4 ignored heliopause CUDA tests were not run.
    • In a broader helios --lib sweep, 6 chat-template tests require FLARE_TEST_TEMPLATE_DIR and 1 pre-existing unrelated test (model::tests::packed_combined_budget_keeps_width_one_batches_without_a_useful_packed_shape) failed in untouched helios/src/model/packed_round_tests.rs.

Discord: lukealonso

…d drafter scope

Three silent corruption defects affect the core export pipeline:

1. In ignition/preparation/compilation.py, _reads_across_mutations restricted
   taint tracking to single-tensor aten OpOverload nodes and skipped
   operator.getitem in backward last_use propagation, allowing Inductor to
   reorder mutations ahead of reads through multi-output aten ops (such as
   split, chunk, unbind, topk, and var_mean). Separately, _lower_storage seeded
   accesses[node] only for persistent regions, so aten.copy_ into persistent
   storage could defer past a later mutation of a temporary source.
2. In heliopause/src/export/capture.rs, the cached weight-payload export path
   (WeightDownload::queue and resolve_weight_payload) ignored
   allocation.initialize == "zero" (unlike write_allocation and RetainedReader
   on the uncached path), copying dirty post-warmup GPU or mapped-host bytes
   into initial-state.safetensors and breaking deterministic payload hashes.
3. In ignition/parameters.py, SpeculationParameters.manifest_parameters marked
   speculation.method as ParameterScope.DEPLOYMENT, which compatible_for_combine
   and compatible_for_weight_reuse in helios/src/runtime_core/preparation.rs
   ignore, allowing --reuse-weights and ignition combine to mix incompatible
   drafter architectures.

Changes:

- ignition/preparation/compilation.py: Previously, _reads_across_mutations
  propagated last_use only through immutable aten OpOverload nodes and tracked
  live/fresh taint only for single-tensor aten nodes in keys, while
  _lower_storage initialized accesses[node] only for persistent regions. Now,
  _lower_storage hoists operator.getitem(source, int_index) nodes adjacent to
  immutable multi-output aten producers so snapshots precede later mutations,
  _reads_across_mutations propagates last_use through operator.getitem and
  propagates live taint through immutable multi-output aten ops and their
  getitem extractions (marking extracted tensors fresh only when their storage
  key is absent from the producer's input keys so views of mutable storage
  continue observing writes), and accesses[node] adds keys[node] for non-region
  tensor nodes so later writes to temporaries block aten.copy_ deferral.
- heliopause/src/export/capture.rs: Previously, WeightDownload::queue treated
  snapshot_spans: None as covering (0, allocation.nbytes) even when
  allocation.initialize == "zero", and resolve_weight_payload passed only
  request.zero_ranges to weight_payload::extract_retained. Now,
  WeightDownload::queue uses empty recorded ranges when
  allocation.initialize == "zero" (zero-filling the slot buffer with bounds
  checking and issuing no D2H or host copies), both queue and read_into skip
  CUDA tail-fence and event synchronization for zero-init allocations, and
  resolve_weight_payload appends retained non-peer, non-dynamic
  initialize == "zero" allocations to zero_ranges before extract_retained.
- ignition/parameters.py, helios/src/runtime_core/preparation.rs,
  docs/runtime-core-design.md: Previously, speculation.method used
  ParameterScope.DEPLOYMENT and was omitted by from_legacy_rebuild_manifest.
  Now, speculation.method uses ParameterScope.DRAFT_WEIGHT and
  from_legacy_rebuild_manifest projects non-empty speculation.method as
  Scope::DraftWeight, preserving cross-version compatibility between legacy
  RebuildManifest cores and current PreparationManifest cores while rejecting
  drafter method mismatches on combine and --reuse-weights (target-only
  --no-mtp exports omit draft-weight parameters and continue reusing target
  weights).

Result:

- Compiled forwards preserve eager semantics across mutations through
  multi-output aten ops and temporary copies (measured on SM120 CUDA: split
  across overwrite produces [16.0, 18.0, 20.0, 22.0] matching eager instead of
  [2010.0], and copy_ from a later-mutated temporary produces [10.0] matching
  eager instead of [198.0]).
- Cached Heliopause exports issue zero D2H or host copies for
  initialize == "zero" allocations and produce initial-state payloads
  byte-identical to the uncached staged path even when backing GPU or host
  memory contains nonzero post-warmup bytes.
- Core combination and draft-bearing --reuse-weights reject mismatched
  speculation.method values across both modern and legacy manifests.

Validation:

- Rebuilt flare-heliopause in the worktree venv and ran
  `.venv/bin/python -m pytest tests/preparation/test_source_identity.py tests/preparation/test_storage_lifetimes.py tests/preparation/test_core_boundary.py tests/cli -q`:
  377 passed (including 200 randomized graph seeds extended with split/topk +
  getitem, deferred-copy checks, and DRAFT_WEIGHT manifest assertions).
- `FLARE_RUN_CUDA_TESTS=1 CUDA_VISIBLE_DEVICES=0 .venv/bin/python -m pytest tests/preparation/test_storage_lifetimes_cuda.py -q`
  on NVIDIA RTX PRO 6000 Blackwell (SM120): 6 passed.
- `cargo test --locked --release --manifest-path heliopause/Cargo.toml --lib --target-dir flare-cli/target`:
  210 passed, 6 ignored (including new CPU zero-init download and cached vs
  staged resolution test).
- `CUDA_VISIBLE_DEVICES=0 cargo test --locked --release --manifest-path heliopause/Cargo.toml --lib --target-dir flare-cli/target -- --ignored weight_payload_zero_init_device_allocation_matches_staged_bytes weight_payload_device_materialization_matches_staged_bytes`:
  2 passed on SM120.
- `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib --target-dir flare-cli/target -- runtime_core:: core::`:
  487 passed, 11 ignored (including updated legacy projection and mismatched
  speculation.method rejection tests).
- Unrun checks: full-model checkpoint export (`ignition export` + `flare run`)
  and the remaining 4 ignored heliopause CUDA tests were not run.

Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=c3a9
Signed-off-by: Luke Alonso <[email protected]>
@lukealonso
lukealonso force-pushed the flare-export-silent-corruption-compi branch from dabf69b to cf11802 Compare November 29, 2026 03:39
@flare-autobot flare-autobot added area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. bug Something isn't working labels Nov 29, 2026
@lukealonso
lukealonso merged commit a39f677 into main Nov 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants