-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[tests] refactor UNet model tests to align with the new pattern #13153
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
Open
sayakpaul
wants to merge
15
commits into
main
Choose a base branch
from
unet-model-tests-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
14439ab
refactor unet2d condition model tests.
sayakpaul 0e42a3f
fix tests
sayakpaul 2b67fb6
up
sayakpaul 46d44b7
fix
sayakpaul 3371560
Revert "fix"
sayakpaul ca4a7b0
up
sayakpaul 3a61081
Merge branch 'main' into unet-model-tests-refactor
sayakpaul ea08148
recompile limit
sayakpaul ffb254a
[tests] refactor test_models_unet_1d.py to use modular testing mixins
sayakpaul 0411da7
[tests] refactor test_models_unet_2d.py to use modular testing mixins
sayakpaul ecbaed7
[tests] refactor test_models_unet_3d_condition.py to use modular test…
sayakpaul c6e6992
[tests] refactor test_models_unet_controlnetxs.py to use modular test…
sayakpaul 99de4ce
[tests] refactor test_models_unet_spatiotemporal.py to use modular te…
sayakpaul 5f8303f
remove test suites that are passed.
sayakpaul ecfd3b4
Merge branch 'main' into unet-model-tests-refactor
sayakpaul 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
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 |
|---|---|---|
|
|
@@ -92,9 +92,6 @@ def test_torch_compile_repeated_blocks(self, recompile_limit=1): | |
| model.eval() | ||
| model.compile_repeated_blocks(fullgraph=True) | ||
|
|
||
| if self.model_class.__name__ == "UNet2DConditionModel": | ||
| recompile_limit = 2 | ||
|
|
||
|
Comment on lines
-95
to
-97
Member
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. Not needed as we pass |
||
| with ( | ||
| torch._inductor.utils.fresh_inductor_cache(), | ||
| torch._dynamo.config.patch(recompile_limit=recompile_limit), | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
|
|
||
| import gc | ||
| import json | ||
| import logging | ||
| import os | ||
| import re | ||
|
|
||
|
|
@@ -23,10 +24,12 @@ | |
| import torch | ||
| import torch.nn as nn | ||
|
|
||
| from diffusers.utils import logging as diffusers_logging | ||
| from diffusers.utils.import_utils import is_peft_available | ||
| from diffusers.utils.testing_utils import check_if_dicts_are_equal | ||
|
|
||
| from ...testing_utils import ( | ||
| CaptureLogger, | ||
| assert_tensors_close, | ||
| backend_empty_cache, | ||
| is_lora, | ||
|
|
@@ -477,32 +480,34 @@ def test_enable_lora_hotswap_called_after_adapter_added_raises(self): | |
| with pytest.raises(RuntimeError, match=msg): | ||
| model.enable_lora_hotswap(target_rank=32) | ||
|
|
||
| def test_enable_lora_hotswap_called_after_adapter_added_warning(self, caplog): | ||
|
Member
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. It was needed because |
||
| # ensure that enable_lora_hotswap is called before loading the first adapter | ||
| import logging | ||
|
|
||
| def test_enable_lora_hotswap_called_after_adapter_added_warning(self): | ||
| lora_config = self._get_lora_config(8, 8, target_modules=["to_q"]) | ||
| init_dict = self.get_init_dict() | ||
| model = self.model_class(**init_dict).to(torch_device) | ||
| model.add_adapter(lora_config) | ||
| msg = ( | ||
| "It is recommended to call `enable_lora_hotswap` before loading the first adapter to avoid recompilation." | ||
| ) | ||
| with caplog.at_level(logging.WARNING): | ||
|
|
||
| logger = diffusers_logging.get_logger("diffusers.loaders.peft") | ||
| logger.setLevel(logging.WARNING) | ||
| with CaptureLogger(logger) as cap_logger: | ||
| model.enable_lora_hotswap(target_rank=32, check_compiled="warn") | ||
| assert any(msg in record.message for record in caplog.records) | ||
|
|
||
| def test_enable_lora_hotswap_called_after_adapter_added_ignore(self, caplog): | ||
| # check possibility to ignore the error/warning | ||
| import logging | ||
| assert msg in str(cap_logger.out), f"Expected warning not found. Captured: {cap_logger.out}" | ||
|
|
||
| def test_enable_lora_hotswap_called_after_adapter_added_ignore(self): | ||
| lora_config = self._get_lora_config(8, 8, target_modules=["to_q"]) | ||
| init_dict = self.get_init_dict() | ||
| model = self.model_class(**init_dict).to(torch_device) | ||
| model.add_adapter(lora_config) | ||
| with caplog.at_level(logging.WARNING): | ||
|
|
||
| logger = diffusers_logging.get_logger("diffusers.loaders.peft") | ||
| logger.setLevel(logging.WARNING) | ||
| with CaptureLogger(logger) as cap_logger: | ||
| model.enable_lora_hotswap(target_rank=32, check_compiled="ignore") | ||
| assert len(caplog.records) == 0 | ||
|
|
||
| assert cap_logger.out == "", f"Expected no warnings but found: {cap_logger.out}" | ||
|
|
||
| def test_enable_lora_hotswap_wrong_check_compiled_argument_raises(self): | ||
| # check that wrong argument value raises an error | ||
|
|
@@ -515,9 +520,6 @@ def test_enable_lora_hotswap_wrong_check_compiled_argument_raises(self): | |
| model.enable_lora_hotswap(target_rank=32, check_compiled="wrong-argument") | ||
|
|
||
| def test_hotswap_second_adapter_targets_more_layers_raises(self, tmp_path, caplog): | ||
| # check the error and log | ||
| import logging | ||
|
|
||
| # at the moment, PEFT requires the 2nd adapter to target the same or a subset of layers | ||
| target_modules0 = ["to_q"] | ||
| target_modules1 = ["to_q", "to_k"] | ||
|
|
||
Oops, something went wrong.
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.
To ensure reproducibility.