o
    ٷik                     @   s   d dl Z d dlZd dlmZmZmZ ddlmZ d dlm	Z	 e	e
ZejG dd dZejG dd	 d	ZejG d
d deZdS )    N)OptionalUnionList   )	CacheType)init_loggerc                   @   s  e Zd ZU ejZeed< dZeed< dZ	eed< dZ
eejef ed< dZee ed	< dZeed
< dZeed< dZeed< dZeed< dZee ed< dZeed< dZeed< dZee ed< dZeee  ed< dZeed< d$ddZd$ddZd$ddZ de!fd d!Z"defd"d#Z#dS )%BasicCacheConfig
cache_type   Fn_compute_blocksr   Bn_compute_blocksg{Gz?residual_diff_thresholdN'max_accumulated_residual_diff_thresholdmax_warmup_steps   warmup_intervalmax_cached_stepsmax_continuous_cached_stepsenable_separate_cfgFcfg_compute_firstTcfg_diff_compute_separatenum_inference_stepssteps_computation_maskdynamicsteps_computation_policyreturnc                 K   s4   |  D ]\}}t| |r|d urt| || q| S N)itemshasattrsetattr)selfkwargskeyvalue r%   a/home/ubuntu/.local/lib/python3.10/site-packages/cache_dit/caching/cache_contexts/cache_config.pyupdateR   s   
zBasicCacheConfig.updatec                 K   sB   t | D ]}t| |jrt| |jd  q|r| jdi | | S Nr%   )dataclassesfieldsr   namer    r'   )r!   r"   fieldr%   r%   r&   emptyY   s   zBasicCacheConfig.emptyc                 K   s   | j di |S r(   )r-   )r!   r"   r%   r%   r&   resetb   s   zBasicCacheConfig.resetc                 C   s
   t | S r   )r)   asdict)r!   r%   r%   r&   as_dicte   s   
zBasicCacheConfig.as_dictc                 C   s   | j  d| j d| j d| j d| j dtd| j dtd| j d| j }| j	d urB|d	d

tt| j	 7 }|d| j 7 }| jd urO|d| j 7 }| jd ur^|dt| j 7 }|S )N_FB_WIMr   MC_R_SCM __N_CFG)r	   r   r   r   r   maxr   r   r   r   joinmapstrr   r   r   int)r!   base_strr%   r%   r&   strifyh   s0   




zBasicCacheConfig.strify)r   r   )$__name__
__module____qualname__r   DBCacher	   __annotations__r   rA   r   r   r   torchTensorfloatr   r   r   r   r   r   r   boolr   r   r   r   r   r   r@   r'   r-   r.   dictr0   rC   r%   r%   r%   r&   r   
   s*   
 


	r   c                   @   s2   e Zd ZU dZeed< dZeed< dZeed< dS )ExtraCacheConfigNl1_hidden_states_diff_thresholdg        important_condition_thresholdr   downsample_factor)	rD   rE   rF   rO   rK   rH   rP   rQ   rA   r%   r%   r%   r&   rN      s   
 	rN   c                   @   s   e Zd ZdS )DBCacheConfigN)rD   rE   rF   r%   r%   r%   r&   rR      s    rR   )rI   r)   typingr   r   r   cache_typesr   cache_dit.loggerr   rD   logger	dataclassr   rN   rR   r%   r%   r%   r&   <module>   s    v