§
    ŠŠtjç9  ã            
      ó>  — d dl mZ d dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZmZmZmZ d dlmZmZmZ d dlmZ erd dlm Z m!Z!  ede"e#e$edf         ¦  «        Z% ede"e#e$edf         e&e'eef         e(e         ¦  «        Z) G d„ de*¦  «        Z+ G d„ deee%e)f         ¦  «        Z, G d„ de,e%e)f         ¦  «        Z- G d„ de,e%e)f         ¦  «        Z. G d„ de.e%e)f         ¦  «        Z/ G d„ de/e%e)f         ¦  «        Z0dS )é    )ÚannotationsN)ÚABCÚabstractmethod)Úliteral_eval)Úcached_property)Úsha256)Úgetenv)ÚPath)Ú
gettempdir)ÚLock)ÚAnyÚGenericÚTYPE_CHECKINGÚTypeVar)Úassert_neverÚoverrideÚSelf)ÚFileLock)ÚFutureÚThreadPoolExecutorÚKey.ÚValuec                  ó   — e Zd ZdZdS )Ú
CacheErrorzJ
    Exception raised for errors encountered during cache operations.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úS/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/_inductor/cache.pyr   r      s   € € € € € ðð ð ð r    r   c                  óB   — e Zd ZdZedd„¦   «         Zedd„¦   «         ZdS )ÚCachezi
    Abstract base class for cache implementations.
    Provides the interface for cache operations.
    Úselfr   Úkeyr   ÚreturnúValue | Nonec                ó   — dS ©z¾
        Retrieve a value from the cache.
        Args:
            key (Key): The key to look up.
        Returns:
            Value | None: The cached value if present, else None.
        Nr   )r$   r%   s     r!   Úgetz	Cache.get*   ó   € € € r    Úvaluer   Úboolc                ó   — dS )á  
        Insert a value into the cache.
        Args:
            key (Key): The key to insert.
            value (Value): The value to associate with the key.
        Returns:
            bool: True if the value was inserted, False if the key already exists.
        Nr   ©r$   r%   r,   s      r!   ÚinsertzCache.insert4   r+   r    N©r$   r   r%   r   r&   r'   ©r$   r   r%   r   r,   r   r&   r-   )r   r   r   r   r   r*   r1   r   r    r!   r#   r#   $   s^   € € € € € ðð ð
 ðð ð ñ „^ðð ðð ð ñ „^ðð ð r    r#   c                  óZ   — e Zd ZdZdd„Zdd
„Zdd„Zedd„¦   «         Zedd„¦   «         Z	dS )ÚInMemoryCachezL
    In-memory cache implementation using a dictionary and thread lock.
    r$   r   r&   ÚNonec                ó:   — i | _         t          ¦   «         | _        dS )z6
        Initialize an empty in-memory cache.
        N)Ú_cacher   Ú_lock©r$   s    r!   Ú__init__zInMemoryCache.__init__E   s   € ð )+ˆŒÝ™6œ6ˆŒ
ˆ
ˆ
r    r%   r   r'   c                óœ   — | j         5  | j                             |¦  «        x}�|cddd¦  «         S 	 ddd¦  «         dS # 1 swxY w Y   dS r)   )r9   r8   r*   r0   s      r!   r*   zInMemoryCache.getL   s¹   € ð ŒZð 	ð 	ØœŸš¨Ñ-Ô-Ð-�Ð:Øð	ð 	ð 	ð 	ñ 	ô 	ð 	ð 	ð ð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	s   ˆA³AÁAÁAr,   r   r-   c                óŠ   — | j         5  || j        v r	 ddd¦  «         dS || j        |<   	 ddd¦  «         dS # 1 swxY w Y   dS )r/   NFT)r9   r8   r0   s      r!   r1   zInMemoryCache.insertY   s¹   € ð ŒZð 	ð 	Ø�d”kÐ!Ð!àð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð  %ˆDŒK˜ÑØð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	s   ˆ8 8¸<¿<Úenv_varÚstrc           
     óD  —  | ¦   «         }t          |¦  «        x}€|S |                     d¦  «        D �]ë}|                     ¦   «         }|sŒ	 |                     dd¦  «        \  }}n)# t          $ r}t	          d|›d|›d�¦  «        |‚d}~ww xY w|                     ¦   «         |                     ¦   «         }}	 t          |¦  «        }n0# t          t          f$ r}t	          d|›d	|›d
