o
    i                     @  sd  d dl mZ d dlmZmZ d dlZd dlZd dlZd dlZ	d dl
Z
d dlZer<d dlmZmZ d dlmZ d dlmZ d dlZd dlZd dlZd dlmZ G dd	 d	ejZG d
d dejZG dd dejZG dd dejZG dd dZdrddZdsdtd d!Z G d"d dZ!G d#d$ d$e!Z"G d%d& d&e!Z#G d'd( d(e!Z$G d)d* d*e!Z%e%Z&	 G d+d, d,e!Z'G d-d dZ(G d.d/ d/Z)G d0d1 d1Z*G d2d3 d3Z+dud8d9Z,dsdvd<d=Z-dwdCdDZ.dxdEdFZ/dydzdHdIZ0d{dLdMZ1d|dSdTZ2i dGdfd}dUdVZ3d~ddWdXZ4dd[d\Z5ddadbZ6ddddeZ7ddgdhZ8	GdddjdkZ9	m	GdddndoZ:	GdddpdqZ;dS )    )annotations)TYPE_CHECKINGCallableN)ModelPatcherPatcherInjection)	BaseModel)CLIPconditioning_set_valuesc                   @     e Zd ZdZdZdZdS )EnumHookModea(  
    Priority of hook memory optimization vs. speed, mostly related to WeightHooks.

    MinVram: No caching will occur for any operations related to hooks.
    MaxSpeed: Excess VRAM (and RAM, once VRAM is sufficiently depleted) will be used to cache hook weights when switching hook groups.
    minvrammaxspeedN)__name__
__module____qualname____doc__MinVramMaxSpeed r   r   )/mnt/c/Users/fbmor/ComfyUI/comfy/hooks.pyr          r   c                   @  s$   e Zd ZdZdZdZdZdZdZdS )EnumHookTypezD
    Hook types, each of which has different expected behavior.
    weightobject_patch
add_modelstransformer_optionsadd_injectionsN)	r   r   r   r   WeightObjectPatchAdditionalModelsTransformerOptions
Injectionsr   r   r   r   r   '   s    r   c                   @  s   e Zd ZdZdZdS )EnumWeightTargetmodelclipN)r   r   r   ModelClipr   r   r   r   r#   1   s    r#   c                   @  r   )EnumHookScopez
    Determines if hook should be limited in its influence over sampling.

    AllConditioning: hook will affect all conds used in sampling.
    HookedOnly: hook will only affect the conds it was attached to.
    all_conditioninghooked_onlyN)r   r   r   r   AllConditioning
HookedOnlyr   r   r   r   r(   5   r   r(   c                   @  s   e Zd ZdS )_HookRefN)r   r   r   r   r   r   r   r-   @   s    r-   hookHookr$   r   model_optionsdicttarget_dict	dict[str]
registered	HookGroupc                 C  s   dS )z>Example for how custom_should_register function can look like.Tr   )r.   r$   r0   r2   r4   r   r   r   default_should_registerD   s   r6   targetreturnc                 K  s"   i }| dur
| |d< | | |S )z9Creates base dictionary for use with Hooks' target param.Nr7   )update)r7   kwargsdr   r   r   create_target_dictI   s
   
