Skip to content

Fix model imports when torchao is older than 0.15 - #15095

Merged
DN6 merged 3 commits into
huggingface:mainfrom
usmanmateen:fix/torchao-old-version-import
Oct 21, 2026
Merged

DN6 merged 3 commits into
huggingface:mainfrom
usmanmateen:fix/torchao-old-version-import

Conversation

@usmanmateen

@usmanmateen usmanmateen commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #15085

Since #14686 (in v0.41.0), torchao_quantizer.py imports FqnToConfig from torchao.quantization whenever torchao is installed. FqnToConfig only exists from torchao 0.15, so with an older torchao, importing any model fails, even when no quantization is used. That's what happens on Google Colab, which ships an older torchao:

from diffusers import UNet2DModel
RuntimeError: Failed to import diffusers.models.unets.unet_2d ...
cannot import name 'FqnToConfig' from 'torchao.quantization'

The TorchAO quantizer already requires torchao >= 0.15 (validate_environment, and TorchAoConfig itself), so this only imports FqnToConfig and quantize_ from that version on. The other uses of FqnToConfig run after that check.

Tested on main with torch 2.14.1 (CPU):

  • torchao 0.14.1: UNet2DModel, DDPMPipeline and StableDiffusionPipeline failed to import before, and import now. Loading with TorchAoConfig gives the existing message "TorchAoConfig requires torchao >= 0.15.0".
  • torchao 0.15.0: imports work, and loading a UNet with TorchAoConfig(Int8WeightOnlyConfig(version=2)) still quantizes its Linear layers.
  • The new test in tests/others/test_dependencies.py puts a stand-in torchao 0.14.1 on PYTHONPATH, so it runs without torchao installed. It fails on main and passes with this change. pytest tests/others/test_dependencies.py: 5 passed.
  • ruff check and ruff format --check (0.9.10) pass.

Self-review notes (the self-review skill, against .ai/references/review-rules.md and testing.md): no blocking issues. One note for review: a torchao nightly like 0.15.0.devX compares below 0.15.0, so it skips this import, but validate_environment also rejects it, so the two agree.

AI assistance: I used Claude Code to investigate and write this fix. I reviewed the change and ran the tests above.

Before submitting

  • Did you use an AI agent (Claude Code, Codex, Cursor, etc.) to help with this PR? If so:
    • Did you read the Coding with AI agents guide?
    • Did you run the self-review skill on the diff?
    • Did you share the final self-review notes in the PR description or a comment?
  • Did you read the contributor guideline?
  • Did you read our philosophy doc? (important for complex PRs)
  • Was this discussed/approved via a GitHub issue or the forum? Error "cannot import name 'FqnToConfig' from 'torchao.quantization'" when importing the diffusers library on google colab聽#15085
  • Did you make sure to update the documentation with your changes? (no docs change needed)
  • Did you write any new necessary tests?
  • Are you the author (or part of the team) of the model/pipeline?

Who can review?

@sayakpaul

torchao_quantizer.py imported FqnToConfig whenever torchao was installed,
but it only exists from torchao 0.15. With an older torchao, importing any
model failed, including on Google Colab.
Comment thread tests/others/test_dependencies.py Outdated

@sayakpaul sayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@github-actions github-actions Bot removed the tests label Oct 21, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@DN6
DN6 merged commit 3421fed into huggingface:main Oct 21, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error "cannot import name 'FqnToConfig' from 'torchao.quantization'" when importing the diffusers library on google colab

4 participants