Repository navigation
fix(AMD): let diffusion load on Windows ROCm, and say what a gated repo needs - #7981
danielhanchen merged 20 commits into
Conversation
… needs Two things stopped an image load dead on a Windows ROCm host. The Windows xformers pin is CUDA-only, and against a ROCm torch, which ships no distributed backend, importing xformers dies inside torch.distributed. diffusers imports xformers on sight, so every model import went down with it and reported 'module torch.distributed has no attribute Work', naming neither xformers nor the cause. diffusers reaches torchao the same way through its quantizers. Both stubs already existed for torchao; the diffusion paths now install both before the first lazy diffusers import, in the loader and in the trainers' shared module (they run in a spawned child of their own). A gated base then surfaced its raw GatedRepoError in a toast: a request id, a resolve URL, and one useful sentence. It now says which repo is gated, links its page, and asks for a token only when none was sent. The full exception still goes to the log.
🌊 Poseidon Review 🐚Reviewed Four distinct issues remain open, two at P2 and two at P3. The most important fix is wrapping the P2 - Guard hub_access_message so a failure cannot strand the load
The try:
text = hub_access_message(exc, had_token = bool(kwargs.get("hf_token"))) or str(exc)
except Exception: # noqa: BLE001
text = str(exc)P3 - Extend on_windows_rocm fixture to clean up torchao stubs The On a runner without real torchao installed, the stubs persist for the rest of the pytest session: any later Widen the save/restore filter to cover both packages: def _is_stub_key(k: str) -> bool:
return (
k == "xformers" or k.startswith("xformers.")
or k == "torchao" or k.startswith("torchao.")
)
saved = {k: v for k, v in sys.modules.items() if _is_stub_key(k)}
for name in saved:
del sys.modules[name]
yield
for name in [k for k in sys.modules if _is_stub_key(k)]:
del sys.modules[name]
sys.modules.update(saved)P2 - Wire hub_access_message into the video error handler The PR adds from core.inference.diffusion import hub_access_message
text = hub_access_message(exc, had_token = bool(kwargs.get("hf_token"))) or str(exc)
with self._lock:
if self._load_token == token and self._loading is not None:
self._loading.error = redact_native_paths(text)P3 - Update comment to reflect the added gated-repo rewrite The comment at line 1015 says # Rewrite gated-repo errors into the step that unblocks the user, then
# redact native paths: this text is surfaced verbatim and Studio can be shared. |
The diffusion modules install both stubs at module scope, but that is already too late in the server: by the time a route imports one, the app has pulled torchao in through the route tree, and a stub only seeds names nothing has imported yet. The desktop app still died on torch._C._distributed_c10d. Move both installs to the entry point, ahead of every backend import, and guard the ordering with a test that walks run.py's module body.
…ed errors, ambient token, CPU-thread ordering
|
Pushed The diagnosis here is right and the stub is the correct shape, so this is all follow-through on the open review points. I reproduced each one locally before changing anything. 1.
|
…on the two remaining quant paths
|
Pushed The issue is real, and AMD documents itNot a guess from the traceback. AMD's own Radeon/Ryzen ROCm limitations page states that Before and after, reproduced on this Linux boxI could not use the real thing, so I modelled it. The one observable ROCm fact is that Before: After, with the stubs installed first and nothing else changed: That is the whole claim of the PR, demonstrated. One honest caveat: I first tried deleting It does not break the paths that already workedFull cartesian product of Each cell also asserts no Full backend regression, PR branch versus
The same 35, all a pre-existing torchao/torch mismatch in my venv ( Three more things I changed1. The ROCm probe no longer imports torch. My earlier fix moved Every ROCm distribution spells I kept the To be sure the matrix rule was not vacuous, I ran the original probe back through the same harness: it fails the no-torch-import assertion, the new one passes. Rule bites. 2.
3. DiT training accepted explicit
Rejected on Compatibilityhuggingface_hub. Eight isolated Worth knowing why that matters: on 0.20.3 and 0.23.5 Each venv also covers a ten-deep wrapper chain, a self-referential Old installs. Platforms. macOS never reaches the guard at all: One thing I checked and deliberately did not changeWith xformers stubbed, diffusers believes it is usable: The only thing preventing that is Not in this PR
Reproducing any of itThe harnesses are standalone: a per-cell runner for the matrix, the old-probe control, the end-to-end import wall, and the hub venv sweep. Happy to attach them if useful. |
…t token reads as none
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
|
Codex Review: Didn't find any major issues. Nice work! 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". |
What
Fixes #7992 On a Windows ROCm host every image and video model fails to load. Two separate walls, one PR.
1. Nothing diffusers can import
Loading Z-Image reported
module 'torch.distributed' has no attribute 'Work', which names neither the package at fault nor the cause.The Windows pin at
pyproject.toml:171isxformers>=0.0.22.post7 ; sys_platform == 'win32', with no CUDA condition, so a ROCm venv gets a CUDA-only xformers. A ROCm torch ships no distributed backend, andimport xformers.opswalks straight intotorch.distributed. diffusers imports xformers whenever it is installed, so every diffusers model import dies with it. Clear that one and diffusers reaches torchao through its quantizers and dies the same way.The repo already had the fix shape for torchao,
core/_torchao_stub.py, just never called on the diffusion path. This adds the matching xformers stub beside it and installs both at module scope incore/inference/diffusion.pyandcore/training/diffusion_train_common.py, ahead of every lazyimport diffusersbelow them. The trainers run in a spawned child, so they need their own install. No-op on every other runtime.2. A gated repo pasted its 403 back at you
black-forest-labs/FLUX.2-klein-9Bis gated, and the loader surfaced the rawGatedRepoErrorverbatim: a request id, a resolve URL, and one useful sentence. It now names the repo, links its page, and asks for a token only when none was sent. The full exception still reaches the log.Verification
diffusers.models.transformers.transformer_z_image, now imports through the realcore.inference.diffusionpath in a Windows ROCm venv. So doesDiffusionPipeline.test_zimage_forward_matches_stock_*arch-patch tests.test_xformers_stub_diffusion_parity.pypins the stub behaviour and asserts both installs stay at module scope in both modules;test_diffusion_hub_access.pycovers the gated message with and without a token, an unparseable repo, and that unrelated errors keep their own text. 12 pass.compileall,ruff check,scripts/verify_import_hoist.pyall clean.Follow-ups, not in this PR
diffusion_attention.pystill offersxformersas a selectable backend on that platform. It is the NVIDIA path, aiter is the AMD one, so selecting it there should be rejected rather than dispatched into a stub.