Uh oh!
There was an error while loading. Please reload this page.
fix: add PyTorch version check for torch.accelerator in gather_size_by_comm - #13093
fix: add PyTorch version check for torch.accelerator in gather_size_by_comm#13093Mr-Neutr0n wants to merge 2 commits into
Conversation
…y_comm torch.accelerator.current_accelerator() only exists in PyTorch 2.6+. Since diffusers officially supports PyTorch 2.1+, this causes AttributeError on versions 2.1-2.5. Added hasattr check with fallback to 'cuda' for older PyTorch versions, matching the pattern already used in lora_pipeline.py. Fixes#13074
Mr-Neutr0n
commented
Feb 12, 2026
Friendly bump! Let me know if there's anything I should update or improve to help move this forward. |
| elif hasattr(torch, "accelerator"): | ||
| gather_device = torch.accelerator.current_accelerator() | ||
| else: | ||
| gather_device = "cuda" |
There was a problem hiding this comment.
I think this can actually be reduced to a one liner if we use
diffusers/src/diffusers/utils/torch_utils.py
Line 281 in 2843b3d
gather_device="cpu"if"cpu"incomm_backendselseget_device()@DN6 (2026-02-13) suggested using the existing get_device() helper from torch_utils instead of the inline hasattr(torch, "accelerator") check. get_device() already returns the appropriate device string for the current environment and falls back to cpu when no accelerator is available, which makes the three-branch if/elif/else a one-liner.
Mr-Neutr0n
commented
Jun 1, 2026
@DN6 — done. Pushed as |
qgallouedec
commented
Jul 23, 2026
This contribution comes from a profile that opens a massive number of pull requests generated purely by AI; I'm closing it. |
Summary
Add backward compatibility check for
torch.accelerator.current_accelerator()which only exists in PyTorch 2.6+.Problem
gather_size_by_comm()in_modeling_parallel.pyusestorch.accelerator.current_accelerator()without checking if it exists. Since diffusers officially supports PyTorch 2.1+, this causesAttributeError: module 'torch' has no attribute 'accelerator'on PyTorch versions 2.1-2.5.Solution
Added
hasattr(torch, "accelerator")check with fallback to"cuda"for older PyTorch versions. This matches the pattern already used in other parts of the codebase:src/diffusers/loaders/lora_pipeline.py(line 111)src/diffusers/hooks/group_offloading.py(lines 121-125)src/diffusers/quantizers/gguf/gguf_quantizer.py(lines 159-163)Fixes#13074