�¦  «        |‚d}~ww xY w	 t          |¦  «        }	n0# t          t          f$ r}t	          d|›d	|›d
�¦  «        |‚d}~ww xY w	 t          j        |¦  «        }
n.# t          j	        $ r}t	          d|›d	|›d�¦  «        |‚d}~ww xY w	 t          j        |	¦  «        }n.# t          j	        $ r}t	          d|›d	|›d�¦  «        |‚d}~ww xY w| 
                    |
|¦  «        sE|                     |
¦  «        |k    r,t	          d|
›d|                     |
¦  «        ›d|›d�¦  «        ‚�Œí|S )av  
        Create an in-memory cache from an environment variable.
        Args:
            env_var (str): Name of the environment variable containing cache data.
        Returns:
            InMemoryCache: An instance populated from the environment variable.
        Raises:
            CacheError: If the environment variable is malformed or contains invalid data.
        Nú;ú,é   zMalformed kv_pair z from env_var z!, likely missing comma separator.zMalformed key_bytes_repr z in kv_pair z, encoding is invalid.zMalformed value_bytes_repr z, not un-pickle-able.zMultiple values for key z found, got z and ú.)r	   ÚsplitÚstripÚ
ValueErrorr   r   ÚSyntaxErrorÚpickleÚloadsÚUnpicklingErrorr1   r*   )Úclsr>   ÚcacheÚenv_valÚkv_pairÚkey_bytes_reprÚvalue_bytes_reprÚerrÚ	key_bytesÚvalue_bytesr%   r,   s               r!   Úfrom_env_varzInMemoryCache.from_env_vari   sê  € ð �‘”ˆå˜g‘”Ð&ˆGÐ/àˆLà—}’} SÑ)Ô)ð 9	ñ 9	ˆGà—m’m‘o”oˆGàð àðà3:·=²=ÀÀaÑ3HÔ3HÑ0�Ð 0Ð 0øÝð ð ð Ý Øn¨ÐnÐnÀ'ÐnÐnÐnñô àðøøøøðøøøð ×$Ò$Ñ&Ô&Ø ×&Ò&Ñ(Ô(ð -ˆNð
å(¨Ñ8Ô8�	�	øÝ¥Ð,ð ð ð Ý Øo°ÐoÐoÈgÐoÐoÐoñô àðøøøøðøøøðå*Ð+;Ñ<Ô<��øÝ¥Ð,ð ð ð Ý ØsÐ2BÐsÐsÐRYÐsÐsÐsñô àðøøøøðøøøð
Ý”l 9Ñ-Ô-��øÝÔ)ð ð ð Ý Øn°ÐnÐnÈgÐnÐnÐnñô àðøøøøðøøøðÝœ [Ñ1Ô1��øÝÔ)ð ð ð Ý ØrÐ2BÐrÐrÐRYÐrÐrÐrñô àðøøøøðøøøð —L’L  eÑ,Ô,ð °5·9²9¸S±>´>ÀUÒ3JÐ3JÝ Øc¨sÐcÐcÀ%Ç)Â)ÈCÁ.Ä.ÐcÐcÐY^ÐcÐcÐcñô ð ùð ˆsx   ÁA(Á(
BÁ2B	Â	BÂ:C
Ã
C7ÃC2Ã2C7Ã;DÄD8ÄD3Ä3D8Ä<EÅE<Å E7Å7E<Æ FÆG Æ$F;Æ;G Úfpathr
   c                ó|  —  | ¦   «         }|                      ¦   «         s|S 	 t          |d¦  «        5 }t          j        |¦  «        |_        ddd¦  «         n# 1 swxY w Y   n+# t          j        $ r}t          d|› d�¦  «        |‚d}~ww xY wt          |j        t          ¦  «        st          d|› d�¦  «        ‚|S )a=  
        Create an in-memory cache from a file path.
        Args:
            fpath (Path): Path to the file containing pickled cache data.
        Returns:
            InMemoryCache: An instance populated from the file.
        Raises:
            CacheError: If the file is not a valid pickled dictionary.
        ÚrbNz&Failed to create cache from file path z#, file contents are un-pickle-able.z-, file contents not pickled dict[Key, Value].)	Úis_fileÚopenrI   Úloadr8   rK   r   Ú