r<   c                   @  sp   e Zd Zddddejfd&d
dZedd Zd'ddZdd Z	dd Z
d(ddZd(dd Zd)d"d#Zd$d% ZdS )*r/   N	hook_typer   hook_refr-   hook_idstrhook_keyframeHookKeyframeGroupc                 C  sF   || _ 	 |r|nt | _	 || _	 |r|nt | _	 || _	 t| _d S N)	r=   r-   r>   r?   rB   rA   
hook_scoper6   custom_should_register)selfr=   r>   r?   rA   rD   r   r   r   __init__S   s   zHook.__init__c                 C  s   | j jS rC   )rA   strengthrF   r   r   r   rH   b   s   zHook.strengthr$   r   c                 C  s   |    | j| d S rC   )resetrA   initialize_timesteps)rF   r$   r   r   r   rK   f   s   zHook.initialize_timestepsc                 C  s   | j   d S rC   )rA   rJ   rI   r   r   r   rJ   j      z
Hook.resetc                 C  s<   |   }| j|_| j|_| j|_| j|_| j|_| j|_|S rC   )	__class__r=   r>   r?   rA   rD   rE   rF   cr   r   r   clonem   s   z
Hook.cloner   r0   r1   r2   r3   r4   r5   c                 C  s   |  | ||||S rC   )rE   rF   r$   r0   r2   r4   r   r   r   should_registerw   s   zHook.should_registerc                 C     t d)Nz6add_hook_patches should be defined for Hook subclassesNotImplementedErrorrQ   r   r   r   add_hook_patchesz      zHook.add_hook_patchesotherc                 C  s   | j |j ko| j|jkS rC   )rM   r>   )rF   rX   r   r   r   __eq__}   s   zHook.__eq__c                 C  
   t | jS rC   )hashr>   rI   r   r   r   __hash__      
zHook.__hash__)r=   r   r>   r-   r?   r@   rA   rB   r$   r   r$   r   r0   r1   r2   r3   r4   r5   )rX   r/   )r   r   r   r(   r+   rG   propertyrH   rK   rJ   rP   rR   rV   rY   r\   r   r   r   r   r/   R   s    





c                      sP   e Zd ZdZd fdd	Zedd Zedd ZdddZ fddZ	  Z
S )
WeightHookz
    Hook responsible for tracking weights to be applied to some model/clip.

    Note, value of hook_scope is ignored and is treated as HookedOnly.
          ?c                   s>   t  jtjtjd d | _d | _d| _|| _	|| _
tj| _d S )N)r=   rD   T)superrG   r   r   r(   r,   weightsweights_clipneed_weight_init_strength_model_strength_cliprD   )rF   strength_modelstrength_cliprM   r   r   rG      s   zWeightHook.__init__c                 C     | j | j S rC   )rg   rH   rI   r   r   r   ri         zWeightHook.strength_modelc                 C  rl   rC   )rh   rH   rI   r   r   r   rj      rm   zWeightHook.strength_clipr$   r   r0   r1   r2   r3   r4   r5   c           	      C  s   |  ||||s
dS d }|dd }|tjkr| j}n| j}| jrDi }|tjkr1tj	|j
|}ntj|j
|}tjj| j|dd}n|tjkrM| j}n| j}|j| ||d ||  dS )NFr7   )log_missingr.   patchesstrength_patchT)rR   getr#   r'   rh   rg   rf   comfyloramodel_lora_keys_clipr$   model_lora_keys_unet	load_lorard   re   rV   add)	rF   r$   r0   r2   r4   rd   r7   rH   key_mapr   r   r   rV      s&   



