From aae0fce83d0f0f95d7ed4ccb879292591a8f8de3 Mon Sep 17 00:00:00 2001 From: tongyu <119610311+tongyu0924@users.noreply.github.com> Date: Mon, 28 Apr 2025 12:21:06 +0800 Subject: [PATCH 1/2] Update test_models_transformer_hunyuan_video.py --- .../test_models_transformer_hunyuan_video.py | 67 ++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/tests/models/transformers/test_models_transformer_hunyuan_video.py b/tests/models/transformers/test_models_transformer_hunyuan_video.py index 495131ad6fd8..aa1140f78ea3 100644 --- a/tests/models/transformers/test_models_transformer_hunyuan_video.py +++ b/tests/models/transformers/test_models_transformer_hunyuan_video.py @@ -18,6 +18,7 @@ from diffusers import HunyuanVideoTransformer3DModel from diffusers.utils.testing_utils import enable_full_determinism, torch_device +from diffusers.utils.testing_utils import require_torch_gpu, require_torch_2, is_torch_compile, slow from ..test_modeling_common import ModelTesterMixin @@ -88,6 +89,25 @@ def prepare_init_args_and_inputs_for_common(self): def test_gradient_checkpointing_is_applied(self): expected_set = {"HunyuanVideoTransformer3DModel"} super().test_gradient_checkpointing_is_applied(expected_set=expected_set) + + def test_gradient_checkpointing_is_applied(self): + expected_set = {"HunyuanVideoTransformer3DModel"} + super().test_gradient_checkpointing_is_applied(expected_set=expected_set) + + @require_torch_gpu + @require_torch_2 + @is_torch_compile + @slow + def test_torch_compile_recompilation_and_graph_break(self): + torch._dynamo.reset() + init_dict, inputs_dict = self.prepare_init_args_and_inputs_for_common() + + model = self.model_class(**init_dict).to(torch_device) + model = torch.compile(model, fullgraph=True) + + with torch._dynamo.config.patch(error_on_recompile=True), torch.no_grad(): + _ = model(**inputs_dict) + _ = model(**inputs_dict) class HunyuanSkyreelsImageToVideoTransformer3DTests(ModelTesterMixin, unittest.TestCase): @@ -157,6 +177,21 @@ def test_gradient_checkpointing_is_applied(self): expected_set = {"HunyuanVideoTransformer3DModel"} super().test_gradient_checkpointing_is_applied(expected_set=expected_set) + @require_torch_gpu + @require_torch_2 + @is_torch_compile + @slow + def test_torch_compile_recompilation_and_graph_break(self): + torch._dynamo.reset() + init_dict, inputs_dict = self.prepare_init_args_and_inputs_for_common() + + model = self.model_class(**init_dict).to(torch_device) + model = torch.compile(model, fullgraph=True) + + with torch._dynamo.config.patch(error_on_recompile=True), torch.no_grad(): + _ = model(**inputs_dict) + _ = model(**inputs_dict) + class HunyuanVideoImageToVideoTransformer3DTests(ModelTesterMixin, unittest.TestCase): model_class = HunyuanVideoTransformer3DModel @@ -222,6 +257,21 @@ def test_output(self): def test_gradient_checkpointing_is_applied(self): expected_set = {"HunyuanVideoTransformer3DModel"} super().test_gradient_checkpointing_is_applied(expected_set=expected_set) + + @require_torch_gpu + @require_torch_2 + @is_torch_compile + @slow + def test_torch_compile_recompilation_and_graph_break(self): + torch._dynamo.reset() + init_dict, inputs_dict = self.prepare_init_args_and_inputs_for_common() + + model = self.model_class(**init_dict).to(torch_device) + model = torch.compile(model, fullgraph=True) + + with torch._dynamo.config.patch(error_on_recompile=True), torch.no_grad(): + _ = model(**inputs_dict) + _ = model(**inputs_dict) class HunyuanVideoTokenReplaceImageToVideoTransformer3DTests(ModelTesterMixin, unittest.TestCase): @@ -286,7 +336,22 @@ def prepare_init_args_and_inputs_for_common(self): def test_output(self): super().test_output(expected_output_shape=(1, *self.output_shape)) - + def test_gradient_checkpointing_is_applied(self): expected_set = {"HunyuanVideoTransformer3DModel"} super().test_gradient_checkpointing_is_applied(expected_set=expected_set) + + @require_torch_gpu + @require_torch_2 + @is_torch_compile + @slow + def test_torch_compile_recompilation_and_graph_break(self): + torch._dynamo.reset() + init_dict, inputs_dict = self.prepare_init_args_and_inputs_for_common() + + model = self.model_class(**init_dict).to(torch_device) + model = torch.compile(model, fullgraph=True) + + with torch._dynamo.config.patch(error_on_recompile=True), torch.no_grad(): + _ = model(**inputs_dict) + _ = model(**inputs_dict) From 1b4ba9af503f7da4eda9313275991197ffb06e2b Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Wed, 30 Apr 2025 18:54:24 +0800 Subject: [PATCH 2/2] update --- .../test_models_transformer_hunyuan_video.py | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/models/transformers/test_models_transformer_hunyuan_video.py b/tests/models/transformers/test_models_transformer_hunyuan_video.py index aa1140f78ea3..0a917352164c 100644 --- a/tests/models/transformers/test_models_transformer_hunyuan_video.py +++ b/tests/models/transformers/test_models_transformer_hunyuan_video.py @@ -17,8 +17,14 @@ import torch from diffusers import HunyuanVideoTransformer3DModel -from diffusers.utils.testing_utils import enable_full_determinism, torch_device -from diffusers.utils.testing_utils import require_torch_gpu, require_torch_2, is_torch_compile, slow +from diffusers.utils.testing_utils import ( + enable_full_determinism, + is_torch_compile, + require_torch_2, + require_torch_gpu, + slow, + torch_device, +) from ..test_modeling_common import ModelTesterMixin @@ -86,10 +92,6 @@ def prepare_init_args_and_inputs_for_common(self): inputs_dict = self.dummy_input return init_dict, inputs_dict - def test_gradient_checkpointing_is_applied(self): - expected_set = {"HunyuanVideoTransformer3DModel"} - super().test_gradient_checkpointing_is_applied(expected_set=expected_set) - def test_gradient_checkpointing_is_applied(self): expected_set = {"HunyuanVideoTransformer3DModel"} super().test_gradient_checkpointing_is_applied(expected_set=expected_set) @@ -97,7 +99,7 @@ def test_gradient_checkpointing_is_applied(self): @require_torch_gpu @require_torch_2 @is_torch_compile - @slow + @slow def test_torch_compile_recompilation_and_graph_break(self): torch._dynamo.reset() init_dict, inputs_dict = self.prepare_init_args_and_inputs_for_common() @@ -191,7 +193,7 @@ def test_torch_compile_recompilation_and_graph_break(self): with torch._dynamo.config.patch(error_on_recompile=True), torch.no_grad(): _ = model(**inputs_dict) _ = model(**inputs_dict) - + class HunyuanVideoImageToVideoTransformer3DTests(ModelTesterMixin, unittest.TestCase): model_class = HunyuanVideoTransformer3DModel @@ -257,7 +259,7 @@ def test_output(self): def test_gradient_checkpointing_is_applied(self): expected_set = {"HunyuanVideoTransformer3DModel"} super().test_gradient_checkpointing_is_applied(expected_set=expected_set) - + @require_torch_gpu @require_torch_2 @is_torch_compile @@ -336,7 +338,7 @@ def prepare_init_args_and_inputs_for_common(self): def test_output(self): super().test_output(expected_output_shape=(1, *self.output_shape)) - + def test_gradient_checkpointing_is_applied(self): expected_set = {"HunyuanVideoTransformer3DModel"} super().test_gradient_checkpointing_is_applied(expected_set=expected_set)