
    +j
                        S SK Jr  S SKrS SKrS SKJr  S SKJrJ	r	J
r
  \(       a  S SKJr  S SKJr  SrSrSS	 jrSSS
SS/4     SS jjrg)    )annotationsN)
WrappersMP)TYPE_CHECKINGCallableOptional)ModelPatcher)WrapperExecutorztorch.compiletorch_compile_kwargsc                   ^  SU 4S jjnU$ )zC
Create a wrapper that will refer to the compiled_diffusion_model.
c                  >  0 nTR                  5        H[  u  pE[        R                  R                  U R                  U5      X4'   [        R                  R                  U R                  XE5        M]     U " U0 UD6UR                  5        H/  u  pE[        R                  R                  U R                  XE5        M1     $ ! WR                  5        H/  u  pE[        R                  R                  U R                  XE5        M1     f = f)N)itemscomfyutilsget_attr	class_objset_attr)executorargskwargsorig_moduleskeyvaluecompiled_module_dicts         E/home/wildlama/comfy/ComfyUI/comfy_api/torch_helpers/torch_compile.pyapply_torch_compile_wrapper@apply_torch_compile_factory.<locals>.apply_torch_compile_wrapper   s    	EL288:
$)KK$8$89K9KS$Q!$$X%7%7D ; T,V,*002
$$X%7%7D 3l002
$$X%7%7D 3s   A8B? ?AD)r   r	    )r   r   s   ` r   apply_torch_compile_factoryr      s    	E '&    Fdiffusion_modelc                X   U R                  [        R                  [        5        U(       d  S/nUUUUUS.n	0 n
U H,  n[        R
                  " SSU R                  U5      0U	D6X'   M.     [        U
S9nU R                  [        R                  [        U5        XR                  [        '   g)aH  
Perform torch.compile that will be applied at sample time for either the whole model or specific params of the BaseModel instance.

When keys is None, it will default to using ["diffusion_model"], compiling the whole diffusion_model.
When a list of keys is provided, it will perform torch.compile on only the selected modules.
r    )backendoptionsmode	fullgraphdynamicmodel)r   Nr   )remove_wrappers_with_keyr   APPLY_MODELCOMPILE_KEYtorchcompileget_model_objectr   add_wrapper_with_keymodel_optionsTORCH_COMPILE_KWARGS)r'   r"   r#   r$   r%   r&   keysr   r   compile_kwargscompiled_modulesr   wrapper_funcs                r   set_torch_compile_wrapperr5   !   s     
"":#9#9;G!" N  % !,,S1! !  /-L 
z55{LQ0>,-r   )r   zdict[str, Callable]returnr   )r'   r   r"   strr#   zOptional[dict[str, str]]r$   zOptional[str]r&   zOptional[bool]r1   z	list[str])
__future__r   r+   comfy.utilsr   comfy.patcher_extensionr   typingr   r   r   comfy.model_patcherr   r	   r*   r0   r   r5   r   r   r   <module>r=      sd    "   . 4 407 - '" cg26%ae/@.A$?$1$?R`$?$-$?r   