o
    ۷i                     @   s  d dl Z d dlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
 ddlmZ dd	lmZmZmZmZ dd
lmZmZmZ ddlmZ eeZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZ G dd deZ!G dd de!Z"G dd  d e!Z#G d!d" d"e!Z$G d#d$ d$e!Z%G d%d& d&e!Z&G d'd( d(e!Z'G d)d* d*e!Z(dS )+    N   )
FrozenDict)ClassifierFreeGuidance)QwenImageControlNetModelQwenImageTransformer2DModel)FlowMatchEulerDiscreteScheduler)logging   )
BlockStateLoopSequentialPipelineBlocksModularPipelineBlocksPipelineState)ComponentSpec
InputParamOutputParam   )QwenImageModularPipelinec                	   @   \   e Zd ZdZedefddZedee fddZ	e
 deded	ed
e
jfddZdS )QwenImageLoopBeforeDenoiser	qwenimagereturnc                 C      	 dS Nzstep within the denoising loop that prepares the latent input for the denoiser. This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `QwenImageDenoiseLoopWrapper`) selfr   r   c/home/ubuntu/vllm_env/lib/python3.10/site-packages/diffusers/modular_pipelines/qwenimage/denoise.pydescription(      z'QwenImageLoopBeforeDenoiser.descriptionc                 C   s   t ddtjddgS )NlatentsT^The initial latents to use for the denoising process. Can be generated in prepare_latent step.namerequired	type_hintr   )r   torchTensorr   r   r   r   inputs0   s   z"QwenImageLoopBeforeDenoiser.inputs
componentsblock_stateitc                 C   s.   | |jjd |jj|_|j|_||fS )Nr   )expandr   shapetodtypetimesteplatent_model_inputr   r(   r)   r*   r+   r   r   r   __call__;   s   z$QwenImageLoopBeforeDenoiser.__call__N__name__
__module____qualname__
model_namepropertystrr   listr   r'   r%   no_gradr   r
   intr&   r3   r   r   r   r   r   %   s    
"r   c                	   @   r   )QwenImageEditLoopBeforeDenoiserqwenimage-editr   c                 C   r   r   r   r   r   r   r   r   F   r   z+QwenImageEditLoopBeforeDenoiser.descriptionc                 C   s   t ddtjddt dgS )Nr   Tr    r!   image_latentsr   r%   r&   templater   r   r   r   r'   N   s   z&QwenImageEditLoopBeforeDenoiser.inputsr(   r)   r*   r+   c                 C   s>   t j|j|jgdd|_||jjd |jj|_	||fS )Nr   )dimr   )
r%   catr   r@   r1   r,   r-   r.   r/   r0   r2   r   r   r   r3   Z   s   z(QwenImageEditLoopBeforeDenoiser.__call__Nr4   r   r   r   r   r>   C   s    "r>   c                	   @   sp   e Zd ZdZedee fddZedefddZ	edee
 fddZe d	ed
ededefddZdS )%QwenImageLoopBeforeDenoiserControlNetr   r   c                 C   "   t dttddiddt dtgS )Nguiderguidance_scale      @from_configconfigdefault_creation_method
controlnet)r   r   r   r   r   r   r   r   expected_componentsf      
z9QwenImageLoopBeforeDenoiserControlNet.expected_componentsc                 C   r   )Nzstep within the denoising loop that runs the controlnet before the denoiser. This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `QwenImageDenoiseLoopWrapper`)r   r   r   r   r   r   r   r   z1QwenImageLoopBeforeDenoiserControlNet.descriptionc                 C   s2   t ddtjddt jdddt ddtt d	d
gS )Ncontrol_image_latentsTzgThe control image to use for the denoising process. Can be generated in prepare_controlnet_inputs step.r#   r$   r   controlnet_conditioning_scalez*updated in prepare_controlnet_inputs step.)notecontrolnet_keepzOThe controlnet keep values. Can be generated in prepare_controlnet_inputs step.r!   )r   r%   r&   rB   r;   floatr   r   r   r   r'   z   s   z,QwenImageLoopBeforeDenoiserControlNet.inputsr(   r)   r*   r+   c              
   C   s   t |j| trdd t|j|j| D |_n|j}t |tr$|d }||j|  |_|j|j|j|j|j	d |j
