Repository navigation
Conversation
Qubitium
force-pushed
the
upstream/10-disk-backed-layer-outputs-20261108
branch
from
November 8, 2026 08:02
a56c675 to
ded8fcc
Compare
Qubitium
reviewed
Nov 8, 2026
Qubitium
left a comment
Collaborator
There was a problem hiding this comment.
Review: layer 10/36 — authenticated disk-backed layer outputs
Rebased onto the layer-9 branch (ef7a8c5e); no conflicts. Diff vs the predecessor is looper/input_cache.py, the new test, and one requirements line. Pushed as ded8fcc1.
Verified
tests/test_disk_backed_layer_outputs.py→ 7 passed (6 original + 1 added)ruff checkclean
Fixed
- Finalize crash window —
finalize()deletedprogress.jsonbeforeos.replace(temporary, destination). A crash between those two calls left a completemanifest.jsonin.partialbut no progress record, so the next writer started with an empty shard set and recomputed every batch. Progress is now removed only after the rename commits (and a leftoverprogress.jsonin a complete directory is ignored byopen()). Added a rename-crash regression test that fails on the old ordering. - Manifest path containment —
root / shard["path"]lets an absolute path (or..) escape the root, and_restore_progressdid not reject symlinks at all. Added_contained_path()(rejects absolute/escaping paths and symlinks) and used it in bothopen()and_restore_progress(). - Non-POSIX durability —
_fsync_directorycalledos.open(dir, O_RDONLY)+fsyncunguarded, which fails on Windows. It is now a no-op off POSIX and usesO_DIRECTORYwhere available. _atomic_jsonhygiene — the temp file leaked on write/replace failure and was created0600. It is now removed on failure and written0644.xxhashdependency — the comment claimed it was "needed only for this optional recovery path", but_flush_shard()and_restore_progress()hash every shard, so the writer hard-requires it. It was undeclared, which makes the feature (and its test) fail on a stock install. Addedxxhash>=4.0.2torequirements.txtand a clearImportError. If you want it genuinely optional, the writer needs a no-hash/fallback mode rather than a lazy import.
Notes (not blockers)
append()computes its index fromlen(committed) + sum(pending)under the lock, then releases and callsput(). A concurrentput()can race between the two. SequentialForwardExecutoruse is fine; document the single-writer assumption.- The
Sequence[List[torch.Tensor]]contract suggests multi-tensor batches, butput()accepts exactly one tensor (len(value) != 1→TypeError). Either widen it or narrow the annotation/docstring. open()verifies every shard hash by default, i.e. reads the whole cache; that is correct but expensive for large activation sets.verify_hashes=Falseis available but easy to miss.open()/_restore_progress()still passbatch_count/shard_batchesthroughint()without type checks, so a malformed (but self-hashed) manifest can raise a rawTypeError. Minor.lifetime_diagnostic()relies ongc.get_referrersand is heuristic by nature; the__new__shortcut inDiskBackedLayerOutputSequenceis hacky but harmless.
The core design is good: shards are content-hashed, the manifest is canonical-JSON self-hashed, progress is atomic, completed shards resume without rewriting, and finalizer retries work.
Qubitium
marked this pull request as ready for review
November 8, 2026 08:10
Qubitium
force-pushed
the
upstream/10-disk-backed-layer-outputs-20261108
branch
2 times, most recently
from
November 8, 2026 08:22
2aeb0e7 to
f8842b0
Compare
The new test file used semicolons (E702) and unsorted imports (I001), and the module import block was unsorted; format/check.sh runs ruff check over tests, so the PR could not merge as-is. No behavior change: 20 tests still pass.
…utputs - Keep progress.json until the destination rename commits. A crash after the complete manifest is written but before the rename now resumes the finished shards instead of recomputing them; add a rename-crash regression test. - Reject manifest/progress shard paths that escape the root or are symlinks. - Make _fsync_directory a no-op off POSIX; clean up _atomic_json temp files on failure and write them 0644. - Declare xxhash (the writer hashes every shard, so it is not recovery-only) and raise a clear ImportError when it is missing.
Qubitium
force-pushed
the
upstream/10-disk-backed-layer-outputs-20261108
branch
from
November 8, 2026 08:35
f8842b0 to
d1896b6
Compare
Collaborator
|
Clean review found out-of-order replay batches stayed in RAM and later reads could miss changed shard data. Fixed in merged #3790; 14 focused tests pass with and without the GIL. Concurrent |
12 tasks done
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
…to disk for every processor (#6656) ds4rt's disk-backed layer outputs (#3588) were reachable only through per-model configure_*_store hooks that nothing in-tree calls. Make the same DiskBackedLayerOutputWriter/Sequence available to every processor through one typed field, CalibrationConfig.spill_path (map PR-G2): - spill_writer() gives each pass a private, non-durable directory (no fsync, no resume journal) that weakref.finalize removes with its sequence, or with the writer when a failed pass never finalizes it. - ForwardExecutor._output_collection spills every pass that produces all batches (replays, native capture) after the unchanged model hook; subset forwards that stop early keep their list. The first-layer capture moves each batch into a spill writer as soon as its forward returns. - The writer records each batch's device and the sequence reads it back there, so consumers see the same tensors on the same device. Deep copies share the immutable files. - ContinuationCodec stores a spilled cache as the list it replaces, so spill composes with CheckpointConfig (layer and subset steps). - The lm_head stage copies a lazy cache into lists before the in-place norm hook. - Delete TensorLifetimeDiagnostic, whose last consumer #6477 removed. spill_path=None runs none of this: GPTQ and AWQ on Qwen2.5-0.5B-Instruct are bit-identical to main. With spill on, GPTQ and AWQ on Qwen2.5-0.5B-Instruct and GPTQ on OLMoE-1B-7B are bit-identical to spill off, and peak GPU memory drops by the hidden-state sets the default path keeps resident. Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Summary
Add an opt-in writer and random-access sequence for bounded calibration boundaries. Shard safetensors batches, bind provenance and hashes, publish completion manifests atomically, resume completed shards, and retry post-commit finalizers. Non-owning lifetime diagnostics help verify that readers release issued tensors. The public utility is available to explicit consumers; automatic looper/model wiring remains in the fork remainder. xxhash is imported lazily and is needed only for this optional recovery path.
Stack
Layer 10/36 of a dependency-ordered fork extraction. Depends on #3587. Review only this layer.
GitHub requires this cross-fork PR to target upstream
main, so its Files changed tab includes earlier stack layers. After the predecessor lands, rebase this branch and retarget the next layer; do not merge later layers out of order. No predecessor is merged automatically.Tests
6 passed. Used Python 3.12, Torch 2.14.1, Transformers 5.19.0. No model quantization, GPU work, downloads, or heavyweight model validation. Unit fixtures are small and CPU execution is constrained to one math thread.
Review and remaining validation
This layer and its dependency diff were reviewed for scope, existing extension points, and compatibility with the resolved fork snapshot. New focused regression coverage is included. Kept as a draft for maintainer review; hardware paths and end-to-end model behavior have not been revalidated in this session. No speed claim. Original integration/history is preserved in tpurtell#3.