Skip to content

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.

Quick answer

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.
Infrastructure#torchao#pytorch#weights_only#quantization#checkpoints

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.

Live diagnosis, no signup

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.

training_logs.txt
No log to hand? Try one:

Upload your log file. Large files are processed in your browser. Only selected evidence is submitted when you run diagnosis.

3 free cloud diagnoses per day

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.

SymptomPossible explanation
Weights only load failed or unable to import torchao.dtypes tensor subclass during torch.loadEither 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 classesEither 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

  1. 1Read the full UnpicklingError or ImportError line to see whether a class was rejected by weights_only or relocated in a newer torchao version.
  2. 2Install the matching torchao release recorded during quantization export.
  3. 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.

Use your company email, for example alex@yourcompany.com.

Who qualifies?

Company email domains activate the free 30-day Team evaluation (up to 50 diagnoses a day) after an email and domain check, whatever mail provider you use. If we cannot verify your domain automatically, support reviews it: write to support@denpex.com. Free local diagnosis in the editor extension needs no account.

Using a personal email (Gmail, Outlook, Naver, QQ) or solo cluster? Create a free $0 account (no work email required) to save 7-day history and unlock AI fallback, or send a cluster crash log for a live walkthrough.
Already have an account? Sign in

Searchable error signature

search key
UnpicklingError: Weights only load failed: Unsupported global torchao.dtypes.AffineQuantizedTensor or unable to import tensor objects

Use 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 logs

No 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

snippet
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 / StackRecommendationNotes
Module path mismatchPin matching torchao releaseInternal torchao subclass paths refactor between minor releases.
PyTorch 2.6+ weights_onlyUse safe_globals for trusted classesAvoid setting weights_only=False on external or unverified weights.

With the fix vs without the fix

DimensionWith the fixWithout the fix
Checkpoint loadingMatch torchao version and allowlist explicit tensor classesDisabling weights_only=True globally on unverified files
Long-term portabilityPin export/serve containers or save plain state dictsPickling internal Python tensor subclass structures

Diagnostic note

“Grounded in PyTorch weights_only serialization safeguards and torchao tensor-subclass quantization compatibility rules.”

Visual fingerprint

torchao checkpoint load path
torch.load error -> missing module path? pin matching torchao version | blocked global? wrap with add_safe_globals
Separate PyTorch 2.6+ safe_globals allowlisting from torchao package version drift.

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 extension

PyTorch 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 errors

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?
No. weights_only=False permits arbitrary pickle code execution and should never be used on untrusted checkpoints. Use torch.serialization.safe_globals with explicit classes on verified checkpoints.
Why did an older torchao checkpoint stop loading after upgrading torchao?
torchao evolved several internal tensor subclass module paths across releases, so loading pickled subclass instances across versions can fail with import errors unless versions match or weights are re-exported.

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.