torchao: Unable to Import Tensor Objects Error
Fix torchao unable to import quantized tensor objects when loading checkpoints with torch.load. Align torchao versions and weights_only safe globals.
Checkpoint loading fails with unable to import torchao tensor objects when torch.load(weights_only=True) blocks custom tensor subclasses (for example AffineQuantizedTensor) or when the saved checkpoint references an older torchao module path that changed across releases. Align the torchao package version with checkpoint creation, or register supported safe globals.
- Symptom
UnpicklingError: Weights only load failed: Unsupported global torchao.dtypes.AffineQuantizedTensor or unable to import tensor objects- Root cause
- Either torch.load(weights_only=True) rejected unregistered torchao tensor classes, or the checkpoint was pickled against a different torchao module hierarchy than the serving container.
- Recommended fix
- Check the exact torchao version used when saving the checkpoint and install matching PyTorch + torchao versions in the serving environment.
- How Denpex helps
- Denpex investigates torchao: Unable to Import Tensor Objects Error using the evidence you provide or your connected workload collects. Earlier rank, host or application evidence is needed to distinguish an initiating failure from a downstream report.
What this failure is
A PyTorch deserialization or module-resolution error when loading a quantized model serialized with torchao tensor subclasses across PyTorch 2.6+ or mismatched torchao versions.
Is this what broke your run? Paste your log.
You're reading about torchao: Unable to Import Tensor Objects Error. Paste your own traceback and relevant evidence for an investigation of your workload, with a next action or a specific missing fact. A reference entry does not establish your cause. No account or card for the free diagnosis. Review data handling before submitting sensitive logs.
Before uploading, review cloud data handling and local options.
Upload your log file. Large files are processed in your browser. Only selected evidence is submitted when you run diagnosis.
Why it happens (the mechanism)
torchao quantizes weights by wrapping parameters in Python Tensor subclasses serialized via pickle/torch.save. Starting in PyTorch 2.6, torch.load defaults to weights_only=True, rejecting custom classes unless allowlisted; meanwhile rapid torchao refactors move internal tensor subclass module paths between versions.
What you'll observe
- Loading an int8/int4/fp8 quantized checkpoint fails with UnpicklingError or ModuleNotFoundError naming torchao tensor objects.
- Training or evaluation pipelines crash immediately during checkpoint resume even though the same weights loaded under an earlier container.
Common symptoms and what they mean
Check possible explanations against the incident evidence. A matching symptom alone does not establish its cause.
| Symptom | Possible explanation |
|---|---|
| Weights only load failed or unable to import torchao.dtypes tensor subclass during torch.load | Either torch.load(weights_only=True) rejected unregistered torchao tensor classes, or the checkpoint was pickled against a different torchao module hierarchy than the serving container. |
| ModuleNotFoundError referencing relocated torchao.dtypes.affine_quantized_tensor classes | Either torch.load(weights_only=True) rejected unregistered torchao tensor classes, or the checkpoint was pickled against a different torchao module hierarchy than the serving container. |
Which systems are affected
- PyTorch 2.6+ training and serving jobs using torchao quantized weights
- Cross-version model checkpoint sharing between torchao releases
How to confirm this is the problem
Use this checklist to test the hypothesis against a small reproduction. No single line proves the root cause, so preserve the preceding events and compare one variable at a time.
- ✓Print python3 -c "import torch, torchao; print(torch.__version__, torchao.__version__)" in both save and load environments.
- ✓Load the checkpoint inside an isolated test script using torch.serialization.safe_globals and confirm forward inference matches reference outputs.
Root cause
- Either torch.load(weights_only=True) rejected unregistered torchao tensor classes, or the checkpoint was pickled against a different torchao module hierarchy than the serving container.
The fix and how to prevent it
How to fix it
- Check the exact torchao version used when saving the checkpoint and install matching PyTorch + torchao versions in the serving environment.
- Export quantized weights with Hugging Face Safetensors or torchao-recommended serialization formats instead of arbitrary pickle tensor objects whenever possible.
- For trusted internal checkpoints requiring torch.load, allowlist the exact torchao tensor classes using torch.serialization.add_safe_globals([...]) or safe_globals context manager.
- Inspect the missing module path in the traceback before widening weights_only=False (only ever use weights_only=False on verified internal artifacts).
Step-by-step remediation
- 1Read the full UnpicklingError or ImportError line to see whether a class was rejected by weights_only or relocated in a newer torchao version.
- 2Install the matching torchao release recorded during quantization export.
- 3Register required tensor classes inside torch.serialization.safe_globals before calling torch.load(weights_only=True).
How to prevent it
- Record torch.__version__ and torchao.__version__ inside model metadata alongside every quantized checkpoint.
- Pin torchao versions cleanly across export, evaluation, and deployment images.
Save this diagnosis and catch the next crash automatically
All root cause, fix, and prevention steps above are free to read. Create a free account with any email or GitHub to keep your saved diagnosis history across the encyclopedia and run cloud checks, or use a work email below for the 30-day Team evaluation. No card required.
Or start a 30-day free Team trial (work email)
Verified work email unlocks all 14 fleet diagnostic tools, Slack alerts, and team history for 30 days. No card and no automatic charge.
Searchable error signature
UnpicklingError: Weights only load failed: Unsupported global torchao.dtypes.AffineQuantizedTensor or unable to import tensor objectsUse this text as a lookup key in logs and upstream issue trackers. It is not presented as a captured customer log. Confirm the cause from your own preceding events, versions, configuration and the cited references.
Diagnose your own log automatically
The root cause and fix steps above stay free. Create a free account to analyze full job logs, attribute the first failed rank, and keep saved incident history.
Sign up free. Analyze your cluster logsNo credit card. Daily allowance follows verified trust tier. Instant access.
Why the recommended fix works
Aligning torchao package versions restores expected tensor subclass definitions while explicit safe_globals satisfies PyTorch 2.6+ security defaults without blind pickle execution.
Code examples
import torch
from torchao.dtypes import AffineQuantizedTensor
with torch.serialization.safe_globals([AffineQuantizedTensor]):
state = torch.load("quantized_model.pt", weights_only=True)This snippet illustrates the entry-specific check. Verify the installed versions, permissions, target and workload context before using it. A command or API example is not proof of recovery.
Best practices by model family
| Model / Stack | Recommendation | Notes |
|---|---|---|
| Module path mismatch | Pin matching torchao release | Internal torchao subclass paths refactor between minor releases. |
| PyTorch 2.6+ weights_only | Use safe_globals for trusted classes | Avoid setting weights_only=False on external or unverified weights. |
With the fix vs without the fix
| Dimension | With the fix | Without the fix |
|---|---|---|
| Checkpoint loading | Match torchao version and allowlist explicit tensor classes | Disabling weights_only=True globally on unverified files |
| Long-term portability | Pin export/serve containers or save plain state dicts | Pickling internal Python tensor subclass structures |
Diagnostic note
“Grounded in PyTorch weights_only serialization safeguards and torchao tensor-subclass quantization compatibility rules.”
Visual fingerprint
torch.load error -> missing module path? pin matching torchao version | blocked global? wrap with add_safe_globals
Diagnose this failure in VS Code
Select the traceback or open the failed terminal, then run Denpex locally to inspect matched failure patterns, supporting evidence and next checks without uploading the log. Verify recommendations against your workload before changing production.
Install the free VS Code extensionPyTorch GPU errors in context
PyTorch training errors commonly originate at tensor device placement, DataLoader /dev/shm IPC, or checkpoint state restoration.
Compare related pytorch gpu errorsRelated failures to investigate next
Frequently asked questions
Questions engineers and on-call staff commonly ask about this failure.
Should I set weights_only=False everywhere to make torchao load?
Why did an older torchao checkpoint stop loading after upgrading torchao?
Don't just read the fix, diagnose your run
The encyclopedia explains documented failure patterns. Denpex investigates your logs, configuration and stack, shows the supporting evidence, and asks for missing details when needed.
Related Infrastructure errors
Dual ISP BGP Route Withdrawal Causing Complete GPU Cloud Region Outage
Infrastructure · critical
Routine UPS Maintenance Triggering Cascading Power and Cooling Failure Across GPU Cloud Region
Infrastructure · critical
Remediation Storm Prevention via Circuit Breaker Pattern in AutoClusters
Infrastructure · high
Network Storage Volume Causing Process Hangs on H100 GPU Nodes
Infrastructure · high