isinstanceÚdict)rL   rV   rM   ÚfprR   s        r!   Úfrom_file_pathzInMemoryCache.from_file_path·   s  € ð �‘”ˆà�}Š}‰Œð 	àˆLð	Ý�e˜TÑ"Ô"ð / bÝ%œ{¨2™œ�”ð/ð /ð /ñ /ô /ð /ð /ð /ð /ð /ð /øøøð /ð /ð /ð /øøåÔ%ð 	ð 	ð 	ÝØc¸ÐcÐcÐcñô àðøøøøð	øøøõ
 ˜%œ,­Ñ-Ô-ð 	ÝØm¸ÐmÐmÐmñô ð ð ˆs:   ¢A$ ²AÁA$ ÁAÁA$ ÁAÁ A$ Á$BÁ3BÂBN©r$   r   r&   r6   r2   r3   )r>   r?   r&   r   )rV   r
   r&   r   )
r   r   r   r   r;   r*   r1   ÚclassmethodrU   r_   r   r    r!   r5   r5   @   sŸ   € € € € € ðð ð"ð "ð "ð "ðð ð ð ðð ð ð ð  ðKð Kð Kñ „[ðKðZ ðð ð ñ „[ðð ð r    r5   c                  ó"   — e Zd ZdZdd
„Zdd„ZdS )Ú
AsyncCachezE
    Asynchronous cache implementation using ThreadPoolExecutor.
    r$   r   r%   r   Úexecutorr   r&   úFuture[Value | None]c                ó8   — |                      | j        |¦  «        S )a  
        Retrieve a value from the cache asynchronously.
        Args:
            key (Key): The key to look up.
            executor (ThreadPoolExecutor): Executor for async execution.
        Returns:
            Future[Value | None]: Future for the cached value or None.
        )Úsubmitr*   )r$   r%   rd   s      r!   Ú	get_asynczAsyncCache.get_asyncÝ   s   € ð �Š˜tœx¨Ñ-Ô-Ð-r    r,   r   úFuture[bool]c                ó:   — |                      | j        ||¦  «        S )aO  
        Insert a value into the cache asynchronously.
        Args:
            key (Key): The key to insert.
            value (Value): The value to associate with the key.
            executor (ThreadPoolExecutor): Executor for async execution.
        Returns:
            Future[bool]: Future for the result of insertion.
        )rg   r1   )r$   r%   r,   rd   s       r!   Úinsert_asynczAsyncCache.insert_asyncê   s   € ð �Š˜tœ{¨C°Ñ7Ô7Ð7r    N)r$   r   r%   r   rd   r   r&   re   )
r$   r   r%   r   r,   r   rd   r   r&   ri   )r   r   r   r   rh   rk   r   r    r!   rc   rc   Ø   sF   € € € € € ðð ð.ð .ð .ð .ð8ð 8ð 8ð 8ð 8ð 8r    rc   c                  óœ   — e Zd ZU dZdZded<   ddd„Zedd„¦   «         Zd d„Z	d!d„Z
ed"d„¦   «         Zed#d„¦   «         Zed$d„¦   «         ZdS )%ÚOnDiskCachea?  
    On-disk cache implementation using files and file locks.
    Stores cache data in files on disk, with atomic operations and versioning.
    Supports custom cache directory names.
    Attributes:
        version (int): The version used for cache versioning.
        name (str): The name of the cache directory.
    r   ÚintÚversionNr$   r   Únameú
