
    +hu                        S SK r S SKJrJrJrJ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  \R8                  " \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)AnyListOptionalTuple   )
FrozenDict)ClassifierFreeGuidance)ControlNetModelUNet2DConditionModel)EulerDiscreteScheduler)logging   )
BlockStateLoopSequentialPipelineBlocksModularPipelineBlocksPipelineState)ComponentSpec
InputParamOutputParam   ) StableDiffusionXLModularPipelinec            	           \ 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)#StableDiffusionXLLoopBeforeDenoiser(   stable-diffusion-xlreturnc                 $    [        S[        5      /$ N	schedulerr   r   selfs    q/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/modular_pipelines/stable_diffusion_xl/denoise.pyexpected_components7StableDiffusionXLLoopBeforeDenoiser.expected_components+        +'=>
 	
    c                      g)Nzstep within the denoising loop that prepare the latent input for the denoiser. This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `StableDiffusionXLDenoiseLoopWrapper`) r!   s    r#   description/StableDiffusionXLLoopBeforeDenoiser.description1       B	
r'   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.required	type_hintr*   )r   torchTensorr!   s    r#   inputs*StableDiffusionXLLoopBeforeDenoiser.inputs9   s&     ,,|	
 	
r'   
componentsblock_stateitc                 ^    UR                   R                  UR                  U5      Ul        X4$ N)r   scale_model_inputr.   scaled_latentsr"   r7   r8   r9   r:   s        r#   __call__,StableDiffusionXLLoopBeforeDenoiser.__call__D   s-    %/%9%9%K%KKL_L_ab%c"&&r'   r)   N)__name__
__module____qualname____firstlineno__
model_namepropertyr   r   r$   strr*   r5   r3   no_gradr   r   intr@   __static_attributes__r)   r'   r#   r   r   (   s    &J
T-%8 
 

 
S 
 
 
S	 
 
 ]]_'#C 'R\ 'ad 'il ' '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\S 5       r\R                  " 5       S\S	\S
