
    
3j                        S SK r S SKrSSKJr  SSKJr  SSKJrJr  SSK	J
r
  SSKJr  SS	KJrJrJrJr  SS
KJrJrJr  SSKJr  \R.                  " \5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r  " S S\5      r! " S S\!5      r" " S S \!5      r# " S! S"\!5      r$ " S# S$\!5      r% " S% S&\!5      r& " S' S(\!5      r' " S) S*\!5      r(g)+    N   )
FrozenDict)ClassifierFreeGuidance)QwenImageControlNetModelQwenImageTransformer2DModel)FlowMatchEulerDiscreteScheduler)logging   )
BlockStateLoopSequentialPipelineBlocksModularPipelineBlocksPipelineState)ComponentSpec
InputParamOutputParam   )QwenImageModularPipelinec            	           \ rS rSrSr\S\4S j5       r\S\\	   4S j5       r
\R                  " 5       S\S\S\S	\R                   4S
 j5       rSrg)QwenImageLoopBeforeDenoiser%   	qwenimagereturnc                      g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`) selfs    g/home/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/modular_pipelines/qwenimage/denoise.pydescription'QwenImageLoopBeforeDenoiser.description(       :	
    c                 8    [        SS[        R                  SS9/$ )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   s    r   inputs"QwenImageLoopBeforeDenoiser.inputs0   s&     ,,|	
 	
r"   
componentsblock_stateitc                     UR                  UR                  R                  S   5      R                  UR                  R                  5      Ul        UR                  Ul        X4$ )Nr   )expandr$   shapetodtypetimesteplatent_model_inputr   r.   r/   r0   r1   s        r   __call__$QwenImageLoopBeforeDenoiser.__call__;   sT      !xx(;(;(A(A!(DEHHI\I\IbIbc)4)<)<&&&r"   r   N__name__
__module____qualname____firstlineno__
model_namepropertystrr   listr   r,   r*   no_gradr   r   intr+   r:   __static_attributes__r   r"   r   r   r   %   s    J
S 
 
 
Z( 
 
 ]]_'#; '* 'Y\ 'afamam ' 'r"   r   c            	           \ rS rSrSr\S\4S j5       r\S\\	   4S j5       r
\R                  " 5       S\S\S\S	\R                   4S
 j5       rSrg)QwenImageEditLoopBeforeDenoiserC   qwenimage-editr   c                      gr   r   r   s    r   r   +QwenImageEditLoopBeforeDenoiser.descriptionF   r!   r"   c                 b    [        SS[        R                  SS9[         R                  " S5      /$ )Nr$   Tr%   r&   image_latentsr   r*   r+   templater   s    r   r,   &QwenImageEditLoopBeforeDenoiser.inputsN   s6     ,,|	 0
 	
r"   r.   r/   r0   r1   c                    [         R                  " UR                  UR                  /SS9Ul        UR                  UR                  R                  S   5      R                  UR                  R                  5      Ul	        X4$ )Nr   )dimr   )
r*   catr$   rO   r8   r3   r4   r5   r6   r7   r9   s        r   r:   (QwenImageEditLoopBeforeDenoiser.__call__Z   sk     */K4G4GIbIb3cij)k& xx(;(;(A(A!(DEHHI\I\IbIbc&&r"   r   Nr<   r   r"   r   rI   rI   C   s    !J
S 
 
 	
Z( 	
 	
 ]]_'#; '* 'Y\ 'afamam ' 'r"   rI   c            	           \ rS rSrSr\S\\   4S j5       r\S\	4S j5       r
\S\\   4S j5       r\R                  " 5       S\S\S	\S
\4S j5       rSrg)%QwenImageLoopBeforeDenoiserControlNetc   r   r   c                 X    [        S[        [        SS05      SS9[        S[        5      /$ )Nguiderguidance_scale      @from_configconfigdefault_creation_method
controlnet)r   r   r   r   r   s    r   expected_components9QwenImageLoopBeforeDenoiserControlNet.expected_componentsf   s:     &!#3S"9:(5	 ,(@A
 	
r"   c                      g)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   s    r   r   1QwenImageLoopBeforeDenoiserControlNet.descriptionr   r!   r"   c           	          [        SS[        R                  SS9[         R                  " SSS9[        SS[        [
           S	S
9/$ )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+   rQ   rD   floatr   s    r   r,   ,QwenImageLoopBeforeDenoiserControlNet.inputsz   sU     ',, F	  ?Frs&u+m	
 	
r"   r.   r/   r0   r1   c                 *   [        UR                  U   [        5      (       a@  [        UR                  UR                  U   5       VVs/ s H	  u  pVXV-  PM     snnUl        O<UR                  n[        U[        5      (       a  US   nXrR                  U   -  Ul        UR                  UR                  UR                  UR
                  UR                  S-  UR                  UR                  UR                  SS9nXR                  S'   X4$ s  snnf )Nr     F)hidden_statescontrolnet_condconditioning_scaler7   
img_shapesencoder_hidden_statesencoder_hidden_states_maskreturn_dictcontrolnet_block_samples)
isinstancerl   rD   ziprj   
cond_scalerb   r8   rh   r7   rt   prompt_embedsprompt_embeds_maskadditional_cond_kwargs)	r   r.   r/   r0   r1   cscontrolnet_cond_scalerx   s	            r   r:   .QwenImageLoopBeforeDenoiserControlNet.__call__   s    k11!4d;;"%k&O&OQ\QlQlmnQo"p&"p$!"p&K" %0$M$M!/66(=a(@%%:=X=XYZ=[%[K" $.#8#8%88'==*55 ))D0"--"-";";'2'E'E $9 	$
  Jb**+EF&&/&s   	Dr   N)r=   r>   r?   r@   rA   rB   rD   r   rc   rC   r   r   r,   r*   rE   r   r   rF   r:   rG   r   r"   r   rX   rX   c   s    J	
T-%8 	
 	
 
S 
 
 
Z( 
 
" ]]_'#; '* 'Y\ 'ad ' 'r"   rX   c            	           \ rS rSrSr\S\4S j5       r\S\\	   4S j5       r
\S\\   4S j5       r\R                  " 5       S\S\S	\S
\R$                  4S j5       rSrg)QwenImageLoopDenoiser   r   r   c                      g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   s    r   r   !QwenImageLoopDenoiser.description   r!   r"   c                 X    [        S[        [        SS05      SS9[        S[        5      /$ Nr[   r\   r]   r^   r_   transformerr   r   r   r   r   s    r   rc   )QwenImageLoopDenoiser.expected_components   :     &!#3S"9:(5	 -)DE
 	
r"   c           
          [         R                  " S5      [         R                  " S5      [        SS[        [        [        [        4      SS9/$ )Nattention_kwargsdenoiser_input_fieldsrt   TzhThe shape of the image latents for RoPE calculation. can be generated in prepare_additional_inputs step.ri   r   rQ   rD   tuplerF   r   s    r   r,   QwenImageLoopDenoiser.inputs   P      23 78uS#X/ G		
 		
r"   r.   r/   r0   r1   c           	         [        USS 5      [        USS 5      4[        USS 5      [        USS 5      4S.n[        [        R                  " UR                  R
                  5      R                  R                  5       5      n0 nUR                  R                  5        H  u  pX;   d  M  X;  d  M  XU'   M     UR                  R                  U5        UR                  R                  X2R                  US9  UR                  R                  U5      n
U
 H  nUR                  R!                  UR                  5        UR                  5        Vs0 s H  o[        X5      _M     nnUR                  " SUR"                  UR$                  S-  UR&                  SS	.UDUR                  D6S
   Ul        UR                  R+                  UR                  5        M     UR                  U
5      n[,        R.                  " UR0                  SSS9n[,        R.                  " UR2                  SSS9nUR2                  UU-  -  Ul        X4$ s  snf )Nr|   negative_prompt_embedsr}   negative_prompt_embeds_maskru   rv   stepnum_inference_stepsr7   rp   Frq   r7   r   rw   r   TrT   keepdimr   )getattrsetinspect	signaturer   forward
parameterskeysr   itemsr~   updater[   	set_stater   prepare_inputsprepare_modelsr8   r7   r   
noise_predcleanup_modelsr*   norm	pred_condpred)r   r.   r/   r0   r1   guider_inputstransformer_argsr~   
field_namefield_valueguider_stateguider_state_batch
input_namecond_kwargsguider_outputpred_cond_norm	pred_norms                    r   r:   QwenImageLoopDenoiser.__call__   s7    _d;%=tD&
 %94@%BDI+	
 w001G1G1O1OP[[``bc!#'2'H'H'N'N'P#J-*2Q5@z2 (Q 	**112HI##@_@_jk#l!((77F".,,Z-C-CDanasasauvauS]w/A'NNauKv -7,B,B -)<<$--4!,!=!=!	-
 - 44- -) ,,Z-C-CD #/  #)),7 M$;$;TRJJ}11r4H	!.!3!3~	7Q!R&&+ ws   Ir   Nr=   r>   r?   r@   rA   rB   rC   r   rD   r   rc   r   r,   r*   rE   r   r   rF   r+   r:   rG   r   r"   r   r   r      s    J
S 
 
 	
T-%8 	
 	
 

Z( 

 

 ]]_-'#; -'* -'Y\ -'afamam -' -'r"   r   c            	           \ rS rSrSr\S\4S j5       r\S\\	   4S j5       r
\S\\   4S j5       r\R                  " 5       S\S\S	\S
\R$                  4S j5       rSrg)QwenImageEditLoopDenoiser   rK   r   c                      gr   r   r   s    r   r   %QwenImageEditLoopDenoiser.description  r!   r"   c                 X    [        S[        [        SS05      SS9[        S[        5      /$ r   r   r   s    r   rc   -QwenImageEditLoopDenoiser.expected_components  r   r"   c           
          [         R                  " S5      [         R                  " S5      [        SS[        [        [        [        4      SS9/$ )Nr   r   rt   TzhThe shape of the image latents for RoPE calculation. Can be generated in prepare_additional_inputs step.ri   r   r   s    r   r,    QwenImageEditLoopDenoiser.inputs  r   r"   r.   r/   r0   r1   c           	         [        USS 5      [        USS 5      4[        USS 5      [        USS 5      4S.n[        [        R                  " UR                  R
                  5      R                  R                  5       5      n0 nUR                  R                  5        H  u  pX;   d  M  X;  d  M  XU'   M     UR                  R                  U5        UR                  R                  X2R                  US9  UR                  R                  U5      n
U
 H  nUR                  R!                  UR                  5        UR                  5        Vs0 s H  o[        X5      _M     nnUR                  " SUR"                  UR$                  S-  UR&                  SS	.UDUR                  D6S
   Ul        UR                  R+                  UR                  5        M     UR                  U
5      nUR,                  S S 2S UR.                  R1                  S5      24   nUR2                  S S 2S UR.                  R1                  S5      24   n[4        R6                  " USSS9n[4        R6                  " USSS9nUUU-  -  Ul        X4$ s  snf )Nr|   r   r}   r   r   r   rp   Fr   r   r   r   Tr   r   )r   r   r   r   r   r   r   r   r   r   r~   r   r[   r   r   r   r   r8   r7   r   r   r   r   r$   sizer   r*   r   )r   r.   r/   r0   r1   r   r   r~   r   r   r   r   r   r   r   r   r   r   r   s                      r   r:   "QwenImageEditLoopDenoiser.__call__$  s}    _d;%=tD&
 %94@%BDI+	
 w001G1G1O1OP[[``bc!#'2'H'H'N'N'P#J-*2Q5@z2 (Q 	**112HI##@_@_jk#l!((77F".,,Z-C-CDanasasauvauS]w/A'NNauKv -7,B,B -)<<$--4!,!=!=!	-
 - 44- -) ,,Z-C-CD #/  #)),7!!!%B{':':'?'?'B%B"BC!++A/L1D1D1I1I!1L/L,LM	 I2tDJJtT:	!%))C!D&&1 ws   Jr   Nr   r   r"   r   r   r      s    !J
S 
 
 	
T-%8 	
 	
 

Z( 

 

 ]]_0'#; 0'* 0'Y\ 0'afamam 0' 0'r"   r   c            	           \ rS rSrSr\S\4S j5       r\S\\	   4S j5       r
\S\\   4S j5       r\R                  " 5       S\S\S	\S
\R$                  4S j5       rSrg)QwenImageLoopAfterDenoiseriY  r   r   c                      g)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   s    r   r   &QwenImageLoopAfterDenoiser.description\  r!   r"   c                 $    [        S[        5      /$ N	schedulerr   r   r   s    r   rc   .QwenImageLoopAfterDenoiser.expected_componentsd       +'FG
 	
r"   c                 0    [         R                  " S5      /$ Nr$   r   rQ   r   s    r   intermediate_outputs/QwenImageLoopAfterDenoiser.intermediate_outputsj         +
 	
r"   r.   r/   r0   r1   c                 r   UR                   R                  nUR                  R                  UR                  UUR                   SS9S   Ul         UR                   R                  U:w  aM  [
        R                  R                  R                  5       (       a   UR                   R                  U5      Ul         X4$ )NF)rw   r   )
r$   r6   r   r   r   r*   backendsmpsis_availabler5   )r   r.   r/   r0   r1   latents_dtypes         r   r:   #QwenImageLoopAfterDenoiser.__call__p  s    #++11(2277""	 8 

  $$5~~!!..00&1&9&9&<&<]&K#&&r"   r   N)r=   r>   r?   r@   rA   rB   rC   r   rD   r   rc   r   r   r*   rE   r   r   rF   r+   r:   rG   r   r"   r   r   r   Y  s    J
S 
 
 
T-%8 
 

 
d;&7 
 

 ]]_'#; '* 'Y\ 'afamam ' 'r"   r   c            	           \ rS rSrSr\S\4S j5       r\S\\	   4S j5       r
\S\\   4S j5       r\R                  " 5       S\S\S	\S
\R$                  4S j5       rSrg)!QwenImageLoopAfterDenoiserInpainti  r   r   c                      g)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   s    r   r   -QwenImageLoopAfterDenoiserInpaint.description  r!   r"   c           	          [        SS[        R                  SS9[         R                  " S5      [        SS[        R                  SS9/$ )NmaskTz]The mask to use for the inpainting process. Can be generated in inpaint prepare latents step.ri   rO   initial_noisezfThe initial noise to use for the inpainting process. Can be generated in inpaint prepare latents step.rP   r   s    r   r,   (QwenImageLoopAfterDenoiserInpaint.inputs  sQ     ,,{	 0,, E	
 	
r"   c                 0    [         R                  " S5      /$ r   r   r   s    r   r   6QwenImageLoopAfterDenoiserInpaint.intermediate_outputs  r   r"   r.   r/   r0   r1   c                    UR                   Ul        U[        UR                  5      S-
  :  al  UR                  US-      Ul        UR
                  R                  UR                  [        R                  " UR                  /5      UR                  5      Ul        SUR                  -
  UR                  -  UR                  UR                  -  -   Ul        X4$ )Nr   )rO   init_latents_properlen	timestepsnoise_timestepr   scale_noiser*   tensorr   r   r$   r9   s        r   r:   *QwenImageLoopAfterDenoiserInpaint.__call__  s    *5*C*C's;(()A--)4)>)>q1u)EK&.8.B.B.N.N//{?Y?Y>Z1[]h]v]v/K+
    ++,.9.>.>ATAT.TU &&r"   r   N)r=   r>   r?   r@   rA   rB   rC   r   rD   r   r,   r   r   r*   rE   r   r   rF   r+   r:   rG   r   r"   r   r   r     s    J
S 
 
 
Z( 
 
" 
d;&7 
 

 ]]_'#; '* 'Y\ 'afamam ' 'r"   r   c                       \ rS rSrSr\S\4S j5       r\S\\	   4S j5       r
\S\\   4S j5       r\R                  " 5       S\S\S\4S	 j5       rS
rg)QwenImageDenoiseLoopWrapperi  r   r   c                      g)NzPipeline block that iteratively denoise the latents over `timesteps`. The specific steps with each iteration can be customized with `sub_blocks` attributesr   r   s    r   r   'QwenImageDenoiseLoopWrapper.description  s    d	
r"   c                 $    [        S[        5      /$ r   r   r   s    r   loop_expected_components4QwenImageDenoiseLoopWrapper.loop_expected_components  r   r"   c                 `    [        SS[        R                  SS9[         R                  " SSS9/$ )Nr   TzWThe timesteps to use for the denoising process. Can be generated in set_timesteps step.r&   r   )r(   rP   r   s    r   loop_inputs'QwenImageDenoiseLoopWrapper.loop_inputs  s9      ,,u	  5E
 	
r"   r.   statec           	      v   U R                  U5      n[        [        UR                  5      UR                  UR
                  R                  -  -
  S5      Ul        0 Ul        U R                  UR                  S9 n[        UR                  5       Hz  u  pVU R                  XXVS9u  pU[        UR                  5      S-
  :X  d7  US-   UR                  :  d  MH  US-   UR
                  R                  -  S:X  d  Mj  UR                  5         M|     S S S 5        U R                  X#5        X4$ ! , (       d  f       N"= f)Nr   )total)r0   r1   r   )get_block_statemaxr   r   r   r   ordernum_warmup_stepsr~   progress_bar	enumerate	loop_stepr   set_block_state)r   r.   r   r/   r  r0   r1   s          r   r:   $QwenImageDenoiseLoopWrapper.__call__  s   **51'*%%&)H)H:K_K_KeKe)eegh(
$ .0*[%D%DE!+"7"78*...TU.*['
K112Q66Uk:::AI]I]IcIc?cgh?h '') 9 F 	U0   FEs   :AD*D*:D**
D8r   N)r=   r>   r?   r@   rA   rB   rC   r   rD   r   r   r   r   r*   rE   r   r   r:   rG   r   r"   r   r   r     s    J
S 
 
 
$}*= 
 

 	
T*- 	
 	
 ]]_!#; !M !Vc ! !r"   r   c                   F    \ rS rSrSrSr\\\/r	/ SQr
