Repository navigation
Fix silent export corruption in AOT lowering, zero-init downloads, and drafter scope - #593
Merged
Merged
Conversation
…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
force-pushed
the
flare-export-silent-corruption-compi
branch
from
November 29, 2026 03:39
dabf69b to
cf11802
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Three silent corruption defects affect the core export pipeline:
ignition/preparation/compilation.py):_reads_across_mutationsdetermines which computed values must be materialized withflare::snapshotbefore an in-place mutation overwrites their source storage. It restricted taint propagation to single-tensoratenOpOverloadnodes (node in keys) and skippedoperator.getitemduring backwardlast_usepropagation. Multi-outputatenoperations (split,chunk,unbind,topk,var_mean) return lists or tuples that are absent fromkeys, 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_storageleaves eligibleaten.copy_calls as plain copies (which AOTAutograd defers to the post-graph writeback) unless a source storage key inaccesses[source]is mutated later (last_write[key] > positions[node]). Becauseaccesses[node]was seeded only for persistentregions(get_attrbuffers), temporary allocations such astorch.empty(...)had emptyaccesses, allowingdst.copy_(tmp * 2)to defer past a latertmp.fill_(99.0)(on CUDA, producing[198.0]instead of[10.0]).heliopause/src/export/capture.rs):write_allocationreturns early forallocation.initialize == "zero", soRetainedReaderreconstructs zeros. On the default cached export path (cache_scan),resolve_weight_payloadpassed onlyrequest.zero_rangestoweight_payload::extract_retained(leaving retainedinitialize == "zero"allocations incatalog.state.spans), andWeightDownload::queueignoredallocation.initialize == "zero"(defaultingsnapshot_spans: Noneto(0, allocation.nbytes)). As a result,cuMemcpyDtoHAsync_v2and mapped-host copies persisted dirty post-warmup GPU or host bytes intoinitial-state.safetensorsand broke deterministic payload hashes.speculation.methodbypasses drafter compatibility checks (ignition/parameters.py,helios/src/runtime_core/preparation.rs):SpeculationParameters.manifest_parametersemittedspeculation.methodwithParameterScope.DEPLOYMENT. Becausecompatible_for_combineandcompatible_for_weight_reuseignoreDEPLOYMENT-scoped parameters,--reuse-weightsandignition combineallowed mixing incompatible drafter architectures (such asmtpvsdflash2ordsparkvsdfly2).What changed
ignition/preparation/compilation.py:_reads_across_mutationspropagatedlast_useonly through immutableatenOpOverloadnodes and trackedlive/freshtaint only for single-tensoratennodes (node in keys)._lower_storageseededaccesses[node]only whenkeys[node] in regions._lower_storagehoistsoperator.getitem(source, int_index)extractions adjacent to immutable multi-outputatenproducers so snapshots of extracted fresh tensors precede any later mutation of their inputs._reads_across_mutationspropagateslast_usebackward throughoperator.getitem, propagateslivetaint forward through immutable multi-outputatenproducers (recording their input storage keys) and theirgetitemoutputs, and marks extracted tensor elementsfreshonly when their storage key is absent from the producer's input keys (so views of mutable storage such assplit(buf)[0]continue observing subsequent writes)._lower_storageaddskeys[node]toaccesses[node]for non-region tensor nodes alongside the union of their input accesses, blockingaten.copy_deferral whenever any persistent or temporary source key is mutated later.heliopause/src/export/capture.rs:WeightDownload::queuedefaultedsnapshot_spans: Noneto(0, allocation.nbytes)regardless ofallocation.initialize, always issued CUDA tail-fence/event operations for non-mapped_hostallocations, andresolve_weight_payloadpassed onlyrequest.zero_rangestoweight_payload::extract_retained.WeightDownload::queuepasses empty recorded ranges&[]tocopy_recorded_rangeswhenallocation.initialize == "zero", zero-filling the slot buffer with bounds checking while issuing no D2H or host copies. BothWeightDownload::queueandWeightDownload::read_intoskipflush_d2h_tail,cuEventRecord, andcuEventSynchronizeforinitialize == "zero"allocations.resolve_weight_payloadappends retained non-peer, non-dynamicinitialize == "zero"allocation ranges tozero_rangesbeforeweight_payload::extract_retained, omitting them fromcatalog.state.spans.ignition/parameters.py,helios/src/runtime_core/preparation.rs,helios/src/core/conversion.rs,docs/runtime-core-design.md:SpeculationParameters.manifest_parametersemittedspeculation.methodwithParameterScope.DEPLOYMENT, andfrom_legacy_rebuild_manifestomittedspeculation.method.SpeculationParameters.manifest_parametersemitsspeculation.methodwithParameterScope.DRAFT_WEIGHT,from_legacy_rebuild_manifestprojects non-emptyspeculation.methodasScope::DraftWeight, anddocs/runtime-core-design.mdlistsspeculation.methodunderPREPARATION_PARAMETER_SCOPE_DRAFT_WEIGHT. Cross-version combine and weight reuse between legacyRebuildManifestcores and currentPreparationManifestcores continue to succeed whenspeculation.methodmatches and reject mismatches; target-only--no-mtpexports emit noDRAFT_WEIGHTparameters and continue to reuse target weights from draft-bearing caches.Claimed benefit and result
atenoperations (split,chunk,unbind,topk,var_mean) and temporary copies. On SM120 CUDA, thesplit-across-overwrite reproducer changed from[2010.0]to exact eager[16.0, 18.0, 20.0, 22.0], and the deferred temporarycopy_reproducer changed from[198.0]to exact eager[10.0].initialize == "zero"allocations and produceinitial-state.safetensorspayloads byte-identical to the uncached staged path even when GPU or host memory holds nonzero post-warmup bytes.ignition combineand draft-bearing--reuse-weightsreject mismatched drafter methods across both current and legacy manifests while preserving target-only--no-mtpweight reuse.Supporting evidence and limitations
flare-heliopausefrom this branch into the worktree.venvwithuv 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 withsplit/topk+getitem, delayedgetitemhoisting, temporarycopy_non-deferral,DRAFT_WEIGHTscope forspeculation.method, andflare_heliopausesource identity).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 (coverssplit,chunk,unbind, mutable-view observation after mutation,var_meanwith delayed indexing +topk, and temporarycopy_before mutation).heliopauseCPU and CUDA suites:cargo test --locked --release --manifest-path heliopause/Cargo.toml --lib --target-dir flare-cli/target: 210 passed, 0 failed, 6 ignored (includeszero_init_allocations_skip_weight_download_and_match_staged_state, verifying zero copies/bytes downloaded and byte-identical cached vs staged resolution on dirtymapped_hostanddevicezero-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 GPUinitialize == "zero"allocation with0xCCviacuMemsetD8_v2and verifies 0 D2H transfers and byte-identical cached vs stagedWeightPayloadSources).heliospreparation 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 (verifiesfrom_legacy_rebuild_manifestprojection, cross-version combine compatibility whenspeculation.methodmatches, rejection whenspeculation.methoddisagrees, and preserved--no-mtptarget-only weight reuse).ignition exportfollowed byflare run) and the remaining 4 ignoredheliopauseCUDA tests were not run.helios --libsweep, 6 chat-template tests requireFLARE_TEST_TEMPLATE_DIRand 1 pre-existing unrelated test (model::tests::packed_combined_budget_keeps_width_one_batches_without_a_useful_packed_shape) failed in untouchedhelios/src/model/packed_round_tests.rs.Discord: lukealonso