pytorch - 💡(How to fix) Fix PyTorch 2.6 weights_only=True breaks loading of existing checkpoints [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#179904Fetched 2026-04-11 06:11:57
View on GitHub
Comments
1
Participants
2
Timeline
26
Reactions
0
Author
Participants
Timeline (top)
mentioned ×9subscribed ×9labeled ×6commented ×1

Error Message

Error Summary WeightsUnpickler error: Unsupported operand 6 Final exception: When attempting to convert a Hugging Face Whisper model using ct2-transformers-converter, loading the PyTorch checkpoint fails with a _pickle.UnpicklingError followed by an OSError. The error originates from torch.load during model loading and appears to be related to the recent change in PyTorch 2.6 where the default value of weights_only was changed from False to True The error message recommends retrying with weights_only=False, but this introduces potential security risks (arbitrary code execution). The error Unsupported operand 6 suggests that the current safe unpickler does not support certain serialized objects or opcodes in the checkpoint.

RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

Error Summary

torch.load fails with:

_pickle.UnpicklingError: Weights only load failed WeightsUnpickler error: Unsupported operand 6

Followed by:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff

Final exception:

OSError: Unable to load weights from pytorch checkpoint file Expected Behavior

The model checkpoint (pytorch_model.bin) should load successfully during conversion without requiring manual overrides or unsafe deserialization. When attempting to convert a Hugging Face Whisper model using ct2-transformers-converter, loading the PyTorch checkpoint fails with a _pickle.UnpicklingError followed by an OSError. The error originates from torch.load during model loading and appears to be related to the recent change in PyTorch 2.6 where the default value of weights_only was changed from False to True

Actual Behavior The checkpoint cannot be loaded with default settings. The failure suggests incompatibility with weights_only=True. The error message recommends retrying with weights_only=False, but this introduces potential security risks (arbitrary code execution). Additional Context The checkpoint appears valid and works in other environments/tools. The failure occurs specifically during conversion via ctranslate2. The error Unsupported operand 6 suggests that the current safe unpickler does not support certain serialized objects or opcodes in the checkpoint. Why this is an issue

This change in default behavior breaks compatibility with existing model checkpoints that rely on full pickle deserialization. Tools like ctranslate2 (and potentially others) cannot load such models without explicitly overriding safety defaults.

Suggested Improvement Improve compatibility of weights_only=True with common checkpoint formats. Provide clearer diagnostics for unsupported pickle operands. Offer safer fallback mechanisms for trusted checkpoints.

Versions

Environment PyTorch version: 2.6 (or later; issue weights_only ) Python version: 3.12 OS: Linux (Ubuntu, WSL environment) Tooling: transformers (Hugging Face) ctranslate2 (using ct2-transformers-converter) Model format: Hugging Face PyTorch checkpoint (pytorch_model.bin)

Command used:

PYTHONPATH=. TORCH_FORCE_WEIGHTS_ONLY_LOAD=0 ct2-transformers-converter
--model ./model
--output_dir whisper-v3-ct2
--copy_files tokenizer.json preprocessor_config.json
--quantization int8_float16

cc @mruberry @mikaylagawarecki

extent analysis

TL;DR

  • Setting weights_only=False in torch.load may resolve the issue, but introduces potential security risks.

Guidance

  • Verify that the checkpoint file is valid and works in other environments to rule out corruption issues.
  • Consider setting weights_only=False in torch.load as a temporary workaround, but be aware of the potential security risks associated with arbitrary code execution.
  • Check if updating ctranslate2 or transformers to the latest version resolves the compatibility issue with PyTorch 2.6.
  • If possible, try loading the model with TORCH_FORCE_WEIGHTS_ONLY_LOAD=0 to force the old behavior of torch.load.

Example

# Example of loading a model with weights_only=False
import torch
model = torch.load('pytorch_model.bin', weights_only=False)

Note: This example is provided for illustration purposes only and should be used with caution due to the potential security risks.

Notes

  • The issue seems to be related to the change in default behavior of torch.load in PyTorch 2.6, which may break compatibility with existing model checkpoints.
  • The Unsupported operand 6 error suggests that the current safe unpickler does not support certain serialized objects or opcodes in the checkpoint.

Recommendation

  • Apply workaround: Set weights_only=False in torch.load as a temporary solution, but prioritize updating ctranslate2 or transformers to the latest version to resolve the compatibility issue with PyTorch 2.6.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - 💡(How to fix) Fix PyTorch 2.6 weights_only=True breaks loading of existing checkpoints [1 comments, 2 participants]