zWeightHook.add_hook_patchesc                   s6   t   }| j|_| j|_| j|_| j|_| j|_|S rC   )rc   rP   rd   re   rf   rg   rh   rN   rk   r   r   rP      s   
zWeightHook.clone)rb   rb   r_   )r   r   r   r   rG   r`   ri   rj   rV   rP   __classcell__r   r   rk   r   ra      s    	


ra   c                      s<   e Zd Zdejfd fddZ fddZdddZ  ZS )ObjectPatchHookNobject_patchesr3   c                       t  jtjd || _|| _d S Nr=   )rc   rG   r   r   r|   rD   )rF   r|   rD   rk   r   r   rG      s   
zObjectPatchHook.__init__c                   s   t   }| j|_|S rC   )rc   rP   r|   rN   rk   r   r   rP      s   
zObjectPatchHook.cloner$   r   r0   r1   r2   r4   r5   c                 C  rS   )Nz0ObjectPatchHook is not supported yet in ComfyUI.rT   rQ   r   r   r   rV      rW   z ObjectPatchHook.add_hook_patches)r|   r3   r_   	r   r   r   r(   r+   rG   rP   rV   rz   r   r   rk   r   r{      s    r{   c                      s:   e Zd ZdZdd fddZ fd	d
ZdddZ  ZS )AdditionalModelsHookz
    Hook responsible for telling model management any additional models that should be loaded.

    Note, value of hook_scope is ignored and is treated as AllConditioning.
    Nmodelslist[ModelPatcher]keyr@   c                   r}   r~   )rc   rG   r   r    r   r   )rF   r   r   rk   r   r   rG      s   
zAdditionalModelsHook.__init__c                   s.   t   }| jr| j n| j|_| j|_|S rC   )rc   rP   r   copyr   rN   rk   r   r   rP      s   
zAdditionalModelsHook.cloner$   r   r0   r1   r2   r3   r4   r5   c                 C  s"   |  ||||s
dS ||  dS )NFT)rR   rx   rQ   r   r   r   rV      s   
z%AdditionalModelsHook.add_hook_patches)NN)r   r   r   r@   r_   )r   r   r   r   rG   rP   rV   rz   r   r   rk   r   r      s
    r   c                      sJ   e Zd ZdZdejfd fddZ fddZdddZdddZ	  Z
S )TransformerOptionsHookzt
    Hook responsible for adding wrappers, callbacks, patches, or anything else related to transformer_options.
    Ntransformers_dict/dict[str, dict[str, dict[str, list[Callable]]]]c                   s&   t  jtjd || _|| _d| _d S )Nr   F)rc   rG   r   r!   r   rD   _skip_adding)rF   r   rD   rk   r   r   rG      s
   zTransformerOptionsHook.__init__c                   s   t   }| j|_| j|_|S rC   )rc   rP   r   r   rN   rk   r   r   rP      s   
zTransformerOptionsHook.cloner$   r   r0   r1   r2   r3   r4   r5   c                 C  sf   |  ||||s
dS d| _| jtjkr| j| jd}d| _nd| ji}||  tjj	||dd dS )NF)r   to_load_optionsTr   
copy_dict1)
rR   r   rD   r(   r+   r   rx   rs   patcher_extensionmerge_nested_dicts)rF   r$   r0   r2   r4   add_model_optionsr   r   r   rV      s   

z'TransformerOptionsHook.add_hook_patchesr   c                 C  s"   | j stjj|| jdd d S d S )NFr   )r   rs   r   r   r   )rF   r$   r   r   r   r   on_apply_hooks  s   z%TransformerOptionsHook.on_apply_hooks)r   r   r_   )r$   r   r   r3   )r   r   r   r   r(   r+   rG   rP   rV   r   rz   r   r   rk   r   r      s    
r   c                      s>   e Zd Zddejfd fddZ fdd	ZdddZ  ZS )InjectionsHookNr   r@   
injectionslist[PatcherInjection]c                   s&   t  jtjd || _|| _|| _d S r~   )rc   rG   r   r"   r   r   rD   )rF   r   r   rD   rk   r   r   rG     s   
zInjectionsHook.__init__c                   s4   t   }| j|_| jr| j |_|S | j|_|S rC   )rc   rP   r   r   r   rN   rk   r   r   rP     s   
zInjectionsHook.cloner$   r   r0   r1   r2   r3   r4   r5   c                 C  rS   )Nz/InjectionsHook is not supported yet in ComfyUI.rT   rQ   r   r   r   rV     rW   zInjectionsHook.add_hook_patches)r   r@   r   r   r_   r   r   r   rk   r   r     s    r   c                   @  s   e Zd ZdZdd Zdd Zd*dd	Zd*d
dZd+ddZd*ddZ	d,ddZ
d,ddZdd Zd,ddZd-ddZdd  Zd!d" Zed.d/d'd(Zd)S )0r5   z
    Stores groups of hooks, and allows them to be queried by type.

    To prevent breaking their functionality, never modify the underlying self.hooks or self._hook_dict vars directly;
    always use the provided functions on HookGroup.
    c                 C  s   g | _ i | _d S rC   )hooks
_hook_dictrI   r   r   r   rG   &  s   
zHookGroup.__init__c                 C  rZ   rC   )lenr   rI   r   r   r   __len__*  r]   zHookGroup.__len__r.   r/   c                 C  s4   || j vr| j | | j|jg | d S d S rC   )r   appendr   
setdefaultr=   rF   r.   r   r   r   rx   -  s   
zHookGroup.addc                 C  s0   || j v r| j | | j|j | d S d S rC   )r   remover   r=   r   r   r   r   r   2  s   
zHookGroup.remover=   r   c                 C  s   | j |g S rC   )r   rr   )rF   r=   r   r   r   get_type7  rL   zHookGroup.get_typec                 C  s
   || j v S rC   )r   r   r   r   r   contains:  r]   zHookGroup.containsrX   c                 C  s   t | j}t |j}||S rC   )setr   issubset)rF   rX   
self_hooksother_hooksr   r   r   is_subset_of=  s   


zHookGroup.is_subset_ofc                 C  s.   t  }| jD ]}||r||  q|S rC   )r5   r   r   rx   rP   rF   rX   rO   r.   r   r   r   new_with_common_hooksB  s   

zHookGroup.new_with_common_hooksc                 C  s$   t  }| jD ]	}||  q|S rC   )r5   r   rx   rP   )rF   rO   r.   r   r   r   rP   I  s   
zHookGroup.clonec                 C  s.   |   }|d ur|jD ]	}||   q|S rC   )rP   r   rx   r   r   r   r   clone_and_combineO  s
   
zHookGroup.clone_and_combinehook_kfrB   c                 C  s.   |d u rt  }n| }| jD ]}||_qd S rC   )rB   rP   r   rA   )rF   r   r.   r   r   r   set_keyframes_on_hooksV  s   
z HookGroup.set_keyframes_on_hooksc                   s  i }|  tjD ]\}g }t|jjdkr|d |||< q|jjd }|jjD ]&}|j|jkrFt	|j
|j
sF||j|jf|f |}q(|j|jkrN|}q(t	|jds`||jdf|f |||< qg }| D ]}|D ]	\}}|| qoqkttj|}	|	d t|	  fddtt d D }
g }|
D ]8}g }| D ](\}}d }|D ]\}}|d |d k r|d |d kr|} nq|||f q|||f q|S )Nr   ))        rb   Nrb   r   c                   s    g | ]} |  |d   fqS )   r   ).0i
boundariesr   r   
<listcomp>~  s     z9HookGroup.get_hooks_for_clip_schedule.<locals>.<listcomp>r   )r   r   r   r   rA   	keyframesr   start_percentmathiscloserH   valuesr   	itertoolschainfrom_iterablerx   sortedrangeitems)rF   scheduled_hooksr.   hook_scheduleprev_keyframekeyframe
all_ranges	range_kfst_rangeboundaries_setreal_rangesscheduled_keyframeshooks_schedulevalstored_range	stored_kfr   r   r   get_hooks_for_clip_schedule^  sP   


 z%HookGroup.get_hooks_for_clip_schedulec                 C  s   | j D ]}|  qd S rC   )r   rJ   r   r   r   r   rJ     s   

