Skip to content

fix(looper): bound disk-backed output staging and verify replay reads - #3790

Merged
Qubitium merged 1 commit into
mainfrom
fix/disk-backed-output-bounds-integrity
Nov 12, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/disk-backed-output-bounds-integrity

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fix

Out-of-order replay batches previously stayed in RAM until a whole shard completed. Each incomplete batch now spills to an atomic safetensors file; only one complete shard is loaded during assembly. Replay reads recheck the shard digest, and concurrent append() calls reserve distinct indices under the writer lock.

flowchart TD
  A["DiskBackedLayerOutputWriter.put or append"] --> B["Reserve index under lock"]
  B --> C{"Shard complete?"}
  C -- "No" --> D["Atomically spill batch to disk"]
  C -- "Yes" --> E["Load and hash one shard"]
  E --> F{"Digest valid?"}
  F -- "No" --> X["Fail; do not commit"]
  F -- "Yes" --> G["Commit shard and progress"]
  H["DiskBackedLayerOutputSequence.__getitem__"] --> I["Load batch and rehash shard"]
  I --> J{"Digest valid?"}
  J -- "No" --> Y["Fail; do not return tensor"]
  J -- "Yes" --> K["Return batch"]
  classDef failure fill:#fdd,stroke:#c33
  class X,Y failure
Loading
Mechanism Before After
Out-of-order batches, gptqmodel/looper/input_cache.py:559 _pending held each tensor in RAM _pending holds spill path and digest
Replay reads, gptqmodel/looper/input_cache.py:320 Hash checked only at open Hash checked on every batch read
Concurrent append, gptqmodel/looper/input_cache.py:581 Index lock released before put() Index reservation and write share one lock

Validation: 14 focused disk-backed tests passed on normal Python and again with PYTHON_GIL=0; 2,000 out-of-order batches retained zero pending tensors in RAM. Reference: docs/looper-checkpoint-redesign.md.

Fixes #3588.

@Qubitium
Qubitium force-pushed the fix/disk-backed-output-bounds-integrity branch from ab657db to a50e9cf Compare November 12, 2026 02:49

Copy link
Copy Markdown
Collaborator Author

Reviewed: out-of-order batches spill to disk, replay reads detect changed shards, and concurrent appends claim distinct indices. All 14 focused tests pass with and without the GIL; CI passes and the review thread is resolved.

@Qubitium
Qubitium merged commit f7e4163 into main Nov 12, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/disk-backed-output-bounds-integrity branch November 12, 2026 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants