- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6.5k
[qwen] Qwen image edit followups #12166
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 6 commits
      Commits
    
    
            Show all changes
          
          
            9 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      23ae973
              
                add docs.
              
              
                sayakpaul 34dd6cf
              
                more docs.
              
              
                sayakpaul df737cc
              
                xfail full compilation for Qwen for now.
              
              
                sayakpaul 615a420
              
                tests
              
              
                sayakpaul 35744eb
              
                up
              
              
                sayakpaul 75f2598
              
                up
              
              
                sayakpaul 10c7496
              
                up
              
              
                sayakpaul 58d47ca
              
                reviewer feedback.
              
              
                sayakpaul ed6283b
              
                Merge branch 'main' into qwen-image-edit-followups
              
              
                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
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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 | 
|---|---|---|
|  | @@ -46,15 +46,20 @@ | |
| >>> import torch | ||
| >>> from PIL import Image | ||
| >>> from diffusers import QwenImageEditPipeline | ||
| >>> from diffusers.utils import load_image | ||
|  | ||
| >>> pipe = QwenImageEditPipeline.from_pretrained("Qwen/Qwen-Image-Edit", torch_dtype=torch.bfloat16) | ||
| >>> pipe.to("cuda") | ||
| >>> prompt = "Change the cat to a dog" | ||
| >>> image = Image.open("cat.png") | ||
| >>> image = load_image( | ||
| ... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/yarn-art-pikachu.png" | ||
| ... ).convert("RGB") | ||
| >>> prompt = ( | ||
| ... "Make Pikachu hold a sign that says 'Qwen Edit is awesome', yarn art style, detailed, vibrant colors" | ||
| ... ) | ||
| >>> # Depending on the variant being used, the pipeline call will slightly vary. | ||
| >>> # Refer to the pipeline documentation for more details. | ||
| >>> image = pipe(image, prompt, num_inference_steps=50).images[0] | ||
| >>> image.save("qwenimageedit.png") | ||
| >>> image.save("qwenimage_edit.png") | ||
| ``` | ||
| """ | ||
| PREFERRED_QWENIMAGE_RESOLUTIONS = [ | ||
|  | @@ -178,7 +183,7 @@ def calculate_dimensions(target_area, ratio): | |
|  | ||
| class QwenImageEditPipeline(DiffusionPipeline, QwenImageLoraLoaderMixin): | ||
| r""" | ||
| The QwenImage pipeline for text-to-image generation. | ||
| The Qwen-Image-Edit pipeline for image editing. | ||
|  | ||
| Args: | ||
| transformer ([`QwenImageTransformer2DModel`]): | ||
|  | @@ -217,8 +222,8 @@ def __init__( | |
| transformer=transformer, | ||
| scheduler=scheduler, | ||
| ) | ||
| self.latent_channels = 16 | ||
| self.vae_scale_factor = 2 ** len(self.vae.temperal_downsample) if getattr(self, "vae", None) else 8 | ||
| self.latent_channels = self.vae.config.z_dim if getattr(self, "vae", None) else 16 | ||
| # QwenImage latents are turned into 2x2 patches and packed. This means the latent width and height has to be divisible | ||
| # by the patch size. So the vae scale factor is multiplied by the patch size to account for this | ||
| self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor * 2) | ||
|  | @@ -635,7 +640,9 @@ def __call__( | |
| [`~pipelines.qwenimage.QwenImagePipelineOutput`] if `return_dict` is True, otherwise a `tuple`. When | ||
| returning a tuple, the first element is a list with the generated images. | ||
| """ | ||
| calculated_width, calculated_height, _ = calculate_dimensions(1024 * 1024, image.width / image.height) | ||
| image_size = image[0].size if isinstance(image, list) else image.size | ||
| width, height = image_size | ||
| calculated_width, calculated_height, _ = calculate_dimensions(1024 * 1024, width / height) | ||
| 
      Comment on lines
    
      -638
     to 
      +645
    
   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. Otherwise,  | ||
| height = height or calculated_height | ||
| width = width or calculated_width | ||
|  | ||
|  | ||
  
    
      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 | 
|---|---|---|
|  | @@ -15,6 +15,7 @@ | |
|  | ||
| import unittest | ||
|  | ||
| import pytest | ||
| import torch | ||
|  | ||
| from diffusers import QwenImageTransformer2DModel | ||
|  | @@ -99,3 +100,7 @@ def prepare_init_args_and_inputs_for_common(self): | |
|  | ||
| def prepare_dummy_input(self, height, width): | ||
| return QwenImageTransformerTests().prepare_dummy_input(height=height, width=width) | ||
|  | ||
| @pytest.mark.xfail(condition=True, reason="RoPE needs to be revisited.", strict=True) | ||
| 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. Makes sense since RoPE refactor changes have been reverted | ||
| def test_torch_compile_recompilation_and_graph_break(self): | ||
| super().test_torch_compile_recompilation_and_graph_break() | ||
      
      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.
Without this, the
test_to_devicetest fails:diffusers/tests/pipelines/test_pipelines_common.py
Line 1503 in e682af2