Repository navigation
Studio: fix image and video loads on torchao 0.14 (FqnToConfig import error with diffusers 0.41) - #13308
Conversation
diffusers 0.41 imports torchao.quantization.FqnToConfig unguarded, and that name first exists in torchao 0.15.0. Studio pairs torch <= 2.8 (and torch 2.9 on installs predating the 0.15 pin) with torchao 0.14.0, whose class is still called ModuleFqnToConfig, so every model that imports diffusers.loaders.peft (MiniMax-H3, any LoRA load) failed with "cannot import name 'FqnToConfig'". alias_torchao_fqn_to_config() adds the new name as an alias of the old class, the same alias torchao 0.15 keeps the other way round. It runs with the other pre-diffusers hooks (run.py, the diffusion and diffusion-training modules, the diffusers prewarm), reads the version from package metadata, imports torchao only when the alias is due, and leaves a stubbed, absent or >= 0.15 torchao alone.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8ab79c1bd5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| install_xformers_windows_rocm_stub() | ||
| hide_xformers_built_for_another_torch() | ||
| install_torchao_windows_rocm_stub() | ||
| alias_torchao_fqn_to_config() |
There was a problem hiding this comment.
Defer the alias until after GPU environment initialization
On every standard run.py launch with torchao < 0.15, this call eagerly imports torchao.quantization, whose package initialization imports torch, before main.py can set CUDA_DEVICE_ORDER, normalize allocator settings, restore the desktop ROCm environment, or register Windows ROCm DLL directories. This violates the explicit pre-torch initialization ordering in main.py and can make affected older-torch installations select the wrong GPU or initialize ROCm with missing settings; install the alias without importing torch here, or perform it only after that initialization but before diffusers is imported.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e05fc7a: the alias is now deferred to the first diffusers import through a meta path finder, so run.py and spawn children no longer import torch or torchao (import run on torch 2.8 + torchao 0.14.0: 0.10 s / 25 MB again, alias still applied when diffusers loads).
…port Importing torchao.quantization from run.py loaded torch into the server process and every spawn child before main.py's pre-torch environment setup, costing seconds and about 600 MB on the torchao 0.14 hosts the alias targets. A meta path finder now aliases on the first import of diffusers, the only package that needs the name.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
The reds here come from this PR; the same files pass on main (513 passed):
|
…3336) test_torchao_fqn_alias.py (from #13308) imports a fake diffusers package from tmp_path. monkeypatch.delitem records only entries that existed, so in an xdist worker where the real diffusers had not been imported yet, the fake one stayed in sys.modules and every later test in that worker saw a diffusers without AutoencoderKLWan or its pipelines: test_video_vae_bf16_decode_rocm, test_video_backend and test_train_precision_scheme_contract fail on main and on unrelated PRs (#13315). An autouse fixture now restores the diffusers/torchao entries of sys.modules exactly after every test. Also apply the ruff-format-with-kwargs hook to the two files #13308 added, which test_formatter_fixed_point flags on main.
Fixes image and video loads failing with
cannot import name 'FqnToConfig' from 'torchao.quantization'on Studio installs that pair diffusers 0.41 with torchao 0.14.Problem
Loading MiniMax-H3 (or any model or LoRA that goes through
diffusers.loaders.peft) on these installs fails before any weights are read:diffusers/quantizers/torchao/torchao_quantizer.py:55) runsfrom torchao.quantization import FqnToConfig, quantize_whenever torchao is installed, with no version check. diffusers 0.40 did not.FqnToConfigfirst exists in torchao 0.15.0. 0.13.0, 0.14.0 and 0.14.1 only have the same class under its old name,ModuleFqnToConfig(checked in the released wheels). 0.15 renamed it and keptModuleFqnToConfig = FqnToConfig._select_torchao_specpairs torch 2.8 and older with torchao 0.14.0 (its C++ extension has to match torch), and did the same for torch 2.9 until Studio installer: drop a flash-attn built for a torch that is gone, and pair torch 2.9 with torchao 0.15.0 #13247. So the break reaches every install on torch 2.6 to 2.8 (older drivers and older GPUs, e.g. [Bug] LLM CUDA works, image model import fails after Repair. #11545 on torch 2.6.0+cu124) and every torch 2.9 install from a release before Studio installer: drop a flash-attn built for a torch that is gone, and pair torch 2.9 with torchao 0.15.0 #13247 ([Bug] Studio update channel installs a CUDA-13 / torch-2.10 flash-attn wheel into a CUDA-12 (driver-locked) venv; diffusers image generation then fails: libcudart.so.13 → torchao FqnToConfig #13244: Desktop 0.1.905-beta, torch 2.9.0+cu126, torchao 0.14.0+cu126). Studio installer: drop a flash-attn built for a torch that is gone, and pair torch 2.9 with torchao 0.15.0 #13247 cannot help the first group and only reaches the second through a reinstall.Fix
alias_torchao_fqn_to_config()incore/_torchao_stub.pygives torchao older than 0.15 thetorchao.quantization.FqnToConfigname as an alias ofModuleFqnToConfig: the same alias torchao 0.15 keeps, the other way round. It is called with the existing pre-diffusers hooks, right after the Windows ROCm torchao stub, in every place that imports diffusers first:run.py,core/inference/diffusion.py,core/training/diffusion_train_common.py(the spawned diffusion trainer) and the diffusers prewarm inutils/torch_warmup.py.import diffusersthrough a meta path finder that never resolves a module itself. Importing torchao inrun.pywould load torch into the server process and every spawn child beforemain.pysets up the GPU environment; on torch 2.8 + torchao 0.14.0 that tookimport runfrom 0.1 s / 25 MB to 6.6 to 16 s / about 665 MB. With the deferralimport runis unchanged (0.10 s, 25 MB, no torch) and the alias lands when diffusers loads. If diffusers ortorchao.quantizationis already loaded, it aliases at once.torchao.quantizationonly when an alias is due, so a torchao >= 0.15 install never imports torchao earlier than before.FqnToConfig, and a failure inside the finder never breaks the diffusers import.Testing
core.inference.diffusion,core.inference.video,core.training.diffusion_train_commonand therun.pyhook sequence followed bydiffusers.models.transformers.transformer_minimax_h3all fail with the exact error above. With this PR all four succeed, plusdiffusers.loaders.peftandTorchAoConfig.TorchAoConfig(diffusers', which Studio's image and video paths do not use, and transformers') raises the library's own "requires torchao >= 0.15.0", exactly as on main; transformers 5.x treats torchao < 0.15 as unavailable.tests/test_torchao_fqn_alias.py: the alias for 0.13 / 0.14 / 0.14.1 / local-tagged and dev versions, idempotence, 0.15+ left alone and not imported, absent and stubbed torchao, an existingFqnToConfigkept, the alias deferred until a realimport diffusersand applied then, a failing alias not breaking the import, and the hook order in the three module-level hook blocks.tests/test_diffusers_prewarm.pyasserts the alias runs in the prewarm's stub sequence before diffusers is imported. 45 passed on ubuntu-latest, macos-15 and windows-latest.