\S\4S j5       rSrg)	QwenImageDenoiseStepi  a/  
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                      g)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   s    r   r    QwenImageDenoiseStep.description  s    R	
r"   r   N)r=   r>   r?   r@   __doc__rA   r   r   r   block_classesblock_namesrB   rC   r   rG   r   r"   r   r
  r
    sB    @ J 	$"M
 DK	
S 	
 	
r"   r
  c                   H    \ rS rSrSrSr\\\\	/r
/ SQr\S\4S j5       rSrg)	QwenImageInpaintDenoiseStepi-  a  
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                      g)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   s    r   r   'QwenImageInpaintDenoiseStep.description^  s    B		
r"   r   N)r=   r>   r?   r@   r  rA   r   r   r   r   r  r  rB   rC   r   rG   r   r"   r   r  r  -  sC    %N J#")	M ^K

S 

 

r"   r  c                   H    \ rS rSrSrSr\\\\	/r
/ SQr\S\4S j5       rSrg)	QwenImageControlNetDenoiseStepin  aD  
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                      g)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   s    r   r   *QwenImageControlNetDenoiseStep.description  s    X		
r"   r   N)r=   r>   r?   r@   r  rA   r   rX   r   r   r  r  rB   rC   r   rG   r   r"   r   r  r  n  sC    %N J#-"	M bK