|j|jdd}||jd< ||fS )Nc                 S   s   g | ]\}}|| qS r   r   ).0csr   r   r   
<listcomp>   s    zBQwenImageLoopBeforeDenoiserControlNet.__call__.<locals>.<listcomp>r     F)hidden_statescontrolnet_condconditioning_scaler0   
img_shapesencoder_hidden_statesencoder_hidden_states_maskreturn_dictcontrolnet_block_samples)
isinstancerU   r;   ziprS   
cond_scalerN   r1   rQ   r0   r_   prompt_embedsprompt_embeds_maskadditional_cond_kwargs)r   r(   r)   r*   r+   controlnet_cond_scalerc   r   r   r   r3      s(   


z.QwenImageLoopBeforeDenoiserControlNet.__call__N)r5   r6   r7   r8   r9   r;   r   rO   r:   r   r   r'   r%   r<   r   r
   r=   r3   r   r   r   r   rE   c   s     rE   c                	   @   r   e Zd ZdZedefddZedee fddZ	edee
 fddZe d	ed
ededejfddZdS )QwenImageLoopDenoiserr   r   c                 C   r   Nzstep within the denoising loop that denoise the latent input for the denoiser. This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `QwenImageDenoiseLoopWrapper`)r   r   r   r   r   r      r   z!QwenImageLoopDenoiser.descriptionc                 C   rF   NrG   rH   rI   rJ   rK   transformerr   r   r   r   r   r   r   r   rO      rP   z)QwenImageLoopDenoiser.expected_componentsc              	   C   .   t dt dt ddttttf  ddgS )Nattention_kwargsdenoiser_input_fieldsr_   TzhThe shape of the image latents for RoPE calculation. can be generated in prepare_additional_inputs step.rR   r   rB   r;   tupler=   r   r   r   r   r'         zQwenImageLoopDenoiser.inputsr(   r)   r*   r+   c                    sX  t |dd t |dd ft |dd t |dd fd}tt|jjj }i }|j	 D ]\}}	||v r<||vr<|	||< q,|j
| |jj||j|d |j|}
|
D ]3 |j|j  fdd| D }|jd|j|jd	 |jd
d||j
d  _|j|j qU||
}tj|jddd}tj|jddd}|j||  |_||fS )Nrg   negative_prompt_embedsrh   negative_prompt_embeds_maskr`   ra   stepnum_inference_stepsr0   c                       i | ]}|t  |qS r   getattrrW   
input_nameguider_state_batchr   r   
<dictcomp>       z2QwenImageLoopDenoiser.__call__.<locals>.<dictcomp>r[   Fr\   r0   rr   rb   r   TrC   keepdimr   )r   setinspect	signaturero   forward
parameterskeysrs   itemsri   updaterG   	set_stater|   prepare_inputsprepare_modelsr1   r0   rr   
noise_predcleanup_modelsr%   norm	pred_condpred)r   r(   r)   r*   r+   guider_inputstransformer_argsri   
field_namefield_valueguider_statecond_kwargsguider_outputpred_cond_norm	pred_normr   r   r   r3      sJ   



	
zQwenImageLoopDenoiser.__call__Nr5   r6   r7   r8   r9   r:   r   r;   r   rO   r   r'   r%   r<   r   r
   r=   r&   r3   r   r   r   r   rl          "rl   c                	   @   rk   )QwenImageEditLoopDenoiserr?   r   c                 C   r   rm   r   r   r   r   r   r     r   z%QwenImageEditLoopDenoiser.descriptionc                 C   rF   rn   rp   r   r   r   r   rO     rP   z-QwenImageEditLoopDenoiser.expected_componentsc              	   C   rq   )Nrr   rs   r_   TzhThe shape of the image latents for RoPE calculation. Can be generated in prepare_additional_inputs step.rR   rt   r   r   r   r   r'     rv   z QwenImageEditLoopDenoiser.inputsr(   r)   r*   r+   c                    s  t |dd t |dd ft |dd t |dd fd}tt|jjj }i }|j	 D ]\}}	||v r<||vr<|	||< q,|j
| |jj||j|d |j|}
|
D ]3 |j|j  fdd| D }|jd|j|jd	 |jd
d||j
d  _|j|j qU||
}|jd d d |jdf }|jd d d |jdf }tj|ddd}tj|ddd}|||  |_||fS )Nrg   rw   rh   rx   ry   rz   c                    r}   r   r~   r   r   r   r   r   =  r   z6QwenImageEditLoopDenoiser.__call__.<locals>.<dictcomp>r[   Fr   r   r   r   Tr   r   )r   r   r   r   ro   r   r   r   rs   r   ri   r   rG   r   r|   r   r   r1   r0   rr   r   r   r   r   sizer   r%   r   )r   r(   r)   r*   r+   r   r   ri   r   r   r   r   r   r   r   r   r   r   r   r   r3   $  sN   



	
z"QwenImageEditLoopDenoiser.__call__Nr   r   r   r   r   r      r   r   c                	   @   rk   )QwenImageLoopAfterDenoiserr   r   c                 C   r   )Nzstep within the denoising loop that updates the latents. This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `QwenImageDenoiseLoopWrapper`)r   r   r   r   r   r   \  r   z&QwenImageLoopAfterDenoiser.descriptionc                 C      t dtgS N	schedulerr   r   r   r   r   r   rO   d     z.QwenImageLoopAfterDenoiser.expected_componentsc                 C      t dgS Nr   r   rB   r   r   r   r   intermediate_outputsj  r   z/QwenImageLoopAfterDenoiser.intermediate_outputsr(   r)   r*   r+   c                 C   sT   |j j}|jj|j||j ddd |_ |j j|kr&tjj r&|j 	||_ ||fS )NF)rb   r   )
r   r/   r   r{   r   r%   backendsmpsis_availabler.   )r   r(   r)   r*   r+   latents_dtyper   r   r   r3   p  s   z#QwenImageLoopAfterDenoiser.__call__N)r5   r6   r7   r8   r9   r:   r   r;   r   rO   r   r   r%   r<   r   r
   r=   r&   r3   r   r   r   r   r   Y  s    "r   c                	   @   rk   )!QwenImageLoopAfterDenoiserInpaintr   r   c                 C   r   )Nzstep within the denoising loop that updates the latents using mask and image_latents for inpainting. This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `QwenImageDenoiseLoopWrapper`)r   r   r   r   r   r     r   z-QwenImageLoopAfterDenoiserInpaint.descriptionc                 C   s,   t ddtjddt dt ddtjddgS )NmaskTz]The mask to use for the inpainting process. Can be generated in inpaint prepare latents step.rR   r@   initial_noisezfThe initial noise to use for the inpainting process. Can be generated in inpaint prepare latents step.rA   r   r   r   r   r'     s   z(QwenImageLoopAfterDenoiserInpaint.inputsc                 C   r   r   r   r   r   r   r   r     r   z6QwenImageLoopAfterDenoiserInpaint.intermediate_outputsr(   r)   r*   r+   c                 C   sp   |j |_|t|jd k r%|j|d  |_|j|jt|jg|j	|_d|j
 |j |j
|j  |_||fS )Nr   )r@   init_latents_properlen	timestepsnoise_timestepr   scale_noiser%   tensorr   r   r   r2   r   r   r   r3     s   
z*QwenImageLoopAfterDenoiserInpaint.__call__N)r5   r6   r7   r8   r9   r:   r   r;   r   r'   r   r   r%   r<   r   r
   r=   r&   r3   r   r   r   r   r     s    "r   c                   @   sl   e Zd ZdZedefddZedee fddZ	edee
 fddZe d	ed
edefddZdS )QwenImageDenoiseLoopWrapperr   r   c                 C   r   )NzPipeline block that iteratively denoise the latents over `timesteps`. The specific steps with each iteration can be customized with `sub_blocks` attributesr   r   r   r   r   r     r   z'QwenImageDenoiseLoopWrapper.descriptionc                 C   r   r   r   r   r   r   r   loop_expected_components  r   z4QwenImageDenoiseLoopWrapper.loop_expected_componentsc                 C   s    t ddtjddt jdddgS )Nr   TzWThe timesteps to use for the denoising process. Can be generated in set_timesteps step.r!   r|   )r#   rA   r   r   r   r   loop_inputs  s   z'QwenImageDenoiseLoopWrapper.loop_inputsr(   statec                 C   s   |  |}tt|j|j|jj  d|_i |_| j	|jd;}t
|jD ]-\}}| j||||d\}}|t|jd ksN|d |jkrR|d |jj dkrR|  q%W d    n1 s]w   Y  | || ||fS )Nr   )total)r*   r+   r   )get_block_statemaxr   r   r|   r   ordernum_warmup_stepsri   progress_bar	enumerate	loop_stepr   set_block_state)r   r(   r   r)   r   r*   r+   r   r   r   r3     s    
"z$QwenImageDenoiseLoopWrapper.__call__N)r5   r6   r7   r8   r9   r:   r   r;   r   r   r   r   r%   r<   r   r   r3   r   r   r   r   r     s    r   c                   @   8   e Zd ZdZdZeeegZg dZ	e
defddZdS )QwenImageDenoiseStepa  
    Denoise step that iteratively denoise the latents.
      Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method At each iteration, it runs blocks
      defined in `sub_blocks` sequencially:
       - `QwenImageLoopBeforeDenoiser`
       - `QwenImageLoopDenoiser`
       - `QwenImageLoopAfterDenoiser`
      This block supports text2image and image2image tasks for QwenImage.

      Components:
          guider (`ClassifierFreeGuidance`) transformer (`QwenImageTransformer2DModel`) scheduler
          (`FlowMatchEulerDiscreteScheduler`)

      Inputs:
          timesteps (`Tensor`):
              The timesteps to use for the denoising process. Can be generated in set_timesteps step.
          num_inference_steps (`int`):
              The number of denoising steps.
          latents (`Tensor`):
              The initial latents to use for the denoising process. Can be generated in prepare_latent step.
          attention_kwargs (`dict`, *optional*):
              Additional kwargs for attention processors.
          **denoiser_input_fields (`None`, *optional*):
              conditional model inputs for the denoiser: e.g. prompt_embeds, negative_prompt_embeds, etc.
          img_shapes (`list`):
              The shape of the image latents for RoPE calculation. can be generated in prepare_additional_inputs step.

      Outputs:
          latents (`Tensor`):
              Denoised latents.
    r   before_denoiserdenoiserafter_denoiserr   c                 C   r   )Nae  Denoise step that iteratively denoise the latents.
Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method
At each iteration, it runs blocks defined in `sub_blocks` sequencially:
 - `QwenImageLoopBeforeDenoiser`
 - `QwenImageLoopDenoiser`
 - `QwenImageLoopAfterDenoiser`
This block supports text2image and image2image tasks for QwenImage.r   r   r   r   r   r     r   z QwenImageDenoiseStep.descriptionN)r5   r6   r7   __doc__r8   r   rl   r   block_classesblock_namesr9   r:   r   r   r   r   r   r     s     r   c                   @   :   e Zd ZdZdZeeeegZ	g dZ
edefddZdS )QwenImageInpaintDenoiseStepad  
    Denoise step that iteratively denoise the latents.
      Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method At each iteration, it runs blocks
      defined in `sub_blocks` sequencially:
       - `QwenImageLoopBeforeDenoiser`
       - `QwenImageLoopDenoiser`
       - `QwenImageLoopAfterDenoiser`
       - `QwenImageLoopAfterDenoiserInpaint`
      This block supports inpainting tasks for QwenImage.

      Components:
          guider (`ClassifierFreeGuidance`) transformer (`QwenImageTransformer2DModel`) scheduler
          (`FlowMatchEulerDiscreteScheduler`)

      Inputs:
          timesteps (`Tensor`):
              The timesteps to use for the denoising process. Can be generated in set_timesteps step.
          num_inference_steps (`int`):
              The number of denoising steps.
          latents (`Tensor`):
              The initial latents to use for the denoising process. Can be generated in prepare_latent step.
          attention_kwargs (`dict`, *optional*):
              Additional kwargs for attention processors.
          **denoiser_input_fields (`None`, *optional*):
              conditional model inputs for the denoiser: e.g. prompt_embeds, negative_prompt_embeds, etc.
          img_shapes (`list`):
              The shape of the image latents for RoPE calculation. can be generated in prepare_additional_inputs step.
          mask (`Tensor`):
              The mask to use for the inpainting process. Can be generated in inpaint prepare latents step.
          image_latents (`Tensor`):
              image latents used to guide the image generation. Can be generated from vae_encoder step.
          initial_noise (`Tensor`):
              The initial noise to use for the inpainting process. Can be generated in inpaint prepare latents step.

      Outputs:
          latents (`Tensor`):
              Denoised latents.
    r   r   r   r   after_denoiser_inpaintr   c                 C   r   )Na~  Denoise step that iteratively denoise the latents. 
Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method 
At each iteration, it runs blocks defined in `sub_blocks` sequencially:
 - `QwenImageLoopBeforeDenoiser`
 - `QwenImageLoopDenoiser`
 - `QwenImageLoopAfterDenoiser`
 - `QwenImageLoopAfterDenoiserInpaint`
This block supports inpainting tasks for QwenImage.r   r   r   r   r   r   ^  r   z'QwenImageInpaintDenoiseStep.descriptionN)r5   r6   r7   r   r8   r   rl   r   r   r   r   r9   r:   r   r   r   r   r   r   -      'r   c                   @   r   )QwenImageControlNetDenoiseStepa  
    Denoise step that iteratively denoise the latents.
      Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method At each iteration, it runs blocks
      defined in `sub_blocks` sequencially:
       - `QwenImageLoopBeforeDenoiser`
       - `QwenImageLoopBeforeDenoiserControlNet`
       - `QwenImageLoopDenoiser`
       - `QwenImageLoopAfterDenoiser`
      This block supports text2img/img2img tasks with controlnet for QwenImage.

      Components:
          guider (`ClassifierFreeGuidance`) controlnet (`QwenImageControlNetModel`) transformer
          (`QwenImageTransformer2DModel`) scheduler (`FlowMatchEulerDiscreteScheduler`)

      Inputs:
          timesteps (`Tensor`):
              The timesteps to use for the denoising process. Can be generated in set_timesteps step.
          num_inference_steps (`int`):
              The number of denoising steps.
          latents (`Tensor`):
              The initial latents to use for the denoising process. Can be generated in prepare_latent step.
          control_image_latents (`Tensor`):
              The control image to use for the denoising process. Can be generated in prepare_controlnet_inputs step.
          controlnet_conditioning_scale (`float`, *optional*, defaults to 1.0):
              Scale for ControlNet conditioning. (updated in prepare_controlnet_inputs step.)
          controlnet_keep (`list`):
              The controlnet keep values. Can be generated in prepare_controlnet_inputs step.
          attention_kwargs (`dict`, *optional*):
              Additional kwargs for attention processors.
          **denoiser_input_fields (`None`, *optional*):
              conditional model inputs for the denoiser: e.g. prompt_embeds, negative_prompt_embeds, etc.
          img_shapes (`list`):
              The shape of the image latents for RoPE calculation. can be generated in prepare_additional_inputs step.

      Outputs:
          latents (`Tensor`):
              Denoised latents.
    r   )r   before_denoiser_controlnetr   r   r   c                 C   r   )Na  Denoise step that iteratively denoise the latents. 
Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method 
At each iteration, it runs blocks defined in `sub_blocks` sequencially:
 - `QwenImageLoopBeforeDenoiser`
 - `QwenImageLoopBeforeDenoiserControlNet`
 - `QwenImageLoopDenoiser`
 - `QwenImageLoopAfterDenoiser`
This block supports text2img/img2img tasks with controlnet for QwenImage.r   r   r   r   r   r     r   z*QwenImageControlNetDenoiseStep.descriptionN)r5   r6   r7   r   r8   r   rE   rl   r   r   r   r9   r:   r   r   r   r   r   r   n  r   r   c                   @   s<   e Zd ZdZdZeeeee	gZ
g dZedefddZdS )%QwenImageInpaintControlNetDenoiseStepa	  
    Denoise step that iteratively denoise the latents.
      Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method At each iteration, it runs blocks
      defined in `sub_blocks` sequencially:
       - `QwenImageLoopBeforeDenoiser`
       - `QwenImageLoopBeforeDenoiserControlNet`
       - `QwenImageLoopDenoiser`
       - `QwenImageLoopAfterDenoiser`
       - `QwenImageLoopAfterDenoiserInpaint`
      This block supports inpainting tasks with controlnet for QwenImage.

      Components:
          guider (`ClassifierFreeGuidance`) controlnet (`QwenImageControlNetModel`) transformer
          (`QwenImageTransformer2DModel`) scheduler (`FlowMatchEulerDiscreteScheduler`)

      Inputs:
          timesteps (`Tensor`):
              The timesteps to use for the denoising process. Can be generated in set_timesteps step.
          num_inference_steps (`int`):
              The number of denoising steps.
          latents (`Tensor`):
              The initial latents to use for the denoising process. Can be generated in prepare_latent step.
          control_image_latents (`Tensor`):
              The control image to use for the denoising process. Can be generated in prepare_controlnet_inputs step.
          controlnet_conditioning_scale (`float`, *optional*, defaults to 1.0):
              Scale for ControlNet conditioning. (updated in prepare_controlnet_inputs step.)
          controlnet_keep (`list`):
              The controlnet keep values. Can be generated in prepare_controlnet_inputs step.
          attention_kwargs (`dict`, *optional*):
              Additional kwargs for attention processors.
          **denoiser_input_fields (`None`, *optional*):
              conditional model inputs for the denoiser: e.g. prompt_embeds, negative_prompt_embeds, etc.
          img_shapes (`list`):
              The shape of the image latents for RoPE calculation. can be generated in prepare_additional_inputs step.
          mask (`Tensor`):
              The mask to use for the inpainting process. Can be generated in inpaint prepare latents step.
          image_latents (`Tensor`):
              image latents used to guide the image generation. Can be generated from vae_encoder step.
          initial_noise (`Tensor`):
              The initial noise to use for the inpainting process. Can be generated in inpaint prepare latents step.

      Outputs:
          latents (`Tensor`):
              Denoised latents.
    r   )r   r   r   r   r   r   c                 C   r   )Na  Denoise step that iteratively denoise the latents. 
Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method 
At each iteration, it runs blocks defined in `sub_blocks` sequencially:
 - `QwenImageLoopBeforeDenoiser`
 - `QwenImageLoopBeforeDenoiserControlNet`
 - `QwenImageLoopDenoiser`
 - `QwenImageLoopAfterDenoiser`
 - `QwenImageLoopAfterDenoiserInpaint`
This block supports inpainting tasks with controlnet for QwenImage.r   r   r   r   r   r     r   z1QwenImageInpaintControlNetDenoiseStep.descriptionN)r5   r6   r7   r   r8   r   rE   rl   r   r   r   r   r9   r:   r   r   r   r   r   r     s    .r   c                   @   r   )QwenImageEditDenoiseStepa  
    Denoise step that iteratively denoise the latents.
      Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method At each iteration, it runs blocks
      defined in `sub_blocks` sequencially:
       - `QwenImageEditLoopBeforeDenoiser`
       - `QwenImageEditLoopDenoiser`
       - `QwenImageLoopAfterDenoiser`
      This block supports QwenImage Edit.

      Components:
          guider (`ClassifierFreeGuidance`) transformer (`QwenImageTransformer2DModel`) scheduler
          (`FlowMatchEulerDiscreteScheduler`)

      Inputs:
          timesteps (`Tensor`):
              The timesteps to use for the denoising process. Can be generated in set_timesteps step.
          num_inference_steps (`int`):
              The number of denoising steps.
          latents (`Tensor`):
              The initial latents to use for the denoising process. Can be generated in prepare_latent step.
          image_latents (`Tensor`):
              image latents used to guide the image generation. Can be generated from vae_encoder step.
          attention_kwargs (`dict`, *optional*):
              Additional kwargs for attention processors.
          **denoiser_input_fields (`None`, *optional*):
              conditional model inputs for the denoiser: e.g. prompt_embeds, negative_prompt_embeds, etc.
          img_shapes (`list`):
              The shape of the image latents for RoPE calculation. Can be generated in prepare_additional_inputs step.

      Outputs:
          latents (`Tensor`):
              Denoised latents.
    r?   r   r   c                 C   r   )NaO  Denoise step that iteratively denoise the latents. 
Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method 
At each iteration, it runs blocks defined in `sub_blocks` sequencially:
 - `QwenImageEditLoopBeforeDenoiser`
 - `QwenImageEditLoopDenoiser`
 - `QwenImageLoopAfterDenoiser`
This block supports QwenImage Edit.r   r   r   r   r   r   *  r   z$QwenImageEditDenoiseStep.descriptionNr5   r6   r7   r   r8   r>   r   r   r   r   r9   r:   r   r   r   r   r   r         "r   c                   @   r   )QwenImageEditInpaintDenoiseStepaq  
    Denoise step that iteratively denoise the latents.
      Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method At each iteration, it runs blocks
      defined in `sub_blocks` sequencially:
       - `QwenImageEditLoopBeforeDenoiser`
       - `QwenImageEditLoopDenoiser`
       - `QwenImageLoopAfterDenoiser`
       - `QwenImageLoopAfterDenoiserInpaint`
      This block supports inpainting tasks for QwenImage Edit.

      Components:
          guider (`ClassifierFreeGuidance`) transformer (`QwenImageTransformer2DModel`) scheduler
          (`FlowMatchEulerDiscreteScheduler`)

      Inputs:
          timesteps (`Tensor`):
              The timesteps to use for the denoising process. Can be generated in set_timesteps step.
          num_inference_steps (`int`):
              The number of denoising steps.
          latents (`Tensor`):
              The initial latents to use for the denoising process. Can be generated in prepare_latent step.
          image_latents (`Tensor`):
              image latents used to guide the image generation. Can be generated from vae_encoder step.
          attention_kwargs (`dict`, *optional*):
              Additional kwargs for attention processors.
          **denoiser_input_fields (`None`, *optional*):
              conditional model inputs for the denoiser: e.g. prompt_embeds, negative_prompt_embeds, etc.
          img_shapes (`list`):
              The shape of the image latents for RoPE calculation. Can be generated in prepare_additional_inputs step.
          mask (`Tensor`):
              The mask to use for the inpainting process. Can be generated in inpaint prepare latents step.
          initial_noise (`Tensor`):
              The initial noise to use for the inpainting process. Can be generated in inpaint prepare latents step.

      Outputs:
          latents (`Tensor`):
              Denoised latents.
    r?   r   r   c                 C   r   )Na  Denoise step that iteratively denoise the latents. 
Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method 
At each iteration, it runs blocks defined in `sub_blocks` sequencially:
 - `QwenImageEditLoopBeforeDenoiser`
 - `QwenImageEditLoopDenoiser`
 - `QwenImageLoopAfterDenoiser`
 - `QwenImageLoopAfterDenoiserInpaint`
This block supports inpainting tasks for QwenImage Edit.r   r   r   r   r   r   j  r   z+QwenImageEditInpaintDenoiseStep.descriptionN)r5   r6   r7   r   r8   r>   r   r   r   r   r   r9   r:   r   r   r   r   r   r   9  r   r   c                   @   r   )QwenImageLayeredDenoiseStepa  
    Denoise step that iteratively denoise the latents.
      Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method At each iteration, it runs blocks
      defined in `sub_blocks` sequencially:
       - `QwenImageEditLoopBeforeDenoiser`
       - `QwenImageEditLoopDenoiser`
       - `QwenImageLoopAfterDenoiser`
      This block supports QwenImage Layered.

      Components:
          guider (`ClassifierFreeGuidance`) transformer (`QwenImageTransformer2DModel`) scheduler
          (`FlowMatchEulerDiscreteScheduler`)

      Inputs:
          timesteps (`Tensor`):
              The timesteps to use for the denoising process. Can be generated in set_timesteps step.
          num_inference_steps (`int`):
              The number of denoising steps.
          latents (`Tensor`):
              The initial latents to use for the denoising process. Can be generated in prepare_latent step.
          image_latents (`Tensor`):
              image latents used to guide the image generation. Can be generated from vae_encoder step.
          attention_kwargs (`dict`, *optional*):
              Additional kwargs for attention processors.
          **denoiser_input_fields (`None`, *optional*):
              conditional model inputs for the denoiser: e.g. prompt_embeds, negative_prompt_embeds, etc.
          img_shapes (`list`):
              The shape of the image latents for RoPE calculation. Can be generated in prepare_additional_inputs step.

      Outputs:
          latents (`Tensor`):
              Denoised latents.
    zqwenimage-layeredr   r   c                 C   r   )NaR  Denoise step that iteratively denoise the latents. 
Its loop logic is defined in `QwenImageDenoiseLoopWrapper.__call__` method 
At each iteration, it runs blocks defined in `sub_blocks` sequencially:
 - `QwenImageEditLoopBeforeDenoiser`
 - `QwenImageEditLoopDenoiser`
 - `QwenImageLoopAfterDenoiser`
This block supports QwenImage Layered.r   r   r   r   r   r     r   z'QwenImageLayeredDenoiseStep.descriptionNr   r   r   r   r   r   z  r   r   ))r   r%   configuration_utilsr   guidersr   modelsr   r   
schedulersr   utilsr   modular_pipeliner
   r   r   r   modular_pipeline_utilsr   r   r   r   
get_loggerr5   loggerr   r>   rE   rl   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s4   
 HUY)6<9AAP:A