-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[CI] Refactor Chronoedit, PRX, EasyAnimate, Ovis transformer tests #13347
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
test-refactor-chrono-ovis-easy-animate-prx
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.
+305
−67
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
106 changes: 106 additions & 0 deletions
106
tests/models/transformers/test_models_transformer_chronoedit.py
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 |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # coding=utf-8 | ||
| # Copyright 2025 HuggingFace Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import torch | ||
|
|
||
| from diffusers import ChronoEditTransformer3DModel | ||
| from diffusers.utils.torch_utils import randn_tensor | ||
|
|
||
| from ...testing_utils import enable_full_determinism, torch_device | ||
| from ..testing_utils import ( | ||
| BaseModelTesterConfig, | ||
| ModelTesterMixin, | ||
| TorchCompileTesterMixin, | ||
| TrainingTesterMixin, | ||
| ) | ||
|
|
||
|
|
||
| enable_full_determinism() | ||
|
|
||
|
|
||
| class ChronoEditTransformerTesterConfig(BaseModelTesterConfig): | ||
| @property | ||
| def model_class(self): | ||
| return ChronoEditTransformer3DModel | ||
|
|
||
| @property | ||
| def main_input_name(self) -> str: | ||
| return "hidden_states" | ||
|
|
||
| @property | ||
| def output_shape(self) -> tuple: | ||
| return (16, 8, 8) | ||
|
|
||
| @property | ||
| def input_shape(self) -> tuple: | ||
| return (16, 8, 8) | ||
|
|
||
| @property | ||
| def generator(self): | ||
| return torch.Generator("cpu").manual_seed(0) | ||
|
|
||
| def get_init_dict(self) -> dict: | ||
| return { | ||
| "patch_size": (1, 2, 2), | ||
| "num_attention_heads": 2, | ||
| "attention_head_dim": 8, | ||
| "in_channels": 16, | ||
| "out_channels": 16, | ||
| "text_dim": 32, | ||
| "freq_dim": 16, | ||
| "ffn_dim": 32, | ||
| "num_layers": 2, | ||
| "cross_attn_norm": True, | ||
| "qk_norm": "rms_norm_across_heads", | ||
| "eps": 1e-06, | ||
| "image_dim": None, | ||
| "added_kv_proj_dim": None, | ||
| "rope_max_seq_len": 64, | ||
| "pos_embed_seq_len": None, | ||
| "rope_temporal_skip_len": 8, | ||
| } | ||
|
|
||
| def get_dummy_inputs(self, batch_size: int = 1) -> dict[str, torch.Tensor]: | ||
| num_channels = 16 | ||
| num_frames = 2 | ||
| height = 8 | ||
| width = 8 | ||
| embedding_dim = 32 | ||
| sequence_length = 12 | ||
|
|
||
| return { | ||
| "hidden_states": randn_tensor( | ||
| (batch_size, num_channels, num_frames, height, width), generator=self.generator, device=torch_device | ||
| ), | ||
| "timestep": torch.randint(0, 1000, size=(batch_size,), generator=self.generator).to(torch_device), | ||
| "encoder_hidden_states": randn_tensor( | ||
| (batch_size, sequence_length, embedding_dim), generator=self.generator, device=torch_device | ||
| ), | ||
| "encoder_hidden_states_image": None, | ||
| } | ||
|
|
||
|
|
||
| class TestChronoEditTransformer(ChronoEditTransformerTesterConfig, ModelTesterMixin): | ||
| pass | ||
|
|
||
|
|
||
| class TestChronoEditTransformerTraining(ChronoEditTransformerTesterConfig, TrainingTesterMixin): | ||
| def test_gradient_checkpointing_is_applied(self): | ||
| expected_set = {"ChronoEditTransformer3DModel"} | ||
| super().test_gradient_checkpointing_is_applied(expected_set=expected_set) | ||
|
|
||
|
|
||
| class TestChronoEditTransformerCompile(ChronoEditTransformerTesterConfig, TorchCompileTesterMixin): | ||
| pass | ||
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,58 +13,46 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import unittest | ||
|
|
||
| import torch | ||
|
|
||
| from diffusers import EasyAnimateTransformer3DModel | ||
| 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. Not sure if we need it. |
||
| TrainingTesterMixin, | ||
| ) | ||
|
|
||
|
|
||
| enable_full_determinism() | ||
|
|
||
|
|
||
| class EasyAnimateTransformerTests(ModelTesterMixin, unittest.TestCase): | ||
| model_class = EasyAnimateTransformer3DModel | ||
| main_input_name = "hidden_states" | ||
| uses_custom_attn_processor = True | ||
|
|
||
| class EasyAnimateTransformerTesterConfig(BaseModelTesterConfig): | ||
| @property | ||
| def dummy_input(self): | ||
| batch_size = 2 | ||
| num_channels = 4 | ||
| num_frames = 2 | ||
| height = 16 | ||
| width = 16 | ||
| embedding_dim = 16 | ||
| sequence_length = 16 | ||
| def model_class(self): | ||
| return EasyAnimateTransformer3DModel | ||
|
|
||
| hidden_states = torch.randn((batch_size, num_channels, num_frames, height, width)).to(torch_device) | ||
| encoder_hidden_states = torch.randn((batch_size, sequence_length, embedding_dim)).to(torch_device) | ||
| timestep = torch.randint(0, 1000, size=(batch_size,)).to(torch_device) | ||
|
|
||
| return { | ||
| "hidden_states": hidden_states, | ||
| "timestep": timestep, | ||
| "timestep_cond": None, | ||
| "encoder_hidden_states": encoder_hidden_states, | ||
| "encoder_hidden_states_t5": None, | ||
| "inpaint_latents": None, | ||
| "control_latents": None, | ||
| } | ||
| @property | ||
| def main_input_name(self) -> str: | ||
| return "hidden_states" | ||
|
|
||
| @property | ||
| def input_shape(self): | ||
| def output_shape(self) -> tuple: | ||
| return (4, 2, 16, 16) | ||
|
|
||
| @property | ||
| def output_shape(self): | ||
| def input_shape(self) -> tuple: | ||
| return (4, 2, 16, 16) | ||
|
|
||
| def prepare_init_args_and_inputs_for_common(self): | ||
| init_dict = { | ||
| @property | ||
| def generator(self): | ||
| return torch.Generator("cpu").manual_seed(0) | ||
|
|
||
| def get_init_dict(self) -> dict: | ||
| return { | ||
| "attention_head_dim": 16, | ||
| "num_attention_heads": 2, | ||
| "in_channels": 4, | ||
|
|
@@ -79,9 +67,39 @@ def prepare_init_args_and_inputs_for_common(self): | |
| "time_position_encoding_type": "3d_rope", | ||
| "timestep_activation_fn": "silu", | ||
| } | ||
| inputs_dict = self.dummy_input | ||
| return init_dict, inputs_dict | ||
|
|
||
| def get_dummy_inputs(self, batch_size: int = 2) -> dict[str, torch.Tensor]: | ||
| num_channels = 4 | ||
| num_frames = 2 | ||
| height = 16 | ||
| width = 16 | ||
| embedding_dim = 16 | ||
| sequence_length = 16 | ||
|
|
||
| return { | ||
| "hidden_states": randn_tensor( | ||
| (batch_size, num_channels, num_frames, height, width), generator=self.generator, device=torch_device | ||
| ), | ||
| "timestep": torch.randint(0, 1000, size=(batch_size,), generator=self.generator).to(torch_device), | ||
| "timestep_cond": None, | ||
| "encoder_hidden_states": randn_tensor( | ||
| (batch_size, sequence_length, embedding_dim), generator=self.generator, device=torch_device | ||
| ), | ||
| "encoder_hidden_states_t5": None, | ||
| "inpaint_latents": None, | ||
| "control_latents": None, | ||
| } | ||
|
|
||
|
|
||
| class TestEasyAnimateTransformer(EasyAnimateTransformerTesterConfig, ModelTesterMixin): | ||
| pass | ||
|
|
||
|
|
||
| class TestEasyAnimateTransformerTraining(EasyAnimateTransformerTesterConfig, TrainingTesterMixin): | ||
| def test_gradient_checkpointing_is_applied(self): | ||
| expected_set = {"EasyAnimateTransformer3DModel"} | ||
| super().test_gradient_checkpointing_is_applied(expected_set=expected_set) | ||
|
|
||
|
|
||
| class TestEasyAnimateTransformerCompile(EasyAnimateTransformerTesterConfig, TorchCompileTesterMixin): | ||
| pass | ||
102 changes: 102 additions & 0 deletions
102
tests/models/transformers/test_models_transformer_ovis_image.py
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 |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # coding=utf-8 | ||
| # Copyright 2025 HuggingFace Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import torch | ||
|
|
||
| from diffusers import OvisImageTransformer2DModel | ||
| from diffusers.utils.torch_utils import randn_tensor | ||
|
|
||
| from ...testing_utils import enable_full_determinism, torch_device | ||
| 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. Not sure if we need it. |
||
| TrainingTesterMixin, | ||
| ) | ||
|
|
||
|
|
||
| enable_full_determinism() | ||
|
|
||
|
|
||
| class OvisImageTransformerTesterConfig(BaseModelTesterConfig): | ||
| @property | ||
| def model_class(self): | ||
| return OvisImageTransformer2DModel | ||
|
|
||
| @property | ||
| def main_input_name(self) -> str: | ||
| return "hidden_states" | ||
|
|
||
| @property | ||
| def output_shape(self) -> tuple: | ||
| return (16, 4) | ||
|
|
||
| @property | ||
| def input_shape(self) -> tuple: | ||
| return (16, 4) | ||
|
|
||
| @property | ||
| def generator(self): | ||
| return torch.Generator("cpu").manual_seed(0) | ||
|
|
||
| def get_init_dict(self) -> dict: | ||
| return { | ||
| "patch_size": 1, | ||
| "in_channels": 4, | ||
| "out_channels": 4, | ||
| "num_layers": 1, | ||
| "num_single_layers": 1, | ||
| "attention_head_dim": 16, | ||
| "num_attention_heads": 2, | ||
| "joint_attention_dim": 32, | ||
| "axes_dims_rope": (4, 4, 8), | ||
| } | ||
|
|
||
| def get_dummy_inputs(self, batch_size: int = 1) -> dict[str, torch.Tensor]: | ||
| num_latent_channels = 4 | ||
| num_image_channels = 3 | ||
| height = width = 4 | ||
| sequence_length = 48 | ||
| embedding_dim = 32 | ||
|
|
||
| return { | ||
| "hidden_states": randn_tensor( | ||
| (batch_size, height * width, num_latent_channels), generator=self.generator, device=torch_device | ||
| ), | ||
| "encoder_hidden_states": randn_tensor( | ||
| (batch_size, sequence_length, embedding_dim), generator=self.generator, device=torch_device | ||
| ), | ||
| "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), | ||
| } | ||
|
|
||
|
|
||
| class TestOvisImageTransformer(OvisImageTransformerTesterConfig, ModelTesterMixin): | ||
| pass | ||
|
|
||
|
|
||
| class TestOvisImageTransformerTraining(OvisImageTransformerTesterConfig, TrainingTesterMixin): | ||
| def test_gradient_checkpointing_is_applied(self): | ||
| expected_set = {"OvisImageTransformer2DModel"} | ||
| super().test_gradient_checkpointing_is_applied(expected_set=expected_set) | ||
|
|
||
|
|
||
| class TestOvisImageTransformerCompile(OvisImageTransformerTesterConfig, TorchCompileTesterMixin): | ||
| pass | ||
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.
Not sure if we need it.