str | Noner&   r6   c                ó   — |pd| _         dS )zÅ
        Initialize an on-disk cache instance.
        Args:
            name (str | None, optional): The name of the cache directory. If None,
                defaults to "on_disk_cache".
        Úon_disk_cacheN)rp   )r$   rp   s     r!   r;   zOnDiskCache.__init__  s   € ð Ð+˜OˆŒ	ˆ	ˆ	r    r
   c                óN   — t          t          ¦   «         ¦  «        dz  | j        z  S )z‹
        Get the base directory for the cache.
        Returns:
            Path: The base directory path for storing cache files.
        rM   )r
   r   rp   r:   s    r!   Úbase_dirzOnDiskCache.base_dir  s"   € õ •J‘L”LÑ!Ô! GÑ+¨d¬iÑ7Ð7r    r%   r   c                óî   — 	 | j         t          t          j        |¦  «        ¦  «                             ¦   «         dd…         z  S # t
          t          j        f$ r}t          d|›d�¦  «        |‚d}~ww xY w)a  
        Get the file path for a given key.
        Args:
            key (Key): The key to convert to a file path.
        Returns:
            Path: The file path for the key.
        Raises:
            CacheError: If the key is not pickle-able.
        Né    zFailed to get fpath for key z, key is not pickle-able.)	ru   r   rI   ÚdumpsÚ	hexdigestÚAttributeErrorÚPicklingErrorr   r   )r$   r%   rR   s      r!   Ú_fpath_from_keyzOnDiskCache._fpath_from_key  s…   € ð	Ø”=¥6­&¬,°sÑ*;Ô*;Ñ#<Ô#<×#FÒ#FÑ#HÔ#HÈÈ"ÈÔ#MÑMÐMøÝ¥Ô 4Ð5ð 	ð 	ð 	ÝØO¨sÐOÐOÐOñô àðøøøøð	øøøs   ‚AA ÁA4ÁA/Á/A4rV   r   c                óp   — t          t          |j        dz  |j        dd…         z  ¦  «        dz   ¦  «        S )z²
        Get a file lock for a given file path.
        Args:
            fpath (Path): The file path.
        Returns:
            FileLock: The file lock for the path.
        ÚlocksNé   z.lock)r   r?   Úparentrp   )r$   rV   s     r!   Ú_flock_from_fpathzOnDiskCache._flock_from_fpath*  s5   € õ �˜EœL¨7Ñ2°U´ZÀÀÀ´^ÑCÑDÔDÀwÑNÑOÔOÐOr    Úbytesc                ó¦   — t          t          t          j        ¦  «                             ¦   «         ¦  «                             ¦   «         dd…         S )zŸ
        Get the version prefix for the cache.
        Returns:
            bytes: The version prefix as bytes, derived from the cache version string.
        Nr   )r   r?   rm   ro   ÚencodeÚdigestr:   s    r!   Úversion_prefixzOnDiskCache.version_prefix9  s>   € õ •c�+Ô-Ñ.Ô.×5Ò5Ñ7Ô7Ñ8Ô8×?Ò?ÑAÔAÀ"À1À"ÔEÐEr    r'   c                ó€  — |                       |¦  «        }|                      |¦  «        }|5  |                     ¦   «         s	 ddd¦  «         dS d}t          | j        ¦  «        }t          |d¦  «        5 }|                     |¦  «        | j        k    r|                     ¦   «         }ddd¦  «         n# 1 swxY w Y   |€"|                     ¦   «          	 ddd¦  «         dS 	 t          j	        |¦  «        }n+# t          j
        $ r}t          d|›d�¦  «        |‚d}~ww xY w|cddd¦  «         S # 1 swxY w Y   dS )aŽ  
        Retrieve a value from the cache.
        Args:
            key (Key): The key to look up.
        Returns:
            Value | None: The cached value if present and version matches, else None.
        Raises:
            CacheError: If the value is corrupted or cannot be unpickled.
        Side Effects:
            Removes stale cache files if the version prefix does not match.
        NrX   zFailed to get key z?, value is potentially corrupted (value is not un-pickle-able).)r|   r�   rY   Úlenr†   rZ   ÚreadÚunlinkrI   rJ   rK   r   )	r$   r%   rV   ÚflockrT   Úprefix_lengthr^   r,   rR   s	            r!   r*   zOnDiskCache.getB  s  € ð ×$Ò$ SÑ)Ô)ˆØ×&Ò& uÑ-Ô-ˆàð 	ð 	Ø—=’=‘?”?ð Øð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð ˆKÝ Ô 3Ñ4Ô4ˆMÝ�e˜TÑ"Ô"ð , bØ—7’7˜=Ñ)Ô)¨TÔ-@Ò@Ð@Ø"$§'¢'¡)¤)�Kð,ð ,ð ,ñ ,ô ,ð ,ð ,ð ,ð ,ð ,ð ,øøøð ,ð ,ð ,ð ,ð Ð"ð —’‘”�Øð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð"Ýœ [Ñ1Ô1��øÝÔ)ð ð ð Ý Øo¨ÐoÐoÐoñô àðøøøøðøøøð
 ð1	ð 	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	s_   ­D3Á&D3Á63B5Â)D3Â5B9	Â9D3Â<B9	Â=D3Ã%C:Ã9D3Ã:D"Ä	DÄD"Ä"D3Ä3D7Ä:D7r,   r   r-   c                óì  — |                       |¦  «        }|                      |¦  «        }|j                             dd¬¦  «         	 |5 }t	          |d¦  «        5 }|                     | j        ¦  «         t          j        ||¦  «         ddd¦  «         n# 1 swxY w Y   ddd¦  «         n# 1 swxY w Y   n:# t          j	        $ r}t          d|›d|›d�¦  «        |‚d}~wt          $ r Y dS w xY wdS )	a©  
        Insert a value into the cache.
        Args:
            key (Key): The key to insert.
            value (Value): The value to associate with the key.
        Returns:
            bool: True if the value was inserted, False if the key already exists.
        Raises:
            CacheError: If the value is not pickle-able.
        Side Effects:
            Creates the cache directory if it does not exist.
        T)ÚparentsÚexist_okÚxbNzFailed to insert key z with value z, value is not pickle-able.F)r|   r�   r€   ÚmkdirrZ   Úwriter†   rI   Údumpr{   r   ÚFileExistsError)r$   r%   r,   rV   r‹   Ú_r^   rR   s           r!   r1   zOnDiskCache.insertl  sœ  € ð ×$Ò$ SÑ)Ô)ˆØ×&Ò& uÑ-Ô-ˆØŒ×Ò 4°$ÐÑ7Ô7Ð7ð	ð ð '˜!�T %¨Ñ.Ô.ð '°"Ø—’˜Ô,Ñ-Ô-Ð-Ý”˜E 2Ñ&Ô&Ð&ð'ð 'ð 'ñ 'ô 'ð 'ð 'ð 'ð 'ð 'ð 'øøøð 'ð 'ð 'ð 'ð 'ð 'ð 'ñ 'ô 'ð 'ð 'ð 'ð 'ð 'ð 'øøøð 'ð 'ð 'ð 'øøõ Ô#ð 	ð 	ð 	ÝØ_¨Ð_Ð_¸5Ð_Ð_Ð_ñô àðøøøøõ ð 	ð 	ð 	Ø�5�5ð	øøøàˆtsf   ÁB: Á
