|
| 1 | +# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import unittest |
| 16 | +import paddle |
| 17 | +from ppdiffusers import SD3Transformer2DModel |
| 18 | +from ppdiffusers.utils.testing_utils import ( |
| 19 | + enable_full_determinism, |
| 20 | + paddle_device, |
| 21 | +) |
| 22 | +from .test_modeling_common import ModelTesterMixin |
| 23 | + |
| 24 | +enable_full_determinism() |
| 25 | + |
| 26 | +class SD3TransformerTests(ModelTesterMixin, unittest.TestCase): |
| 27 | + model_class = SD3Transformer2DModel |
| 28 | + main_input_name = "hidden_states" |
| 29 | + @property |
| 30 | + def dummy_input(self): |
| 31 | + batch_size = 2 |
| 32 | + num_channels = 4 |
| 33 | + height = width = embedding_dim = 32 |
| 34 | + pooled_embedding_dim = embedding_dim * 2 |
| 35 | + sequence_length = 154 |
| 36 | + hidden_states = paddle.randn((batch_size, num_channels, height, width)) |
| 37 | + encoder_hidden_states = paddle.randn((batch_size, sequence_length, embedding_dim)) |
| 38 | + pooled_prompt_embeds = paddle.randn((batch_size, pooled_embedding_dim)) |
| 39 | + timestep = paddle.randint(0, 1000, shape=(batch_size,)) |
| 40 | + return { |
| 41 | + "hidden_states": hidden_states, |
| 42 | + "encoder_hidden_states": encoder_hidden_states, |
| 43 | + "pooled_projections": pooled_prompt_embeds, |
| 44 | + "timestep": timestep, |
| 45 | + } |
| 46 | + @property |
| 47 | + def input_shape(self): |
| 48 | + return (4, 32, 32) |
| 49 | + @property |
| 50 | + def output_shape(self): |
| 51 | + return (4, 32, 32) |
| 52 | + def prepare_init_args_and_inputs_for_common(self): |
| 53 | + init_dict = { |
| 54 | + "sample_size": 32, |
| 55 | + "patch_size": 1, |
| 56 | + "in_channels": 4, |
| 57 | + "num_layers": 1, |
| 58 | + "attention_head_dim": 8, |
| 59 | + "num_attention_heads": 4, |
| 60 | + "caption_projection_dim": 32, |
| 61 | + "joint_attention_dim": 32, |
| 62 | + "pooled_projection_dim": 64, |
| 63 | + "out_channels": 4, |
| 64 | + } |
| 65 | + inputs_dict = self.dummy_input |
| 66 | + return init_dict, inputs_dict |
| 67 | + |
| 68 | + @unittest.skip("SD3Transformer2DModel uses a dedicated attention processor. This test doesn't apply") |
| 69 | + def test_from_save_pretrained(self): |
| 70 | + pass |
| 71 | + |
| 72 | + @unittest.skip("SD3Transformer2DModel uses a dedicated attention processor. This test doesn't apply") |
| 73 | + def test_outputs_equivalence(self): |
| 74 | + pass |
| 75 | + |
| 76 | + @unittest.skip("SD3Transformer2DModel uses a dedicated attention processor. This test doesn't apply") |
| 77 | + def test_set_attn_processor_for_determinism(self): |
| 78 | + pass |
| 79 | + |
0 commit comments