Repository navigation
Description
Observed behavior
Enabling checkpoint=CheckpointConfig(interval="layer:1") can add several times the live replay and dense tensor storage to host peak RSS. Each committed boundary serializes that entire continuation, including the calibration inputs and every materialized nonpacked parameter or buffer. With 192 MiB of live synthetic CPU tensors, the production encoder raised process peak RSS by 579.0 MiB. The checkpoint store performed three full 192 MiB reads during commit, collection, and manifest load, before the separate read and decode for restoration.
The packed module artifact path already streams data to and from files. Continuation handling uses the same content-addressed store and has two extra whole-payload paths.
- Capture and calibration identity use
ContinuationCodec.dumps(). It clones each input tensor on CPU and holds the tensor map while safetensors returns the entire serialized buffer. Encoder · State capture · Identity - Commit and manifest verification call
get()on the continuation and discard the bytes. They can reuse the same streaming SHA-256 check used by the packed artifacts. Resume then reads the continuation again and decodes all tensors from the bytes. Verification and commit · Commit validation · Publish and restore
Reproduce
Run the following with the checkout at 85caf6cc5 on Linux. Measured with Python 3.12.16, Torch 2.15.0+cpu, and GPT-QModel 7.11.6. The synthetic InputCache and dense tensor exercise the same codec and store used by quantize(checkpoint=...).
import gc
import os
import resource
from pathlib import Path
from tempfile import TemporaryDirectory
import torch
from gptqmodel.looper.checkpoint_store import CheckpointConfig, CheckpointStore
from gptqmodel.looper.continuation import ContinuationCodec
from gptqmodel.looper.input_cache import InputCache
def current_rss_mib():
resident_pages = int(Path('/proc/self/statm').read_text().split()[1])
return resident_pages * os.sysconf('SC_PAGE_SIZE') / 2**20
def peak_rss_mib():
return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024
torch.set_num_threads(1)
# 128 MiB replay hidden state plus 64 MiB materialized dense model state.
replay = torch.ones((16, 2048, 2048), dtype=torch.bfloat16)
dense = torch.ones((8192, 4096), dtype=torch.bfloat16)
cache = InputCache([[replay]], [{}], [], [], src_inputs=[])
state = {'processors': [{'cache': cache}], 'dense': {'projection': {'weight': dense}}}
source = sum(t.numel() * t.element_size() for t in (replay, dense))
initial_peak = peak_rss_mib()
print(f'source tensors: {source / 2**20:.0f} MiB, RSS before encode: {current_rss_mib():.1f} MiB')
with TemporaryDirectory() as root, CheckpointStore(CheckpointConfig(path=root)) as store:
packed = ContinuationCodec.dumps(state)
print(f'encoded payload: {len(packed) / 2**20:.0f} MiB, peak added since pre-encode: {peak_rss_mib() - initial_peak:.1f} MiB')
ref = store.put(packed)
del packed
gc.collect()
# Count actual full-byte reads in each verification-only transition. The
# wrapper leaves storage, hashing, and transaction logic unchanged.
get = store.get
continuation_reads = []
def observed_get(digest):
result = get(digest)
if digest == ref:
continuation_reads.append(len(result))
return result
store.get = observed_get
store.commit(identity={'example': True}, cursor=0, continuation=ref, artifacts={})
store.collect()
manifest = store.load({'example': True})
print(f'verification-only full reads: {len(continuation_reads)}, total: {sum(continuation_reads) / 2**20:.0f} MiB')
restored = ContinuationCodec.loads(store.get(manifest['continuation']))
assert torch.equal(restored['processors'][0]['cache'].layer_inputs[0][0], replay)
assert torch.equal(restored['dense']['projection']['weight'], dense)source tensors: 192 MiB, RSS before encode: 706.1 MiB
encoded payload: 192 MiB, peak added since pre-encode: 579.0 MiB
verification-only full reads: 3, total: 576 MiB
Suggested fix
Replace the two verification-only reads with the existing streaming integrity check. That preserves checksum verification and fallback to a prior valid generation.
# CheckpointStore._manifest
self.object_path(manifest["continuation"])
# CheckpointStore.commit
self.object_path(continuation)Then stream continuation tensors to a staged safetensors file and publish it through store.put_file(). Use an incrementally written file or bounded tensor shards so GPU-to-CPU transfers never hold a complete host copy. Read verified objects with safe_open and restore tensors one at a time. Use an incremental calibration identity hash with a compatibility rule for the existing serialized identity. Preserve the tagged tree, placement checks, atomic CURRENT publication, and read compatibility with existing continuations.
A regression should run commit and restore on repeated layer boundaries, include an interrupted write and a corrupt newest generation, verify exact restored tensors and cursor, and confirm that peak extra host RSS is bounded by a shard or transfer tile.
Activity
Qubitium commentedon Nov 20, 2026
Agent claim released:
agent-f7b500b8ed4cfinished this issue.Pull request: #5925
Reproducing checkpoint continuation memory/read amplification on CPU