Skip to content

Fix update_ckpt() failing on legacy checkpoints with torch >= 2.6 - #194

Merged
avantikalal merged 2 commits into
Genentech:mainfrom
musharna:fix-update-ckpt-weights-only
Oct 2, 2026
Merged

avantikalal merged 2 commits into
Genentech:mainfrom
musharna:fix-update-ckpt-weights-only

Conversation

@musharna

@musharna musharna commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #193.

update_ckpt() is the documented migration path for checkpoints saved with gReLU v0.4 or lower, but on PyTorch 2.6+ it raises UnpicklingError on exactly those files: PyTorch 2.6 flipped the default of torch.load's weights_only argument to True, and legacy gReLU checkpoints carry numpy metric values in performance (written by LightningModel.on_save_checkpoint), which the safe unpickler refuses.

The fix loads the checkpoint with an explicit weights_only=False, matching the default grelu.resources.wandb.load_model_from_wandb already uses for checkpoint loading. update_ckpt reads files the user is explicitly asking to migrate, the same trust model as before PyTorch 2.6.

Added a regression test that builds a checkpoint the way gReLU writes them, injects numpy performance values and the legacy depth hyperparameter, and runs update_ckpt end to end. Verified with torch 2.13.0 / lightning 2.6.5 / numpy 2.5.2:

  • against current main, the test fails with UnpicklingError: Weights only load failed ... GLOBAL numpy._core.multiarray.scalar was not an allowed global;
  • with this change it passes, and the rest of tests/test_io.py still passes.

The other torch.load calls in the codebase (grelu/model/models.py) load plain tensor state dicts, which the weights_only=True default handles fine, so they are left unchanged.

PyTorch 2.6 changed the default of torch.load's weights_only argument
from False to True. Legacy gReLU checkpoints store numpy metric values
in the "performance" entry (written by LightningModel.on_save_checkpoint),
which the weights_only=True unpickler refuses, so update_ckpt() raised
UnpicklingError on exactly the files it exists to migrate.

Load the checkpoint with an explicit weights_only=False, matching the
default already used for checkpoint loading in grelu.resources.wandb.

Fixes Genentech#193
@musharna
musharna marked this pull request as ready for review September 20, 2026 03:55
@avantikalal
avantikalal merged commit e6fd1d4 into Genentech:main Oct 2, 2026
1 of 2 checks passed
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.

grelu.io.update_ckpt() cannot open the legacy checkpoints it exists to migrate (torch >= 2.6)

2 participants