
    3jL                     |    S SK r S SKJr  S SKJrJr  S r " S S\R                  5      r " S S\5      r	S	\	4S
 jr
g)    N)override)ComfyExtensionioc                     [         R                  R                  R                  U/ SQS9nX-  R	                  / SQSS9U-  nX-
  nX#4$ )N)dimT)r   keepdim)torchnn
functional	normalizesum)v0v1v0_parallelv0_orthogonals       6/home/wildlama/comfy/ComfyUI/comfy_extras/nodes_apg.pyprojectr      sK    				&	&r|	&	<B7--L$-?"DK$M%%    c                   l    \ rS rSr\S\R                  4S j5       r\S\R                  4S j5       r	Sr
g)APG   returnc                 t   [         R                  " SSS[         R                  R                  S5      [         R                  R                  SSSSS	S
SS9[         R                  R                  SSSSSSSS9[         R                  R                  SSSSS	SSS9/[         R                  R                  5       /S9$ )Nr   zAdaptive Projected Guidancezmodel/sampling/custommodeletag      ?g      $g      $@g{Gz?z[Controls the scale of the parallel guidance vector. Default CFG behavior at a setting of 1.T)defaultminmaxsteptooltipadvancednorm_thresholdg      @g        g      I@g?zQNormalize guidance vector to this value, normalization disable at a setting of 0.momentumg      zTControls a running average of guidance during diffusion, disabled at a setting of 0.)node_iddisplay_namecategoryinputsoutputs)r   SchemaModelInputFloatOutput)clss    r   define_schemaAPG.define_schema   s    yy6,w'y!   $o!   r!  )< XX__&'E#
 #	
r   c                    ^^^^^ SmS mUUUUU4S jnUR                  5       nUR                  U5        [        R                  " U5      $ )Nr   c                   > [        U S   5      S:X  a  U S   $ U S   S   nU S   S   nU S   S   nU S   nTb  UT:  a  SmUmX-
  nTS:w  a(  [        R                  " T5      (       d  UmOTT-  U-   mTnTS:  aE  UR                  S/ SQSS	9n[        R                  " [        R
                  " U5      TU-  5      nXW-  n[        XQ5      u  pU	TU-  -   n
X*-   X-
  U-  -   nX/U S   SS  -   $ )
N	conds_out   r   sigma
cond_scale   r   T)pr   r   )lenr   	is_tensornormminimum	ones_liker   )argsconduncondr9   r:   guidanceguidance_normscaleguidance_parallelguidance_orthogonalmodified_guidancemodified_condr   r'   r&   
prev_sigmarunning_avgs               r   pre_cfg_function%APG.execute.<locals>.pre_cfg_function:   s:    4$%*K(($Q'D+&q)FM!$El+J%%**<J}H1}{33"*K"*["88"CK&! (|T ROOM2"]2 $+5<X5L2 3c<M6M M#7DMZ;WWM!*T+->qr-BBBr   )clone"set_model_sampler_pre_cfg_functionr   
NodeOutput)	r2   r   r   r&   r'   rN   mrL   rM   s	     ```  @@r   executeAPG.execute5   sE    
%	C %	CN KKM	,,-=>}}Qr    N)__name__
__module____qualname____firstlineno__classmethodr   r-   r3   rR   rT   __static_attributes__rV   r   r   r   r      s?    $
bii $
 $
L - bmm -  - r   r   c                   L    \ rS rSr\S\\\R                        4S j5       r	Sr
g)ApgExtensionf   r   c                    #    [         /$ 7fN)r   )selfs    r   get_node_listApgExtension.get_node_listg   s      
 	
s   
rV   N)rW   rX   rY   rZ   r   listtyper   	ComfyNoderc   r\   rV   r   r   r^   r^   f   s)    
T$r||*<%= 
 
r   r^   r   c                     #    [        5       $ 7fra   )r^   rV   r   r   comfy_entrypointri   m   s     >s   )r   typing_extensionsr   comfy_api.latestr   r   r   rg   r   r^   ri   rV   r   r   <module>rl      s>     & /&V ",, V r
> 
 r   