S 

 

r"   r  c                   J    \ rS rSrSrSr\\\\	\
/r/ SQr\S\4S j5       rSrg)	%QwenImageInpaintControlNetDenoiseStepi  a  
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                      g)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   s    r   r   1QwenImageInpaintControlNetDenoiseStep.description  s    R
	
r"   r   N)r=   r>   r?   r@   r  rA   r   rX   r   r   r   r  r  rB   rC   r   rG   r   r"   r   r   r     sG    ,\ J#-")MK 
S 
 
r"   r   c                   F    \ rS rSrSrSr\\\/r	/ SQr
\S\4S j5       rSrg)	QwenImageEditDenoiseStepi  a  
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.
rK   r  r   c                      g)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   s    r   r   $QwenImageEditDenoiseStep.description*  s    2	
r"   r   Nr=   r>   r?   r@   r  rA   rI   r   r   r  r  rB   rC   r   rG   r   r"   r   r$  r$    s@     D "J'!"M
 DK	
S 	
 	
r"   r$  c                   H    \ rS rSrSrSr\\\\	/r
/ SQr\S\4S j5       rSrg)	QwenImageEditInpaintDenoiseStepi9  a  
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.
rK   r  r   c                      g)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   s    r   r   +QwenImageEditInpaintDenoiseStep.descriptionj  s    G		
r"   r   N)r=   r>   r?   r@   r  rA   rI   r   r   r   r  r  rB   rC   r   rG   r   r"   r   r)  r)  9  sC    %N "J'!")	M ^K

S 

 

r"   r)  c                   F    \ rS rSrSrSr\\\/r	/ SQr
\S\4S j5       rSrg)	QwenImageLayeredDenoiseStepiz  a  
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                      g)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   s    r   r   'QwenImageLayeredDenoiseStep.description  s    5	
r"   r   Nr'  r   r"   r   r-  r-  z  s@     D %J'!"M
 DK	
S 	
 	
r"   r-  ))r   r*   configuration_utilsr   guidersr   modelsr   r   
schedulersr   utilsr	   modular_pipeliner   r   r   r   modular_pipeline_utilsr   r   r   r   
get_loggerr=   loggerr   rI   rX   r   r   r   r   r   r
  r  r  r   r$  r)  r-  r   r"   r   <module>r9     s     - - K 9  m m K K 6 
		H	%'"7 '<'&; '@D',A D'PR'1 R'jU' 5 U'r&'!6 &'R0'(= 0'l0!"> 0!x4
6 4
r<
"= <
B<
%@ <
BK
,G K
`5
: 5
t<
&A <
B5
"= 5
r"   