Skip to content

Commit c9382ca

Browse files
committed
fix: Add weights_only=False for PyTorch 2.6 checkpoint loading
PyTorch 2.6 changed the default value of weights_only parameter in torch.load() from False to True. Since Lightning checkpoints contain optimizer and scheduler state (not just tensors), loading now requires weights_only=False. This is safe as the checkpoint is self-generated during training.
1 parent 808f749 commit c9382ca

2 files changed

Lines changed: 1731 additions & 1214 deletions

File tree

torchTextClassifiers/torchTextClassifiers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ def train(
198198
- Model training with early stopping
199199
- Best model loading after training
200200
201+
Note on Checkpoints:
202+
After training, the best model checkpoint is automatically loaded.
203+
This checkpoint contains the full training state (model weights,
204+
optimizer, and scheduler state). Loading uses weights_only=False
205+
as the checkpoint is self-generated and trusted.
206+
201207
Args:
202208
X_train: Training input data
203209
y_train: Training labels
@@ -361,6 +367,7 @@ def train(
361367
best_model_path,
362368
model=self.pytorch_model,
363369
loss=training_config.loss,
370+
weights_only=False, # Required: checkpoint contains optimizer/scheduler state
364371
)
365372

366373
self.pytorch_model = self.lightning_module.model.to(self.device)

0 commit comments

Comments
 (0)