Conversation
DN6
commented
Sep 16, 2026
| image = latents | ||
| else: | ||
| latents = latents.to(self.vae.dtype) | ||
| torch_accelerator_module = getattr(torch, get_device(), torch.cuda) |
Collaborator
Author
There was a problem hiding this comment.
Deadcode since min supported torch version is 2.6
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
sayakpaul
reviewed
Sep 17, 2026
| raise ValueError("Using streams for data transfer requires a CUDA device, or an Intel XPU device.") | ||
| if use_stream and onload_device.type == "cpu": | ||
| raise ValueError("Using streams for data transfer requires an accelerator onload device, got `cpu`.") | ||
| stream = TorchDeviceBackend(onload_device).Stream() if use_stream else None |
Member
There was a problem hiding this comment.
What if the underlying device doesn't support streams?
Comment on lines
-1056
to
-1061
| torch_accelerator_module = getattr(torch, get_device(), torch.cuda) | ||
| oom_error = ( | ||
| torch.OutOfMemoryError | ||
| if is_torch_version(">=", "2.5.0") | ||
| else torch_accelerator_module.OutOfMemoryError | ||
| ) |
Member
There was a problem hiding this comment.
Safe because we pin on >=2.6.
Comment on lines
+224
to
+228
| def empty_cache(self) -> None: | ||
| # Backends without a caching allocator (cpu, neuron) have nothing to clear. | ||
| empty_cache = getattr(self.module, "empty_cache", None) | ||
| if empty_cache is not None: | ||
| empty_cache() |
Member
There was a problem hiding this comment.
Should we also warn in case empty_cache is None?
| """Tests for :class:`diffusers.utils.torch_utils.TorchDeviceBackend` on the CPU backend.""" | ||
|
|
||
| def test_module_resolves_from_str_and_torch_device(self): | ||
| import torch |
Member
There was a problem hiding this comment.
I think we can keep all the imports at the top. They seem harmless.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Support for torch device backends keeps growing, and each new backend adds a branch at every site that touches the device module. e.g. Adding NPU streams to group offloading (#14785) looks like this:
This PR introduces a
TorchDeviceBackendobject that automatically routes to the appropriate backend module for a given device type. e.g.Fixes # (issue)
Before submitting
self-reviewskill on the diff?documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.