zHookGroup.resetr   
hooks_listlist[HookGroup]r8   c                 C  s   g }| D ]}|d ur| | qt||k r#td| dt| dt|dkr+d S t|dkr5|d S d }|D ]}|d u rD| }q9||}q9|S )NzNeed at least z  hooks to combine, but only had .r   r   )r   r   	ExceptionrP   r   )r   require_countactualgroup
final_hookr.   r   r   r   combine_all_hooks  s"   

zHookGroup.combine_all_hooksN)r.   r/   )r=   r   )rX   r5   )r   rB   r   )r   r   r8   r5   )r   r   r   r   rG   r   rx   r   r   r   r   r   rP   r   r   r   rJ   staticmethodr   r   r   r   r   r5     s"    







1c                   @  s*   e Zd ZddddZdd	d
Zdd ZdS )HookKeyframer   r   rH   floatc                 C  s    || _ t|| _d| _|| _d S )Ng33dA)rH   r   r   start_tguarantee_steps)rF   rH   r   r   r   r   r   rG     s   

zHookKeyframe.__init__	max_sigmatorch.Tensorc                 C  s   | j |krdS | jS )zIIf keyframe starts before current sampling range (max_sigma), treat as 0.r   )r   r   )rF   r   r   r   r   get_effective_guarantee_steps  s   
z*HookKeyframe.get_effective_guarantee_stepsc                 C  s    t | j| j| jd}| j|_|S )N)rH   r   r   )r   rH   r   r   r   rN   r   r   r   rP     s
   zHookKeyframe.cloneN)r   r   )rH   r   )r   r   )r   r   r   rG   r   rP   r   r   r   r   r     s    
