Repository navigation
Closed
Labels
bugSomething isn't working
Description
Describe the bug
BriaTransformer2DModel introduces a hard dependency on torch._C._distributed_c10d which is NOT present in all torch variants/flavors.
Any torch._C import should be guarded with if-available, not a hard dependency on the entire library.
Without that, diffusers stop being a cross-platform solution.
Reproduction
Attempt to import diffusers, it will immediately fail
Downstream issue: vladmandic/sdnext#4240
Logs
│E:\Work\LLM\sdnext-amd\venv\Lib\site-packages\diffusers\models\transformers\__init__.py:20 in <module> │
│ │
│ 19 from .transformer_allegro import AllegroTransformer3DModel │
│❱ 20 from .transformer_bria import BriaTransformer2DModel │
│ 21 from .transformer_chroma import ChromaTransformer2DModel │
│ │
│E:\Work\LLM\sdnext-amd\venv\Lib\site-packages\diffusers\models\transformers\transformer_bria.py:14 in <module> │
│ │
│ 13 from ..attention import AttentionModuleMixin, FeedForward │
│❱ 14 from ..attention_dispatch import dispatch_attention_fn │
│ 15 from ..cache_utils import CacheMixin │
│ │
│E:\Work\LLM\sdnext-amd\venv\Lib\site-packages\diffusers\models\attention_dispatch.py:23 in <module> │
│ │
│ 22 import torch │
│❱ 23 import torch.distributed._functional_collectives as funcol │
│ 24 │
│ │
│E:\Work\LLM\sdnext-amd\venv\Lib\site-packages\torch\distributed\_functional_collectives.py:9 in <module> │
│ │
│ 8 import torch.distributed as dist │
│❱ 9 import torch.distributed.distributed_c10d as c10d │
│ 10 from torch.distributed.device_mesh import DeviceMesh │
│ │
│E:\Work\LLM\sdnext-amd\venv\Lib\site-packages\torch\distributed\distributed_c10d.py:23 in <module> │
│ │
│ 22 from torch._C import _DistStoreError as DistStoreError │
│❱ 23 from torch._C._distributed_c10d import ( │
│ 24 _DistributedBackendOptions, │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
ModuleNotFoundError: No module named 'torch._C._distributed_c10d'; 'torch._C' is not a packageSystem Info
diffusers main branch: 64a5187
torch-rocm for windows preview build, specifically from https://repo.radeon.com/rocm/windows/rocm-rel-6.4.4/torch/
Who can help?
Reacted by Sayak Paul
Activity
0xDELUXA commentedon Oct 1, 2025
We had the same issue with TheRock wheels on Windows, where transformers tried to import this exact
torch._C._distributed_c10dpackage.The solution came with huggingface/transformers#40038 which checks whether it is available. If not, it does not try to import it, and no error is raised. I think we need something like this here too.
vladmandic commentedon Oct 1, 2025
in diffusers, the issue is of unsafe imports is introduced via #11941 which adds optional context-parallel features.
its not specific to bria transformer specifically, its just where this import sequence is first triggered.
0xDELUXA commentedon Oct 1, 2025
I see. Looking forward to a fix.
sayakpaul commentedon Oct 2, 2025
#12420
vladmandic commentedon Oct 2, 2025
issue is NOT resolved as there are other code paths in diffuers that lead to same problem. ANY torch._C import should be safe-guarded.
vladmandic commentedon Oct 2, 2025
and one more code path causing same crash!
sayakpaul commentedon Oct 3, 2025
Sorry
#12425
vladmandic commentedon Oct 10, 2025
resolved, thanks!