Skip to content

fix: Fix context-parallel gather crash on PyTorch < 2.6 - #14515

Open
Ricardo-M-L wants to merge 1 commit into
huggingface:mainfrom
Ricardo-M-L:fix/modeling-parallel-torch-accelerator-guard-clean
Open

fix: Fix context-parallel gather crash on PyTorch < 2.6#14515
Ricardo-M-L wants to merge 1 commit into
huggingface:mainfrom
Ricardo-M-L:fix/modeling-parallel-torch-accelerator-guard-clean

Conversation

@Ricardo-M-L

Copy link
Copy Markdown
Contributor

Clean rebase

`torch.accelerator` was added in PyTorch 2.6, but diffusers still supports
2.1+. `gather_size_by_comm` unconditionally calls
`torch.accelerator.current_accelerator()` whenever the backend is not CPU,
so any user running distributed context parallelism on an older torch hits
`AttributeError: module 'torch' has no attribute 'accelerator'` before a
single collective runs.

Guard the call with `hasattr(torch, "accelerator")` and fall back to
`torch.cuda.current_device()` on older versions — the same pattern already
used in `loaders/lora_pipeline.py`, `quantizers/gguf/gguf_quantizer.py`,
and `hooks/group_offloading.py`.

Fixes huggingface#13074
@github-actions github-actions Bot added models size/S PR with diff < 50 LOC labels Aug 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi @Ricardo-M-L, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Fixes #1234) to the PR description so the issue is linked. See the contribution guide for more details. If this PR intentionally does not fix a tracked issue, a maintainer can add the no-issue-needed label to silence this reminder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant