-
Notifications
You must be signed in to change notification settings - Fork 6.2k
feat: cuda device_map for pipelines. #12122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Could we add a simple fast GPU test
@DN6 done! I have added a test, too. |
@@ -67,6 +67,7 @@ | |||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah my thoughts too. We should actually move torch_device
to utils
.
What does this PR do?
TL;DR: This PR adds a
device_map
option 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_map
for 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?