\S\4S j5       rSrg)*StableDiffusionXLInpaintLoopBeforeDenoiserL   r   r   c                 B    [        S[        5      [        S[        5      /$ Nr   unetr   r   r   r!   s    r#   r$   >StableDiffusionXLInpaintLoopBeforeDenoiser.expected_componentsO   $     +'=>&"67
 	
r'   c                      g)Nzstep within the denoising loop that prepare the latent input for the denoiser (for inpainting workflow only). This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` objectr)   r!   s    r#   r*   6StableDiffusionXLInpaintLoopBeforeDenoiser.descriptionV   s    y	
r'   c                     [        SS[        R                  SS9[        S[        [        R                     SS9[        S[        [        R                     S	S9/$ )
Nr.   Tr/   r0   mask{The mask to use for the denoising process, for inpainting task only. Can be generated in vae_encode or prepare_latent step.r2   r*   masked_image_latentszThe masked image latents to use for the denoising process, for inpainting task only. Can be generated in vae_encode or prepare_latent step.r   r3   r4   r   r!   s    r#   r5   1StableDiffusionXLInpaintLoopBeforeDenoiser.inputs]   sd     ,,|	 "5<<0 Z
 &"5<<0 j
 	
r'   c                    U R                   nUS:X  a  UR                  b  UR                  c  [        S5      eUR                  R
                  S   nUR                  R
                  S   nUR                  R
                  S   nX4-   U-   U:w  aU  [        SU R                  R                   SU R                  R                  R                   SU SU SU S	X5-   U-    S
35      eg g )N	   zKmask and masked_image_latents must be provided for inpainting-specific Unetr   zCIncorrect configuration settings! The config of `components.unet`: z	 expects z& but received `num_channels_latents`: z + `num_channels_mask`: z  + `num_channels_masked_image`: z = zV. Please verify the config of `components.unet` or your `mask_image` or `image` input.)	num_channels_unetrX   r[   
ValueErrorr.   shaperQ   configin_channels)r7   r8   r`   num_channels_latentsnum_channels_masknum_channels_masked_images         r#   check_inputs7StableDiffusionXLInpaintLoopBeforeDenoiser.check_inputsr   s   &88!';+K+K+S !noo#.#6#6#<#<Q#?  + 0 0 6 6q 9(3(H(H(N(Nq(Q%#7:SSWhh YZdZiZiZpZpYq r"..::;;abvaw x-->,??_`y_z.JM^^_ `PP  i "r'   r7   r8   r9   r:   c                    U R                  X5        UR                  R                  UR                  U5      Ul        UR
                  S:X  a;  [        R                  " UR                  UR                  UR                  /SS9Ul        X4$ )Nr_   r   )dim)
rh   r   r=   r.   r>   r`   r3   catrX   r[   r?   s        r#   r@   3StableDiffusionXLInpaintLoopBeforeDenoiser.__call__   s{    *2%/%9%9%K%KKL_L_ab%c"''1,).++[-=-={?_?_`fg*K& &&r'   r)   N)rB   rC   rD   rE   rF   rG   r   r   r$   rH   r*   r5   staticmethodrh   r3   rI   r   r   rJ   r@   rK   r)   r'   r#   rM   rM   L   s    &J
T-%8 
 
 
S 
 
 
S	 
 
(  $ ]]_	'#C 	'R\ 	'ad 	'il 	' 	'r'   rM   c                       \ rS rSrSr\S\\   4S j5       r\S\	4S j5       r
\S\\\	\4      4S j5       r\R                  " 5       S\S\S	\S
\S\4
S j5       rSrg)StableDiffusionXLLoopDenoiser   r   r   c                 X    [        S[        [        SS05      SS9[        S[        5      /$ )Nguiderguidance_scale      @from_configrc   default_creation_methodrQ   )r   r	   r   r   r!   s    r#   r$   1StableDiffusionXLLoopDenoiser.expected_components   s:     &!#3S"9:(5	 &"67
 	
r'   c                      g)NzStep within the denoising loop that denoise the latents with guidance. This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)r)   r!   s    r#   r*   )StableDiffusionXLLoopDenoiser.description   r,   r'   c                     [        S5      [        SS[        SS9[        S[        [        R                     SS9[        S	S
S9/$ )Ncross_attention_kwargsnum_inference_stepsTgThe number of inference steps to use for the denoising process. Can be generated in set_timesteps step.r0   timestep_condzThe guidance scale embedding to use for Latent Consistency Models(LCMs). Can be generated in prepare_additional_conditioning step.rZ   guider_input_fields  All conditional model inputs that need to be prepared with guider. It should contain prompt_embeds/negative_prompt_embeds, add_time_ids/negative_add_time_ids, pooled_prompt_embeds/negative_pooled_prompt_embeds, and ip_adapter_embeds/negative_ip_adapter_embeds (optional).please add `kwargs_type=guider_input_fields` to their parameter spec (`OutputParam`) when they are created and added to the pipeline statekwargs_typer*   )r   rJ   r   r3   r4   r!   s    r#   r5   $StableDiffusionXLLoopDenoiser.inputs   s`     /0% F	 "5<<0 a
 1a

 	
r'   r7   r8   r9   r:   c                    SSSSS.nUR                   R                  X2R                  US9  UR                   R                  X%5      nU H  nUR                   R	                  UR
                  5        UR                  5       nUR                  5        V	V
s0 s H  u  pX;   d  M  X_M     nn	n
UR                  S5      nUR                  UR                  UUUR                  UR                  USS	9S
   Ul        UR                   R                  UR
                  5        M     UR                  U5      u  Ul        Ul        X4$ s  sn
n	f )Nprompt_embedsnegative_prompt_embedsadd_time_idsnegative_add_time_idspooled_prompt_embedsnegative_pooled_prompt_embedsip_adapter_embedsnegative_ip_adapter_embedsr   time_idstext_embedsimage_embedsstepr~   timestepr   F)encoder_hidden_statesr   r}   added_cond_kwargsreturn_dictr   )rs   	set_stater~   prepare_inputsprepare_modelsrQ   as_dictitemspopr>   r   r}   
noise_predcleanup_modelsscheduler_step_kwargs)r"   r7   r8   r9   r:   r   guider_stateguider_state_batchcond_kwargskvr   s               r#   r@   &StableDiffusionXLLoopDenoiser.__call__   sQ    IATO	
 	##@_@_jk#l "((77Y #/,,Z__=,446K,7,=,=,?\,?DA1C[414,?K\'OOO<M -7OO**&3)77'2'I'I"-! -< - -) ,,Z__=# #/( EODUDUVbDcA A&&' ]s   E#Er)   N)rB   rC   rD   rE   rF   rG   r   r   r$   rH   r*   r   r   r5   r3   rI   r   r   rJ   r   r@   rK   r)   r'   r#   rp   rp      s    &J	
T-%8 	
 	
 
S 
 
 
U38_- 
 
6 ]]_,':,'IS,'X[,'`c,'	,' ,'r'   rp   c            	           \ rS rSrSr\S\\   4S j5       r\S\	4S j5       r
\S\\\	\4      4S j5       r\/ 4S j5       r\R"                  " 5       S\S	\S
\S\4S j5       rSrg)'StableDiffusionXLControlNetLoopDenoiser   r   r   c                 v    [        S[        [        SS05      SS9[        S[        5      [        S[        5      /$ )Nrs   rt   ru   rv   rw   rQ   
controlnet)r   r	   r   r   r
   r!   s    r#   r$   ;StableDiffusionXLControlNetLoopDenoiser.expected_components   sD     &!#3S"9:(5	 &"67,8	
 		
r'   c                      g)Nzstep within the denoising loop that denoise the latents with guidance (with controlnet). This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)r)   r!   s    r#   r*   3StableDiffusionXLControlNetLoopDenoiser.description  r,   r'   c                 2   [        S5      [        SS[        R                  SS9[        S[        SS9[        S	S[        S
S9[        SS[
        [           SS9[        S[        [        R                     SS9[        SS[        SS9[        SSS9[        SSS9/	$ )Nr}   controlnet_condTzgThe control image to use for the denoising process. Can be generated in prepare_controlnet_inputs step.r0   conditioning_scalez}The controlnet conditioning scale value to use for the denoising process. Can be generated in prepare_controlnet_inputs step.rZ   
guess_modezjThe guess mode value to use for the denoising process. Can be generated in prepare_controlnet_inputs step.controlnet_keepzpThe controlnet keep values to use for the denoising process. Can be generated in prepare_controlnet_inputs step.r   zThe guidance scale embedding to use for Latent Consistency Models(LCMs), can be generated by prepare_additional_conditioning stepr~   r   r   r   r   controlnet_kwargszadditional kwargs for controlnet (e.g. control_type_idx and control_type from the controlnet union input step )please add `kwargs_type=controlnet_kwargs` to their parameter spec (`OutputParam`) when they are created and added to the pipeline state)r   r3   r4   floatboolr   r   rJ   r!   s    r#   r5   .StableDiffusionXLControlNetLoopDenoiser.inputs  s     /0!,, F	 $ \
  I	 !u+ O	 "5<<0 `
 % F	 1a
 /__6
 6	
r'   c                     [        [        R                  " U 5      R                  R	                  5       5      n0 nUR                  5        H  u  pVXS;   d  M  XQ;  d  M  XdU'   M     U$ r<   setinspect	signature
parameterskeysr   funcexclude_kwargskwargsaccepted_kwargsextra_kwargskeyvalues          r#   prepare_extra_kwargs<StableDiffusionXLControlNetLoopDenoiser.prepare_extra_kwargsI  X    g//5@@EEGH ,,.JC%#*C$)S! ) r'   r7   r8   r9   r:   c                    U R                   " UR                  R                  40 UR                  D6nSSSSS.n[	        UR
                  U   [        5      (       a@  [        UR                  UR
                  U   5       VVs/ s H	  u  pxXx-  PM     snnUl	        O<UR                  n	[	        U	[        5      (       a  U	S   n	XR
                  U   -  Ul	        S Ul
        S Ul        UR                  R                  X2R                  US9  UR                  R                  X&5      n
U
 GH  nUR                  R!                  UR"                  5        UR$                  UR&                  S.n[)        US	5      (       a  UR*                  b  UR*                  US	'   UR$                  UR&                  S.nUR,                  (       a4  UR                  R.                  (       d  UR                  nUR                  nOUR                  " UR0                  U4UR2                  UR4                  UR                  UR,                  US
S.UD6u  pUR                  c,  U Vs/ s H  n[6        R8                  " U5      PM     snUl
        UR                  c  [6        R8                  " U5      Ul        UR#                  UR0                  UUR2                  UR:                  UR<                  UUUS
S9	S   Ul        UR                  RA                  UR"                  5        GM     UR                  U
5      u  Ul        Ul!        X4$ s  snnf s  snf )Nr   r   r   r   r   r   r   )r   r   r   F)r   r   r   r   r   r   )r   r   r}   r   down_block_additional_residualsmid_block_additional_residualr   )"r   r   forwardr   
isinstancer   listzipr   
cond_scaledown_block_res_samples_zerosmid_block_res_sample_zerosrs   r   r~   r   r   rQ   r   r   hasattrr   r   is_conditionalr>   r   r   r3   
zeros_liker   r}   r   r   r   )r"   r7   r8   r9   r:   extra_controlnet_kwargsr   cscontrolnet_cond_scaler   r   r   controlnet_added_cond_kwargsdown_block_res_samplesmid_block_res_sampleds                    r#   r@   0StableDiffusionXLControlNetLoopDenoiser.__call__S  s;   "&";";!!))#
-8-J-J#
 IATO	
 k11!4d;;"%k&D&DkFaFabcFd"e&"e$!"e&K" %0$B$B!/66(=a(@%%:=X=XYZ=[%[K" 48015. 	##@_@_jk#l "((77Y #/,,Z__=  2==.77! )>::?Q?^?^?j4F4S4S!.1  2==.77,(
 %%j.?.?.N.N)4)Q)Q&'2'M'M$?I?T?T..
