RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory #21641
Replies: 1 comment
|
This error typically means the checkpoint file is corrupted or was only partially written. Here are the most common causes and fixes: 1. Checkpoint saved only on rank 0, but all ranks try to loadYour custom callback has Also note: os.path.makedirs(os.path.dirname(model_path), exist_ok=True)This should be: os.makedirs(os.path.dirname(model_path), exist_ok=True)( 2. The checkpoint file was truncatedCommon causes:
Fix: Add a verification step after saving: def _save_checkpoint(self, trainer, filepath):
if trainer.global_rank == 0:
# ... save ...
# Verify the file is valid
torch.load(model_path, weights_only=True, map_location="cpu")3. File path collisionIf Fix: Use unique filenames (e.g., include step/epoch) or save to a temp file first, then atomically rename: import tempfile, shutil
tmp_path = model_path + ".tmp"
torch.save(state_dict, tmp_path)
shutil.move(tmp_path, model_path) # atomic on same filesystem4. Verify your checkpoint fileYou can check if the file is a valid zip archive: import zipfile
print(zipfile.is_zipfile("model.pth")) # Should be True for PyTorch checkpoints |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have a custom model checkpointing class:
In the end of a DDP training, sometimes it leads to the error
RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory. This is an internal miniz error. If you are seeing this error, there is a high likelihood that your checkpoint file is corrupted. This can happen if the checkpoint was not saved properly, was transferred incorrectly, or the file was modified after saving.Could you help to understand this problem?
All reactions