B.Á0BÂB.ÂB	ÂB.ÂB	ÂB.Â"B: Â.B2Â2B: Â5B2Â6B: Â:C1Ã	C Ã C1Ã0C1)N)r$   r   rp   rq   r&   r6   ©r$   r   r&   r
   )r$   r   r%   r   r&   r
   )r$   r   rV   r
   r&   r   )r$   r   r&   r‚   r2   r3   )r   r   r   r   ro   Ú__annotations__r;   r   ru   r|   r�   Úpropertyr†   r   r*   r1   r   r    r!   rm   rm   ù   sý   € € € € € € ðð ð €GÐÐÐÑð,ð ,ð ,ð ,ð ,ð ð8ð 8ð 8ñ „_ð8ðð ð ð ð&Pð Pð Pð Pð ðFð Fð Fñ „XðFð ð'ð 'ð 'ñ „Xð'ðR ðð ð ñ „Xðð ð r    rm   c                  ó<   ‡ — e Zd ZdZd	ˆ fd„Zed
d„¦   «         Zˆ xZS )ÚInductorOnDiskCachezt
    Inductor-specific on-disk cache implementation.
    Uses a custom base directory for Inductor cache files.
    r$   r   r&   r6   c                óJ   •— t          ¦   «                              d¦  «         dS )zƒ
        Initialize an inductor on-disk cache instance.
        Sets the cache directory name to "inductor_on_disk_cache".
        Úinductor_on_disk_cacheN)Úsuperr;   )r$   Ú	__class__s    €r!   r;   zInductorOnDiskCache.__init__“  s$   ø€ õ
 	‰Œ×ÒÐ1Ñ2Ô2Ð2Ð2Ð2r    r
   c                óJ   — ddl m} t           |¦   «         d| j        ¦  «        S )z•
        Get the base directory for the Inductor cache.
        Returns:
            Path: The base directory path for Inductor cache files.
        r   )Údefault_cache_dirrM   )Ú%torch._inductor.runtime.runtime_utilsr    r
   rp   )r$   r    s     r!   ru   zInductorOnDiskCache.base_dirš  s5   € ð 	LÐKÐKÐKÐKÐKåÐ%Ð%Ñ'Ô'¨°$´)Ñ<Ô<Ð<r    r`   r–   )r   r   r   r   r;   r   ru   Ú__classcell__)rž   s   @r!   rš   rš   �  sg   ø€ € € € € ðð ð
3ð 3ð 3ð 3ð 3ð 3ð ð=ð =ð =ñ „_ð=ð =ð =ð =ð =r    rš   )1Ú
__future__r   rI   Úabcr   r   Úastr   Ú	functoolsr   Úhashlibr   Úosr	   Úpathlibr
   Útempfiler   Ú	threadingr   Útypingr   r   r   r   Útyping_extensionsr   r   r   Útorch.utils._filelockr   Úconcurrent.futuresr   r   r?   rn   Útupler   r‚   r]   Úlistr   rG   r   r#   r5   rc   rm   rš   r   r    r!   ú<module>r²      sÃ  ðØ "Ð "Ð "Ð "Ð "Ð "à €€€Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :à *Ð *Ð *Ð *Ð *Ð *ð ð >Ø=Ð=Ð=Ð=Ð=Ð=Ð=Ð=ð €gˆe�S˜#˜u S¨# XœÑ/Ô/€Øˆ�˜˜c 5¨¨c¨¤?°E¸4ÀÀSÀ¼>È4ÐPSÌ9ÑUÔU€ðð ð ð ð �ñ ô ð ðð ð ð ð ˆC�˜˜e˜Ô$ñ ô ð ð8Uð Uð Uð Uð U�E˜#˜u˜*Ô%ñ Uô Uð Uðp8ð 8ð 8ð 8ð 8��s˜E�zÔ"ñ 8ô 8ð 8ðBQð Qð Qð Qð Q�*˜S %˜ZÔ(ñ Qô Qð Qðh=ð =ð =ð =ð =˜+ c¨5 jÔ1ñ =ô =ð =ð =ð =r    