-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[CI] Refactor Bria Transformer Tests #13341
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
DN6
wants to merge
2
commits into
main
Choose a base branch
from
bria-test-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.
+160
−96
Open
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 |
|---|---|---|
|
|
@@ -13,62 +13,50 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import unittest | ||
|
|
||
| import torch | ||
|
|
||
| from diffusers import BriaFiboTransformer2DModel | ||
| from diffusers.utils.torch_utils import randn_tensor | ||
|
|
||
| from ...testing_utils import enable_full_determinism, torch_device | ||
| from ..test_modeling_common import ModelTesterMixin | ||
| from ..testing_utils import ( | ||
| BaseModelTesterConfig, | ||
| ModelTesterMixin, | ||
| TorchCompileTesterMixin, | ||
|
Member
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. Same comment as above. |
||
| TrainingTesterMixin, | ||
| ) | ||
|
|
||
|
|
||
| enable_full_determinism() | ||
|
|
||
|
|
||
| class BriaFiboTransformerTests(ModelTesterMixin, unittest.TestCase): | ||
| model_class = BriaFiboTransformer2DModel | ||
| main_input_name = "hidden_states" | ||
| # We override the items here because the transformer under consideration is small. | ||
| model_split_percents = [0.8, 0.7, 0.7] | ||
|
|
||
| # Skip setting testing with default: AttnProcessor | ||
| uses_custom_attn_processor = True | ||
| class BriaFiboTransformerTesterConfig(BaseModelTesterConfig): | ||
| @property | ||
| def model_class(self): | ||
| return BriaFiboTransformer2DModel | ||
|
|
||
| @property | ||
| def dummy_input(self): | ||
| batch_size = 1 | ||
| num_latent_channels = 48 | ||
| num_image_channels = 3 | ||
| height = width = 16 | ||
| sequence_length = 32 | ||
| embedding_dim = 64 | ||
| def main_input_name(self) -> str: | ||
| return "hidden_states" | ||
|
|
||
| hidden_states = torch.randn((batch_size, height * width, num_latent_channels)).to(torch_device) | ||
| encoder_hidden_states = torch.randn((batch_size, sequence_length, embedding_dim)).to(torch_device) | ||
| text_ids = torch.randn((sequence_length, num_image_channels)).to(torch_device) | ||
| image_ids = torch.randn((height * width, num_image_channels)).to(torch_device) | ||
| timestep = torch.tensor([1.0]).to(torch_device).expand(batch_size) | ||
| @property | ||
| def model_split_percents(self) -> list: | ||
| return [0.8, 0.7, 0.7] | ||
|
|
||
| return { | ||
| "hidden_states": hidden_states, | ||
| "encoder_hidden_states": encoder_hidden_states, | ||
| "img_ids": image_ids, | ||
| "txt_ids": text_ids, | ||
| "timestep": timestep, | ||
| "text_encoder_layers": [encoder_hidden_states[:, :, :32], encoder_hidden_states[:, :, :32]], | ||
| } | ||
| @property | ||
| def output_shape(self) -> tuple: | ||
| return (256, 48) | ||
|
|
||
| @property | ||
| def input_shape(self): | ||
| def input_shape(self) -> tuple: | ||
| return (16, 16) | ||
|
|
||
| @property | ||
| def output_shape(self): | ||
| return (256, 48) | ||
| def generator(self): | ||
| return torch.Generator("cpu").manual_seed(0) | ||
|
|
||
| def prepare_init_args_and_inputs_for_common(self): | ||
| init_dict = { | ||
| def get_init_dict(self) -> dict: | ||
| return { | ||
| "patch_size": 1, | ||
| "in_channels": 48, | ||
| "num_layers": 1, | ||
|
|
@@ -81,9 +69,41 @@ def prepare_init_args_and_inputs_for_common(self): | |
| "axes_dims_rope": [0, 4, 4], | ||
| } | ||
|
|
||
| inputs_dict = self.dummy_input | ||
| return init_dict, inputs_dict | ||
| def get_dummy_inputs(self, batch_size: int = 1) -> dict[str, torch.Tensor]: | ||
| num_latent_channels = 48 | ||
| num_image_channels = 3 | ||
| height = width = 16 | ||
| sequence_length = 32 | ||
| embedding_dim = 64 | ||
|
|
||
| encoder_hidden_states = randn_tensor( | ||
| (batch_size, sequence_length, embedding_dim), generator=self.generator, device=torch_device | ||
| ) | ||
| return { | ||
| "hidden_states": randn_tensor( | ||
| (batch_size, height * width, num_latent_channels), generator=self.generator, device=torch_device | ||
| ), | ||
| "encoder_hidden_states": encoder_hidden_states, | ||
| "img_ids": randn_tensor( | ||
| (height * width, num_image_channels), generator=self.generator, device=torch_device | ||
| ), | ||
| "txt_ids": randn_tensor( | ||
| (sequence_length, num_image_channels), generator=self.generator, device=torch_device | ||
| ), | ||
| "timestep": torch.tensor([1.0]).to(torch_device).expand(batch_size), | ||
| "text_encoder_layers": [encoder_hidden_states[:, :, :32], encoder_hidden_states[:, :, :32]], | ||
| } | ||
|
|
||
|
|
||
| class TestBriaFiboTransformer(BriaFiboTransformerTesterConfig, ModelTesterMixin): | ||
| pass | ||
|
|
||
|
|
||
| class TestBriaFiboTransformerTraining(BriaFiboTransformerTesterConfig, TrainingTesterMixin): | ||
| def test_gradient_checkpointing_is_applied(self): | ||
| expected_set = {"BriaFiboTransformer2DModel"} | ||
| super().test_gradient_checkpointing_is_applied(expected_set=expected_set) | ||
|
|
||
|
|
||
| class TestBriaFiboTransformerCompile(BriaFiboTransformerTesterConfig, TorchCompileTesterMixin): | ||
| pass | ||
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.
I guess we can remove the expensive test suites from here provided the popularity of the model?