pytorch - 💡(How to fix) Fix Allow registering multiple out-of-tree backends and setting current_accelerator [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#180345Fetched 2026-04-16 06:35:11
View on GitHub
Comments
1
Participants
2
Timeline
15
Reactions
0
Timeline (top)
labeled ×5subscribed ×5mentioned ×4commented ×1
RAW_BUFFERClick to expand / collapse

🚀 The feature, motivation and pitch

Currently PyTorch fundamentally assumes that you have one accelerator, which has a few consequences:

  1. It is not possible to register more than one out-of-tree backend extension at the same time, and trying to do so is a hard failure. Combined with the autoload mechanism, this means that if you get two out-of-tree backends installed in the same environment importing torch itself will fail.
  2. There is no way to set the "current accelerator" to a specific accelerator. If I were to install a "testing" backend, for example (I think openreg might meet this standard), I probably do not want it to be current_accelerator. You can also imagine alternate backend implementations for CPU and CUDA (e.g. if we wanted to add an XLA backend for use with CUDA GPUs, we might want to provide that as an option for users, but not have it automatically used for accelerator.current_accelerator().

Ideally, the out-of-tree extension mechanism would be changed to allow registering arbitrary backends rather than having a single hard-coded slot for "other". I think there are also privateuse2 and privateuse3 backends, but no corresponding interfaces for renaming them, and no interface for selecting whcih one is the current accelerator.

For problem 1, my preferred solutions would be, in order:

  1. Allow registering an arbitrary number of backends instead of renaming privateuse1.
  2. If for some reason all devices must be hard-coded at compile time, expand out the number of "private use" backends to something like 5 or 10.
  3. Allow registering an arbitrary number of modules, but allow swapping out which one is the privateuse1 "device". (This sounds fraught but it's the only other real solution I can think of that maintains a fixed number of devices while allowing registering arbitrary numbers of modules).

I think in both 1 and 2, it would be best if the interface were torch.utils.register_backend(device_name, module) and the renaming of privateuse1 or privateuse2 or whatever would be an implementation detail not exposed to end users.

For problem 2, I think the solution is a lot more straightforward from an interface point of view, you'd just want to add a torch.accelerator.set_current_accelerator(device) function (though I suspect adding that interface will expose a few more concurrency bugs than you currently see, even though it's not necessarily adding new capabilities since you can always rename the privateuse1 backend and implicitly set the accelerator at some random point in the program's execution).

Alternatives

No response

Additional context

No response

cc @bdhirsh @albanD @guangyey @EikanWang

extent analysis

TL;DR

To resolve the issue of PyTorch assuming a single accelerator and limitations with out-of-tree backend extensions, consider modifying the extension mechanism to allow registering arbitrary backends.

Guidance

  • Investigate modifying the torch.utils module to include a function like register_backend(device_name, module) to enable registration of multiple backends.
  • Consider adding a torch.accelerator.set_current_accelerator(device) function to allow setting the current accelerator to a specific device.
  • Evaluate the feasibility of expanding the number of "private use" backends to accommodate more devices without requiring significant changes to the existing architecture.
  • Assess the potential concurrency implications of introducing a set_current_accelerator function to ensure thread safety.

Example

No specific code example is provided due to the lack of detailed implementation requirements in the issue.

Notes

The solution may require significant changes to PyTorch's internal architecture and extension mechanisms. It is essential to consider the potential impact on existing code and the introduction of new concurrency bugs.

Recommendation

Apply a workaround by modifying the existing extension mechanism to allow for the registration of multiple backends, as this approach seems to be the most feasible solution based on the provided information.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING