feat: cuda device_map for pipelines.#12122
Merged
Conversation
|
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. |
DN6
reviewed
Aug 12, 2025
Collaborator
DN6
left a comment
There was a problem hiding this comment.
LGTM. Could we add a simple fast GPU test
Member
Author
|
@DN6 done! I have added a test, too. |
DN6
reviewed
Aug 13, 2025
| numpy_to_pil, | ||
| ) | ||
| from ..utils.hub_utils import _check_legacy_sharding_variant_format, load_or_create_model_card, populate_model_card | ||
| from ..utils.testing_utils import torch_device |
Collaborator
There was a problem hiding this comment.
I would prefer not to import from testing_utils for non-test modules (in fact we should move this module out of src). It would be better to redefine the relevant torch_device functionality in torch_utils and import from there.
Member
Author
There was a problem hiding this comment.
Yeah my thoughts too. We should actually move torch_device to utils.
DN6
approved these changes
Aug 14, 2025
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?
TL;DR: This PR adds a
device_mapoption at the pipeline-level to speed up end-to-end pipeline loading on a target device.To benefit from #11904, users have to follow this pattern:
We could improve the UX a bit by letting the users pass a
device_map="cuda"(or whatever valid value) WHILE initializing thepipe. This PR tackles that =>For pipelines like Flux, passing
device_mapfor loading the text encoders might be as same as doingto(). However, for pipelines like Qwen-Image, that use a mid-range model like Qwen25VL-7B, passingdevice_map="cuda"while initializing the pipeline should be beneficial (of course, the target device should have enough VRAM to support this). Below are the results I got for Qwen-Image (with cold cache):Code
Any objections?