@ +=*J*J$/$?$?'2'='=*55&B %
@ .
@<& ;;C]s?t]sXY@P@PQR@S]s?tK<99A=B=M=MNb=cK: -7OO**&8&F&F)77'2'I'I"30F.B! -< 
- 
-) ,,Z__=k #/p EODUDUVbDcA A&&e&x @us   L5 L;r)   N)rB   rC   rD   rE   rF   rG   r   r   r$   rH   r*   r   r   r5   rn   r   r3   rI   r   r   rJ   r@   rK   r)   r'   r#   r   r      s    &J

T-%8 

 

 
S 
 
 7
U38_- 7
 7
r 24   ]]_b'#C b'R\ b'ad b'il b' b'r'   r   c            	           \ rS rSrSr\S\\   4S j5       r\S\	4S j5       r
\S\\\	\4      4S j5       r\S\\   4S j5       r\/ 4S j5       r\R&                  " 5       S	\S
\S\S\4S j5       rSrg)"StableDiffusionXLLoopAfterDenoiseri  r   r   c                 $    [        S[        5      /$ r   r    r!   s    r#   r$   6StableDiffusionXLLoopAfterDenoiser.expected_components  r&   r'   c                      g)Nzstep within the denoising loop that update the latents. This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)r)   r!   s    r#   r*   .StableDiffusionXLLoopAfterDenoiser.description  r,   r'   c                 ,    [        SSS9[        S5      /$ )Neta        default	generator)r   r!   s    r#   r5   )StableDiffusionXLLoopAfterDenoiser.inputs  s      uc*{#
 	
