- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6.5k
[tests] Enable testing for HiDream transformer #11478
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
          
     Merged
      
      
    
  
     Merged
                    Changes from 5 commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      4caa6e8
              
                add tests for hidream transformer model.
              
              
                sayakpaul 1d1e715
              
                fix
              
              
                sayakpaul 63b6169
              
                Merge branch 'main' into wan-transformer-tests
              
              
                sayakpaul 676ab71
              
                Merge branch 'main' into wan-transformer-tests
              
              
                sayakpaul b7c8d84
              
                Merge branch 'main' into wan-transformer-tests
              
              
                sayakpaul 97de1c3
              
                Update tests/models/transformers/test_models_transformer_hidream.py
              
              
                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
        
          
          
            96 changes: 96 additions & 0 deletions
          
          96 
        
  tests/models/transformers/test_models_transformer_hidream.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,96 @@ | ||
| # coding=utf-8 | ||
| # Copyright 2024 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 unittest | ||
|  | ||
| import torch | ||
|  | ||
| from diffusers import HiDreamImageTransformer2DModel | ||
| from diffusers.utils.testing_utils import ( | ||
| enable_full_determinism, | ||
| torch_device, | ||
| ) | ||
|  | ||
| from ..test_modeling_common import ModelTesterMixin | ||
|  | ||
|  | ||
| enable_full_determinism() | ||
|  | ||
|  | ||
| class HiDreamTransformerTests(ModelTesterMixin, unittest.TestCase): | ||
| model_class = HiDreamImageTransformer2DModel | ||
| main_input_name = "hidden_states" | ||
| model_split_percents = [0.8, 0.8, 0.9] | ||
|  | ||
| @property | ||
| def dummy_input(self): | ||
| batch_size = 2 | ||
| num_channels = 4 | ||
| height = width = 32 | ||
| embedding_dim_t5, embedding_dim_llama, embedding_dim_pooled = 8, 4, 8 | ||
| sequence_length = 8 | ||
|  | ||
| hidden_states = torch.randn((batch_size, num_channels, height, width)).to(torch_device) | ||
| encoder_hidden_states_t5 = torch.randn((batch_size, sequence_length, embedding_dim_t5)).to(torch_device) | ||
| encoder_hidden_states_llama3 = torch.randn((batch_size, batch_size, sequence_length, embedding_dim_llama)).to( | ||
| torch_device | ||
| ) | ||
| pooled_embeds = torch.randn((batch_size, embedding_dim_pooled)).to(torch_device) | ||
| timesteps = torch.randint(0, 1000, size=(batch_size,)).to(torch_device) | ||
|  | ||
| return { | ||
| "hidden_states": hidden_states, | ||
| "encoder_hidden_states_t5": encoder_hidden_states_t5, | ||
| "encoder_hidden_states_llama3": encoder_hidden_states_llama3, | ||
| "pooled_embeds": pooled_embeds, | ||
| "timesteps": timesteps, | ||
| } | ||
|  | ||
| @property | ||
| def input_shape(self): | ||
| return (4, 32, 32) | ||
|  | ||
| @property | ||
| def output_shape(self): | ||
| return (4, 32, 32) | ||
|  | ||
| def prepare_init_args_and_inputs_for_common(self): | ||
| init_dict = { | ||
| "patch_size": 2, | ||
| "in_channels": 4, | ||
| "out_channels": 4, | ||
| "num_layers": 1, | ||
| "num_single_layers": 1, | ||
| "attention_head_dim": 8, | ||
| "num_attention_heads": 4, | ||
| "caption_channels": [8, 4], | ||
| "text_emb_dim": 8, | ||
| "num_routed_experts": 2, | ||
| "num_activated_experts": 2, | ||
| "axes_dims_rope": (4, 2, 2), | ||
| "max_resolution": (32, 32), | ||
| "llama_layers": (0, 1), | ||
| "force_inference_output": True, # TODO: as we don't implement MoE loss in training tests. | ||
| } | ||
| inputs_dict = self.dummy_input | ||
| return init_dict, inputs_dict | ||
|  | ||
| @unittest.skip("HiDreamImageTransformer2DModel uses a dedicated attention processor. This test doesn't apply") | ||
| def test_set_attn_processor_for_determinism(self): | ||
| pass | ||
|  | ||
| def test_gradient_checkpointing_is_applied(self): | ||
| expected_set = {"HiDreamImageTransformer2DModel"} | ||
| super().test_gradient_checkpointing_is_applied(expected_set=expected_set) | ||
  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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.