r   c                   @  sp   e Zd Zdd Zedd Zdd Zd$d	d
Zdd Zdd Z	d%ddZ
dd Zdd Zd&ddZd'd!d"Zd#S )(rB   c                 C  s(   g | _ d | _d| _d| _d | _d| _d S Nr   g      )r   _current_keyframe_current_used_steps_current_index_current_strength_curr_trI   r   r   r   rG     s   
zHookKeyframeGroup.__init__c                 C  s   | j d ur	| j jS dS )Nrb   )r   rH   rI   r   r   r   rH     s   
zHookKeyframeGroup.strengthc                 C  s*   d | _ d| _d| _d | _d| _|   d S r   )r   r   r   r   curr_t_set_first_as_currentrI   r   r   r   rJ     s   zHookKeyframeGroup.resetr   r   c                 C  s&   | j | t| j d| _ |   d S )Nr   )r   r   get_sorted_list_via_attrr   )rF   r   r   r   r   rx     s   zHookKeyframeGroup.addc                 C  s(   t | jdkr| jd | _d S d | _d S Nr   )r   r   r   rI   r   r   r   r     s   
z'HookKeyframeGroup._set_first_as_currentc                 C  s    | j D ]
}|jdkr dS qdS )Nr   TF)r   r   )rF   kfr   r   r   has_guarantee_steps  s
   

z%HookKeyframeGroup.has_guarantee_stepsindexintc                 C  s   |dko
|t | jk S r   r   r   )rF   r   r   r   r   	has_index  s   zHookKeyframeGroup.has_indexc                 C  s   t | jdkS r   r   rI   r   r   r   is_empty  rL   zHookKeyframeGroup.is_emptyc                 C  s.   t  }| jD ]
}|j|  q|  |S rC   )rB   r   r   rP   r   )rF   rO   r   r   r   r   rP     s
   
zHookKeyframeGroup.cloner$   r   c                 C  s    | j D ]
}|j|j|_qd S rC   )r   model_samplingpercent_to_sigmar   r   )rF   r$   r   r   r   r   rK     s   
z&HookKeyframeGroup.initialize_timestepsr   r   r   dict[str, torch.Tensor]r8   boolc                 C  s   |   rdS || jkrdS t|d }| j}| j}| j| j|kr[| 	| jd r[t
| jd t| jD ]$}| j| }|j|krZ|| _|j| _|| _d| _| j|dkrY nq6 |  jd7  _|| _|| jkon|| jkS )NFsample_sigmasr   r   )r   r   torchmaxr   r   r   r   r   r   r   r   r   r   rH   )rF   r   r   r   
prev_indexprev_strengthr   eval_cr   r   r   prepare_current_keyframe  s.   


