
    3j                         S SK Jr  S SKrS SKJrJr   " S S\R                  5      r " S S\R                  5      r " S S	\5      r	S
\	4S jr
g)    )overrideN)ComfyExtensionioc                   P    \ rS rSr\S 5       r\S\R                  4S j5       rSr	g)	RenormCFG   c                 *   [         R                  " SS[         R                  R                  S5      [         R                  R                  SSSSSS	S
9[         R                  R                  SSSSSS	S
9/[         R                  R                  5       /S9$ )Nr   zmodel/patchmodel	cfg_truncd           g      Y@g{Gz?T)defaultminmaxstepadvanced
renorm_cfgg      ?)node_idcategoryinputsoutputs)r   SchemaModelInputFloatOutputclss    :/home/wildlama/comfy/ComfyUI/comfy_extras/nodes_lumina2.pydefine_schemaRenormCFG.define_schema   s    yy"w'{CSeRVaef|ScuSWbfg !
 	
    returnc                    ^^^ UUU4S jnTR                  5       nUR                  U5        [        R                  " U5      $ )Nc                   > U S   nU S   nU S   nU S   nU S   nTR                   R                  R                  nUS   T:  a  US S 2S U24   US S 2S U24   pUS S 2US 24   US S 2US 24   pXXx-
  -  -   nU	n[        T5      S:  a  [        R
                  R                  U[        [        S[        UR                  5      5      5      S	S
9nU[        T5      -  n[        R
                  R                  U[        [        S[        UR                  5      5      5      S	S
9nX:  a  XU-  -  nO.US S 2S U24   US S 2S U24   pUS S 2US 24   US S 2US 24   pUnU	n[        R                  " X/SS9nUU-
  $ )Ncond_denoiseduncond_denoised
cond_scaletimestepinputr   r      T)dimkeepdim)r,   )r
   diffusion_modelin_channelsfloattorchlinalgvector_normtuplerangelenshapecat)argsr&   r'   r(   r)   x_origr/   cond_eps
uncond_eps	cond_rest_half_eps	half_restori_pos_normmax_new_normnew_pos_norm
cfg_resultr   r
   r   s                    r   renorm_cfg_func*RenormCFG.execute.<locals>.renorm_cfg_func   s    1M"#45Ol+JJ'H']F++55AAK{Y&'4Q_'EWXZf[fZfWfGg*,Q_=qR]R^?_1%h6K(LL%	$s*#(<<#;#;H"'aX^^1D(E"FPT $< $L $0%
2C#CL#(<<#;#;$%aX^^9L0M*NX\ $< $L $3#+l/J#K'4Q_'EWXZf[fZfWfGg*,Q_=qR]R^?_1#%	H#8a@J J&&r"   )cloneset_model_sampler_cfg_functionr   
NodeOutput)r   r
   r   r   rE   ms    ```  r   executeRenormCFG.execute   s3    "	'H KKM	((9}}Qr"    N)
__name__
__module____qualname____firstlineno__classmethodr    r   rI   rK   __static_attributes__rM   r"   r   r   r      s3    
 
 ' bmm '  ' r"   r   c                   ^    \ rS rSrSSS.rSr\S 5       r\S\R                  4S j5       r
S	rg
)CLIPTextEncodeLumina2B   zYou are an assistant designed to generate superior images with the superior degree of image-text alignment based on textual prompts or user prompts.zYou are an assistant designed to generate high-quality images with the highest degree of image-text alignment based on textual prompts.)superior	alignmenta]  Lumina2 provide two types of system prompts:Superior: You are an assistant designed to generate superior images with the superior degree of image-text alignment based on textual prompts or user prompts. Alignment: You are an assistant designed to generate high-quality images with the highest degree of image-text alignment based on textual prompts.c                 z   [         R                  " SS/SSS[         R                  R                  S[	        U R
                  R                  5       5      U R                  S9[         R                  R                  SS	S	S
S9[         R                  R                  SSS9/[         R                  R                  SS9/S9$ )NrU   zlumina promptzCLIP Text Encode (Lumina 2)zmodel/conditioning/luminazEncodes a system prompt and a user prompt using a CLIP model into an embedding that can be used to guide the diffusion model towards generating specific images.system_prompt)optionstooltipuser_promptTzThe text to be encoded.)	multilinedynamic_promptsr\   clipz*The CLIP model used for encoding the text.)r\   zNA conditioning containing the embedded text used to guide the diffusion model.)r   search_aliasesdisplay_namer   descriptionr   r   )r   r   Combor   listSYSTEM_PROMPTkeysSYSTEM_PROMPT_TIPStringClipConditioningr   r   s    r   r    #CLIPTextEncodeLumina2.define_schemaN   s    yy++,60l # !2!2!7!7!9:11  
 		!"$(5	    f.Z[ &&l ' +
 	
r"   r#   c                     Uc  [        S5      eU R                  U   nU SU 3nUR                  U5      n[        R                  " UR                  U5      5      $ )NzERROR: clip input is invalid: None

If the clip is from a checkpoint loader node your checkpoint does not contain a valid clip or text encoder model.z <Prompt Start> )RuntimeErrorrf   tokenizer   rI   encode_from_tokens_scheduled)r   r`   r]   rZ   prompttokenss         r   rK   CLIPTextEncodeLumina2.executel   se    <   y  z  z))-8!?"2;-@v&}}T>>vFGGr"   rM   N)rN   rO   rP   rQ   rf   rh   rR   r    r   rI   rK   rS   rM   r"   r   rU   rU   B   sT    WOMC
 
 
: H"-- H Hr"   rU   c                   L    \ rS rSr\S\\\R                        4S j5       r	Sr
g)Lumina2Extensionv   r#   c                 "   #    [         [        /$ 7fN)rU   r   )selfs    r   get_node_listLumina2Extension.get_node_listw   s      "
 	
s   rM   N)rN   rO   rP   rQ   r   re   typer   	ComfyNoderz   rS   rM   r"   r   ru   ru   v   s)    
T$r||*<%= 
 
r"   ru   r#   c                     #    [        5       $ 7frx   )ru   rM   r"   r   comfy_entrypointr      s     s   )typing_extensionsr   r1   comfy_api.latestr   r   r}   r   rU   ru   r   rM   r"   r   <module>r      sK    &  /8  8 v1HBLL 1Hh
~ 
 0 r"   