-
Notifications
You must be signed in to change notification settings - Fork 6.5k
fix offload gpu tests etc #10366
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
Merged
Merged
fix offload gpu tests etc #10366
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ | |
| import requests_mock | ||
| import torch | ||
| import torch.nn as nn | ||
| from accelerate.utils.modeling import _get_proper_dtype, dtype_byte_size | ||
| from accelerate.utils.modeling import _get_proper_dtype, compute_module_sizes, dtype_byte_size | ||
| from huggingface_hub import ModelCard, delete_repo, snapshot_download | ||
| from huggingface_hub.utils import is_jinja_available | ||
| from parameterized import parameterized | ||
|
|
@@ -1080,7 +1080,7 @@ def test_cpu_offload(self): | |
| torch.manual_seed(0) | ||
| base_output = model(**inputs_dict) | ||
|
|
||
| model_size = compute_module_persistent_sizes(model)[""] | ||
| model_size = compute_module_sizes(model)[""] | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. follow up fix for this https://github.com/huggingface/diffusers/pull/10340/files#r1895134336 |
||
| # We test several splits of sizes to make sure it works. | ||
| max_gpu_sizes = [int(p * model_size) for p in self.model_split_percents[1:]] | ||
| with tempfile.TemporaryDirectory() as tmp_dir: | ||
|
|
@@ -1110,7 +1110,7 @@ def test_disk_offload_without_safetensors(self): | |
| torch.manual_seed(0) | ||
| base_output = model(**inputs_dict) | ||
|
|
||
| model_size = compute_module_persistent_sizes(model)[""] | ||
| model_size = compute_module_sizes(model)[""] | ||
| with tempfile.TemporaryDirectory() as tmp_dir: | ||
| model.cpu().save_pretrained(tmp_dir, safe_serialization=False) | ||
|
|
||
|
|
@@ -1144,7 +1144,7 @@ def test_disk_offload_with_safetensors(self): | |
| torch.manual_seed(0) | ||
| base_output = model(**inputs_dict) | ||
|
|
||
| model_size = compute_module_persistent_sizes(model)[""] | ||
| model_size = compute_module_sizes(model)[""] | ||
| with tempfile.TemporaryDirectory() as tmp_dir: | ||
| model.cpu().save_pretrained(tmp_dir) | ||
|
|
||
|
|
@@ -1172,7 +1172,7 @@ def test_model_parallelism(self): | |
| torch.manual_seed(0) | ||
| base_output = model(**inputs_dict) | ||
|
|
||
| model_size = compute_module_persistent_sizes(model)[""] | ||
| model_size = compute_module_sizes(model)[""] | ||
| # We test several splits of sizes to make sure it works. | ||
| max_gpu_sizes = [int(p * model_size) for p in self.model_split_percents[1:]] | ||
| with tempfile.TemporaryDirectory() as tmp_dir: | ||
|
|
@@ -1183,6 +1183,7 @@ def test_model_parallelism(self): | |
| new_model = self.model_class.from_pretrained(tmp_dir, device_map="auto", max_memory=max_memory) | ||
| # Making sure part of the model will actually end up offloaded | ||
| self.assertSetEqual(set(new_model.hf_device_map.values()), {0, 1}) | ||
| print(f" new_model.hf_device_map:{new_model.hf_device_map}") | ||
|
|
||
| self.check_device_map_is_respected(new_model, new_model.hf_device_map) | ||
|
|
||
|
|
||
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
Oops, something went wrong.
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.
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.
Not really a fan of this kind of device casting in
forwardbut okay to keep it since we don't have better solution yet. These usually end up creating problems for anything that modifies device/dtype with hooks and we then have to use some workarounds.Going forward, I think
nn.Parameter's can be put in their own dummynn.Moduleso that device map, or other things we're introducing (like group offloading or fp8 layerwise upcasting), works out of the box (as they will handle the weight/type-casting of inputs in overwritten pre-hook methods). If this sounds good, will do future model integrations with this designThere 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.
ohh I actually did not think about this at all (I just copied from the original code) - could you explain why do we need this device casting here?
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.
Ah okay, I see. I think I missed it when reviewing the PR that added Sana, otherwise would have probably removed it then. I'm not really sure why it is needed here, and think it might be okay to remove