r'   c                 6    [        S[        R                  SS9/$ Nr.   zThe denoised latentsrZ   r   r3   r4   r!   s    r#   intermediate_outputs7StableDiffusionXLLoopAfterDenoiser.intermediate_outputs      IKabccr'   c                     [        [        R                  " U 5      R                  R	                  5       5      n0 nUR                  5        H  u  pVXS;   d  M  XQ;  d  M  XdU'   M     U$ r<   r   r   s          r#   r   7StableDiffusionXLLoopAfterDenoiser.prepare_extra_kwargs  r   r'   r7   r8   r9   r:   c                 Z   U R                  UR                  R                  UR                  UR                  S9Ul        UR                  R                  Ul        UR                  R                  " UR                  UUR                  40 UR
                  DUR                  DSS0D6S   Ul        UR                  R                  UR                  :w  aW  [        R                  R                  R                  5       (       a*  UR                  R                  UR                  5      Ul        X4$ )Nr   r   r   Fr   )r   r   r   r   r   extra_step_kwargsr.   dtypelatents_dtyper   r   r3   backendsmpsis_availabletor?   s        r#   r@   +StableDiffusionXLLoopAfterDenoiser.__call__  s    )-(A(A  %%1F1FKOO )B )
%
 %0$7$7$=$=!(2277""
 ++	

 //
 
  $$(A(AA~~!!..00&1&9&9&<&<[=V=V&W#&&r'   r)   N)rB   rC   rD   rE   rF   rG   r   r   r$   rH   r*   r   r   r5   r   r   rn   r   r3   rI   r   r   rJ   r@   rK   r)   r'   r#   r   r     s    &J
T-%8 
 

 
S 
 
 
U38_- 
 
 dd;&7 d d 24   ]]_'#C 'R\ 'ad 'il ' 'r'   r   c            	           \ rS rSrSr\S\\   4S j5       r\S\	4S j5       r
\S\\\	\4      4S j5       r\S\\   4S j5       r\/ 4S j5       rS	 r\R(                  " 5       S
\S\S\S\4S j5       rSrg))StableDiffusionXLInpaintLoopAfterDenoiseri  r   r   c                 B    [        S[        5      [        S[        5      /$ rP   rR   r!   s    r#   r$   =StableDiffusionXLInpaintLoopAfterDenoiser.expected_components  rT   r'   c                      g)Nzstep within the denoising loop that update the latents (for inpainting workflow only). This block should be used to compose the `sub_blocks` attribute of a `LoopSequentialPipelineBlocks` object (e.g. `StableDiffusionXLDenoiseLoopWrapper`)r)   r!   s    r#   r*   5StableDiffusionXLInpaintLoopAfterDenoiser.description  r,   r'   c                    [        SSS9[        S5      [        SS[        R                  SS9[        S	[        [        R                     S
S9[        S[        [        R                     SS9[        S[        [        R                     SS9/$ )Nr   r   r   r   	timestepsTWThe timesteps to use for the denoising process. Can be generated in set_timesteps step.r0   rX   rY   rZ   noisezhThe noise added to the image latents, for inpainting task only. Can be generated in prepare_latent step.image_latentszThe image latents to use for the denoising process, for inpainting/image-to-image task only. Can be generated in vae_encode or prepare_latent step.r\   r!   s    r#   r5   0StableDiffusionXLInpaintLoopAfterDenoiser.inputs  s     uc*{#,,u	 "5<<0 Z
 "5<<0 G
 "5<<0 r'
 	
r'   c                 6    [        S[        R                  SS9/$ r   r   r!   s    r#   r   >StableDiffusionXLInpaintLoopAfterDenoiser.intermediate_outputs*  r   r'   c                     [        [        R                  " U 5      R                  R	                  5       5      n0 nUR                  5        H  u  pVXS;   d  M  XQ;  d  M  XdU'   M     U$ r<   r   r   s          r#   r   >StableDiffusionXLInpaintLoopAfterDenoiser.prepare_extra_kwargs.  r   r'   c                 @   UR                   S:X  a  UR                  c"  [        SU R                  R                   35      eUR
                  c"  [        SU R                  R                   35      eUR                  c"  [        SU R                  R                   35      eg g )N   z(image_latents is required for this step zmask is required for this step z noise is required for this step )r`   r  ra   	__class__rB   rX   r  )r"   r7   r8   s      r#   rh   6StableDiffusionXLInpaintLoopAfterDenoiser.check_inputs8  s    ''1,((0 #KDNNLcLcKd!eff' #B4>>CZCZB[!\]]  ( #CDNND[D[C\!]^^ ) -r'   r7   r8   r9   r:   c                 D   U R                  X5        U R                  UR                  R                  UR                  UR
                  S9Ul        UR                  R                  Ul	        UR                  R                  " UR                  UUR                  40 UR                  DUR                  DSS0D6S   Ul        UR                  R                  UR                  :w  aW  [        R                  R                  R                  5       (       a*  UR                  R!                  UR                  5      Ul        UR"                  S:X  a  UR$                  Ul        U[)        UR*                  5      S-
  :  al  UR*                  US-      Ul        UR                  R/                  UR&                  UR0                  [        R2                  " UR,                  /5      5      Ul        SUR4                  -
  UR&                  -  UR4                  UR                  -  -   Ul        X4$ )Nr   r   Fr   r  r   )rh   r   r   r   r   r   r   r.   r   r   r   r   r3   r   r   r  r  r`   r  init_latents_properlenr  noise_timestep	add_noiser  tensorrX   r?   s        r#   r@   2StableDiffusionXLInpaintLoopAfterDenoiser.__call__A  s   *2 )-(A(A  %%1F1FKOO )B )
%
 %0$7$7$=$=!(2277""
 ++	

 //
 
  $$(A(AA~~!!..00&1&9&9&<&<[=V=V&W# ''1,.9.G.GK+3{,,-11-8-B-B1q5-I*2<2F2F2P2P33[5F5FVaVpVpUqHr3/
 K$$$//#02=2B2B[EXEX2X#YK &&r'   r)   N)rB   rC   rD   rE   rF   rG   r   r   r$   rH   r*   r   r   r5   r   r   rn   r   rh   r3   rI   r   r   rJ   r@   rK   r)   r'   r#   r  r    s    &J
T-%8 
 
 
S 
 
 
U38_- 
 
6 dd;&7 d d 24  _ ]]_%'#C %'R\ %'ad %'il %' %'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)#StableDiffusionXLDenoiseLoopWrapperik  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*   /StableDiffusionXLDenoiseLoopWrapper.descriptionn  s    d	
r'   c                 v    [        S[        [        SS05      SS9[        S[        5      [        S[        5      /$ )Nrs   rt   ru   rv   rw   r   rQ   )r   r	   r   r   r   r!   s    r#   loop_expected_components<StableDiffusionXLDenoiseLoopWrapper.loop_expected_componentsu  sE     &!#3S"9:(5	 +'=>&"67	
 		
r'   c                 V    [        SS[        R                  SS9[        SS[        SS9/$ )Nr  Tr  r0   r~   r   )r   r3   r4   rJ   r!   s    r#   loop_inputs/StableDiffusionXLDenoiseLoopWrapper.loop_inputs  s?     ,,u	 % F	
 	
r'   r7   statec           	      H   U R                  U5      nUR                  R                  R                  b  SOSUl        UR                  (       a  UR
                  R                  5         OUR
                  R                  5         [        [        UR                  5      UR                  UR                  R                  -  -
  S5      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)NTFr   )total)r9   r:   r   )get_block_staterQ   rc   time_cond_proj_dimdisable_guidancers   disableenablemaxr  r  r~   r   ordernum_warmup_stepsprogress_bar	enumerate	loop_stepupdateset_block_state)r"   r7   r)  r8   r4  r9   r:   s          r#   r@   ,StableDiffusionXLDenoiseLoopWrapper.__call__  s]   **51/9/E/E/X/X/dtjo$''%%'$$&'*%%&)H)H:K_K_KeKe)eegh(
$ [%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FF#F
F!r)   N)rB   rC   rD   rE   rF   rG   rH   r*   r   r   r$  r   r'  r3   rI   r   r   r@   rK   r)   r'   r#   r   r   k  s    &J
S 
 
 

$}*= 

 

 
T*- 
 
  ]]_!#C !M !^k ! !r'   r   c                   >    \ rS rSr\\\/r/ SQr\	S\
4S j5       rSrg)StableDiffusionXLDenoiseStepi  before_denoiserdenoiserafter_denoiserr   c                      g)Nax  Denoise step that iteratively denoise the latents. 
Its loop logic is defined in `StableDiffusionXLDenoiseLoopWrapper.__call__` method 
At each iteration, it runs blocks defined in `sub_blocks` sequencially:
 - `StableDiffusionXLLoopBeforeDenoiser`
 - `StableDiffusionXLLoopDenoiser`
 - `StableDiffusionXLLoopAfterDenoiser`
This block supports both text2img and img2img tasks.r)   r!   s    r#   r*   (StableDiffusionXLDenoiseStep.description  s    C	
r'   r)   N)rB   rC   rD   rE   r   rp   r   block_classesblock_namesrG   rH   r*   rK   r)   r'   r#   r;  r;    s3    +%*M
 DK	
S 	
 	
r'   r;  c                   >    \ rS rSr\\\/r/ SQr\	S\
4S j5       rSrg)&StableDiffusionXLControlNetDenoiseStepi  r<  r   c                      g)Na  Denoise step that iteratively denoise the latents with controlnet. 
Its loop logic is defined in  `StableDiffusionXLDenoiseLoopWrapper.__call__` method 
At each iteration, it runs blocks defined in `sub_blocks` sequencially:
 - `StableDiffusionXLLoopBeforeDenoiser`
 - `StableDiffusionXLControlNetLoopDenoiser`
 - `StableDiffusionXLLoopAfterDenoiser`
This block supports using controlnet for both text2img and img2img tasks.r)   r!   s    r#   r*   2StableDiffusionXLControlNetDenoiseStep.description  s    X	
r'   r)   N)rB   rC   rD   rE   r   r   r   rB  rC  rG   rH   r*   rK   r)   r'   r#   rE  rE    s3    +/*M
 DK	
S 	
 	
r'   rE  c                   >    \ rS rSr\\\/r/ SQr\	S\
4S j5       rSrg)#StableDiffusionXLInpaintDenoiseStepi  r<  r   c                      g)Na  Denoise step that iteratively denoise the latents(for inpainting task only). 
Its loop logic is defined in `StableDiffusionXLDenoiseLoopWrapper.__call__` method 
At each iteration, it runs blocks defined in `sub_blocks` sequencially:
 - `StableDiffusionXLInpaintLoopBeforeDenoiser`
 - `StableDiffusionXLLoopDenoiser`
 - `StableDiffusionXLInpaintLoopAfterDenoiser`
This block onlysupports inpainting tasks.r)   r!   s    r#   r*   /StableDiffusionXLInpaintDenoiseStep.description  s    8	
r'   r)   N)rB   rC   rD   rE   rM   rp   r  rB  rC  rG   rH   r*   rK   r)   r'   r#   rI  rI    s3    2%1M
 DK	
S 	
 	
r'   rI  c                   >    \ rS rSr\\\/r/ SQr\	S\
4S j5       rSrg)-StableDiffusionXLInpaintControlNetDenoiseStepi  r<  r   c                      g)Na  Denoise step that iteratively denoise the latents(for inpainting task only) with controlnet. 
Its loop logic is defined in `StableDiffusionXLDenoiseLoopWrapper.__call__` method 
At each iteration, it runs blocks defined in `sub_blocks` sequencially:
 - `StableDiffusionXLInpaintLoopBeforeDenoiser`
 - `StableDiffusionXLControlNetLoopDenoiser`
 - `StableDiffusionXLInpaintLoopAfterDenoiser`
This block only supports using controlnet for inpainting tasks.r)   r!   s    r#   r*   9StableDiffusionXLInpaintControlNetDenoiseStep.description  s    N	
r'   r)   N)rB   rC   rD   rE   rM   r   r  rB  rC  rG   rH   r*   rK   r)   r'   r#   rM  rM    s3    2/1M
 DK	
S 	
 	
r'   rM  )*r   typingr   r   r   r   r3   configuration_utilsr   guidersr	   modelsr
   r   
schedulersr   utilsr   modular_pipeliner   r   r   r   modular_pipeline_utilsr   r   r   r   
get_loggerrB   loggerr   rM   rp   r   r   r  r   r;  rE  rI  rM  r)   r'   r#   <module>rZ     s     - -  - - ; 0   L K > 
		H	%
 '*?  'HC'1F C'N`'$9 `'H'.C 'F>')> >'Dk'0E k'^@!*F @!H
#F 
,
-P 
,
*M 
,
4W 
r'   