z*HookKeyframeGroup.prepare_current_keyframeN)r   r   )r   r   r^   )r   r   r   r   r8   r   )r   r   r   rG   r`   rH   rJ   rx   r   r   r   r   rP   rK   r   r   r   r   r   rB     s    	



rB   c                   @  s8   e Zd ZdZdZdZdZeeeegZeddddZ	dS )InterpolationMethodlinearease_inease_outease_in_outFnum_fromr   num_tolengthr   methodr@   c           	      C  s   || }|| j krt|||}nW|| jkr(tdd|}|t|d | }n@|| jkrCtdd|}|dtd| d  | }n%|| jkr`tdd|}|dt|tj	  d  | }nt
d| d|rp|jdd}|S )Nr   r      z#Unrecognized interpolation method 'z'.r   )dims)LINEARr   linspaceEASE_INnppowerEASE_OUTEASE_IN_OUTcospi
ValueErrorflip)	clsr   r   r   r   reversediffrd   r   r   r   r   get_weights$  s    



"zInterpolationMethod.get_weightsN)F)r   r   r   r   r   r   r   r@   )
r   r   r   r  r  r  r  _LISTclassmethodr  r   r   r   r   r     s    r   objectslistattrr@   c           	      C  s   | s| S t | dkrdd | D S i }| D ]}t||}||t }|| ||vr0|||< qtt| }g }| D ]}|	| q?|S )Nr   c                 S  s   g | ]}|qS r   r   )r   xr   r   r   r   <  s    z,get_sorted_list_via_attr.<locals>.<listcomp>)
r   getattrrr   r  r   r1   r   r   r   extend)	r  r  unique_attrsoval_attr	attr_listsorted_attrssorted_listobject_listr   r   r   r   8  s"   

r   r   r   c                 C  s@   |d u s| j r	i S |d u ri }|tjD ]}|| | q|S rC   )is_clipr   r   r!   r   )r$   r   r   r.   r   r   r   %create_transformer_options_from_hooksO  s   r!  rt   r   ri   r   rj   c                 C  s&   t  }t||d}|| | |_|S )Nri   rj   )r5   ra   rx   rd   )rt   ri   rj   
hook_groupr.   r   r   r   create_hook_loraZ  s
   
r$  c           	      C  s   t  }t||d}|| d }d }| d ur&i }| D ]}d| | ff||< q|d ur:i }|D ]}d|| ff||< q.||_||_d|_|S )Nr"  model_as_loraF)r5   ra   rx   rd   re   rf   )	weights_modelre   ri   rj   r#  r.   patches_modelpatches_clipr   r   r   r   create_hook_model_as_loraa  s"   
r)  Tc                 C  sF   | d u rd S | j  }|r!t| D ]}|dr ||d  q|S )Nr   )r$   
state_dictr  keys
startswithpop)r$   discard_model_samplingr'  r   r   r   r   get_patch_weights_from_modelt  s   

r/  r%   r   c                 C  s   i }| d urt j| j|}|d urt j|j|}t }t }|| t j	||}| d ur=| 
 }	|	j|||d}
nd}
d }	|d urS|
 }|jj|||d}nd}d }t|
}
t|}|D ]}||
vrs||vrstd|  qa|	||fS )Nro   r   zNOT LOADED )rs   rt   rv   r$   ru   cond_stage_modelr5   ra   rx   rw   rP   rV   patcherr   loggingwarning)r$   r%   rt   ri   rj   ry   r#  r.   loadednew_modelpatcherknew_clipk1r  r   r   r   load_hook_lora_for_models  s4   

r9  c_dictdict[str, HookGroup]r   cache,dict[tuple[HookGroup, HookGroup], HookGroup]c                 C  s   d}||vrd S || vr| |d }|d ur|| |< d S | | || f}| |d }|d u rA|d |d }|||< || |< d S || | |< d S )Nr   r   r   )rr   r   )r:  r   r<  	hooks_keyhooks_valuehooks_tuplecached_hooks	new_hooksr   r   r   _combine_hooks_from_values  s   rC  c                 C  st   g }|d u ri }| D ]-}|d |d   g}|D ]}|r)|dkr)t|d || q|| |d |< q|| q
|S )Nr   r   r   )r   rC  r   )conditioningr   append_hooksr<  rO   tnr6  r   r   r   "conditioning_set_values_with_hooks  s   rH  c                 C  s    |d u r| S t | d|i||dS )Nr   rE  r<  )rH  )condr   rE  r<  r   r   r   set_hooks_for_conditioning  s   rK  timestep_rangetuple[float, float]c                 C  s$   |d u r| S t | |d |d dS )Nr   r   )r   end_percentr	   rJ  rL  r   r   r   set_timesteps_for_conditioning  s
   
rP  maskr   set_cond_arearH   c                 C  sF   |d u r| S d}|dkrd}t |jdk r|d}t| |||dS )NFdefaultT   r   )rQ  set_area_to_boundsmask_strength)r   shape	unsqueezer
   )rJ  rQ  rR  rH   rU  r   r   r   set_mask_for_conditioning  s   
rY  condsc                 C  s   g }| D ]}| | q|S rC   )r  )rZ  combined_condsrJ  r   r   r   combine_conditioning  s   r\  	new_condsc                 C  s.   g }t | |D ]\}}|t||g q|S rC   )zipr   r\  )rZ  r]  r[  rO   new_cr   r   r   combine_with_new_conds  s   r`  timesteps_rangec           
      C  sL   g }i }| D ]}	t |	|||d}	t|	|||d}	t|	|d}	||	 q|S )NrI  )rJ  rQ  rH   rR  rO  )rK  rY  rP  r   )
rZ  rH   rR  rQ  r   ra  rE  final_condsr<  rO   r   r   r   set_conds_props  s   rc  rb   rS  c                 C  s^   g }i }	t | |D ]#\}
}t||||	d}t||||d}t||d}|t|
|g q	|S )NrI  )rJ  rQ  rR  rH   rO  )r^  rK  rY  rP  r   r\  )rZ  r]  rH   rR  rQ  r   ra  rE  r[  r<  rO   masked_cr   r   r   set_conds_props_and_combine  s   re  c           	      C  s\   g }i }t | |D ]"\}}t||||d}t|ddi}t||d}|t||g q	|S )NrI  rS  TrO  )r^  rK  r
   rP  r   r\  )	rZ  r]  r   ra  rE  r[  r<  rO   r_  r   r   r   set_default_conds_and_combine  s   rf  )
r.   r/   r$   r   r0   r1   r2   r3   r4   r5   rC   )r7   r#   r8   r3   )r  r  r  r@   r8   r  )r$   r   r   r5   r   r3   )rt   r   ri   r   rj   r   )ri   r   rj   r   )T)r$   r   )
r$   r   r%   r   rt   r   ri   r   rj   r   )r:  r;  r   r;  r<  r=  )r<  r=  )TN)r   r5   r<  r=  )rL  rM  )rQ  r   rR  r@   rH   r   )rZ  r  )rZ  r  r]  r  )NNNT)rZ  r  rH   r   rR  r@   rQ  r   r   r5   ra  rM  )rb   rS  NNNT)rZ  r  r]  r  rH   r   rR  r@   rQ  r   r   r5   ra  rM  )NNT)rZ  r  r]  r  r   r5   ra  rM  )<
__future__r   typingr   r   enumr   r   numpyr  r   r2  comfy.model_patcherr   r   comfy.model_baser   comfy.sdr   
comfy.lorars   comfy.model_managementcomfy.patcher_extensionnode_helpersr
   Enumr   r   r#   r(   r-   r6   r<   r/   ra   r{   r   r   WrapperHookr   r5   r   rB   r   r   r!  r$  r)  r/  r9  rC  rH  rK  rP  rY  r\  r`  rc  re  rf  r   r   r   r   <module>   st    


	1<& ^




 



