
    [Th                     6   S SK r S SKrS SKrS SKrS SKJr  S SKJrJr  S SK	J
r
Jr  S SKJr  S SKJrJrJr  S SKJr  \R(                  " \5      r " S S	\5      r\R0                  " S
S9 " S S5      5       r\R0                   " S S5      5       r " S S5      rg)    N)Enum)OptionalUnion)
JsonDataTyRemoteCacheJsonSerde)	cache_dir)AppendingByteSerializerBytesReaderBytesWriter)
OrderedSetc                   (    \ rS rSrSrSrSrSrSrSr	g)	CacheArtifactType   z
Type of cache
r             N)
__name__
__module____qualname____firstlineno____doc__INDUCTORAUTOTUNEAOT_AUTOGRADPGO__static_attributes__r       M/var/www/auris/envauris/lib/python3.13/site-packages/torch/compiler/_cache.pyr   r      s     HHL
Cr   r   T)frozenc                       \ rS rSr% Sr\\S'   \\S'   \R                  " SS9r
\\S'   \S\S	S S
S4S j5       r\S\S
S 4S j5       rSrg)CacheArtifact    zG
Data for each cache artifact that will be serialized and deserialized
typekeyF)reprcontentwriterclsreturnNc                     U R                  UR                  R                  5        U R                  UR                  5        U R                  UR                  5        g N)write_uint64r$   value	write_strr%   write_bytesr'   )r(   r)   s     r   	serializeCacheArtifact.serialize*   s<    CHHNN+!3;;'r   readerc                     U R                  5       nU R                  5       nU R                  5       n[        [	        U5      X#5      $ r,   )read_uint64read_str
read_bytesr"   r   )r3   r$   r%   r'   s       r   deserializeCacheArtifact.deserialize0   s=    !!#oo##%.t4cCCr   r   )r   r   r   r   r   r   __annotations__strdataclassesfieldr'   bytesstaticmethodr   r1   r
   r8   r   r   r   r   r"   r"       sv     	H &&E2GU2(+ (O ( ( (
 DK DO D Dr   r"   c                       \ rS rSr% Sr\R                  " \S9r\\	   \
S'   \R                  " \S9r\\	   \
S'   \R                  " \S9r\\	   \
S'   \R                  " \S9r\\	   \
S'   S\S	S
4S jrSS jrSrg
)	CacheInfo8   zV
Return value of serialization and deserialization for the purpose of
instrumentation
)default_factoryinductor_artifactsautotune_artifactsaot_autograd_artifactspgo_artifactsartifactr*   Nc                 h   UR                   [        R                  :X  a&  U R                  R	                  UR
                  5        g UR                   [        R                  :X  a&  U R                  R	                  UR
                  5        g UR                   [        R                  :X  a&  U R                  R	                  UR
                  5        g UR                   [        R                  :X  a&  U R                  R	                  UR
                  5        g [        R                  SUR                    35        g )NUnsupported artifact type )r$   r   r   rD   appendr%   r   rE   r   rF   r   rG   logwarning)selfrH   s     r   addCacheInfo.addD   s    ==-666##**8<<8]]/888##**8<<8]]/<<<''..x||<]]/333%%hll3KK4X]]ODEr   c                     U R                   R                  5         U R                  R                  5         U R                  R                  5         U R                  R                  5         g r,   )rD   clearrE   rF   rG   )rN   s    r   rR   CacheInfo.clearP   sJ    %%'%%'##))+  "r   r   r*   N)r   r   r   r   r   r<   r=   listrD   r;   r:   rE   rF   rG   r"   rO   rR   r   r   r   r   rA   rA   8   s    
 %0$5$5d$KS	K$/$5$5d$KS	K(3(9(9$(ODIO*00FM49F
FM 
Fd 
F#r   rA   c            	       8   \ rS rSr% Sr/ r\\   \S'   \	" 5       r
\	\   \S'   \" \R                  S9r\\   \S'   \" 5       r\\S'   \SS
 j5       r\S\S\S\\\4   SS	4S j5       r\S\4S j5       r\S\\\\4      4S j5       r\S\S\\   4S j5       rSrg	)CacheArtifactManagerW   a!  
Lightweight manager class for collecting and processing cache artifacts for
hot loading

Intended Lifecycle:
- Execute code via torch.compile, this will call
    CacheArtifactManager.record_artifact on each cache artifact
- Call CacheArtifactManager.serialize to convert all the cache artifacts
    to portable format
- Call CacheArtifactManager.deserialize to hot load the cache artifacts on
    a potentially different process

NOTE: There's no FB/FC guarentees, results of cache artifacts will not be
      used unless code version matches.
_new_cache_artifacts_seen_artifacts)serialize_fn_serializer_cache_infor*   Nc                     U R                   R                  5         U R                  R                  5         U R                  R                  5         U R                  R                  5         g r,   )rY   rR   rZ   r\   r]   r)   s    r   rR   CacheArtifactManager.clearu   sF      &&(!!#r   artifact_typer%   r'   c                    U[         R                  :X  a2  [        U[        5      (       a   e[	        5       nUR                  U5      n[        U[        5      (       d   e[        XU5      nXPR                  ;   a  g[        R                  S[        U5      5        U R                  R                  U5        U R                  R                  U5        g)zO
Called from each caching operation to record the artifact in this
"mega" list
NzRecording %s)r   r   
isinstancer>   r   encoder"   rZ   rL   debugr;   rY   rK   rO   )r)   ra   r%   r'   serderH   s         r   record_artifact$CacheArtifactManager.record_artifact|   s     -666!'51111(*Ell7+G'5)))) W=***		.#h-0  ''1)r   c                 2    [        U R                  5      S:g  $ )z7
Have we seen new artifacts since last serialize call?
r   )lenrY   r_   s    r   need_serialize#CacheArtifactManager.need_serialize   s    
 3++,11r   c                    U R                    H4  n[        R                  SU5        U R                  R	                  U5        M6      [
        R                  " U R                  5      nU R                  R                  U R                   5        U R                  R                  5       nU R                   R                  5         X24$ ! [         a    [        R                  SSS9   gf = f)z/
Converts the "mega" list into portable format
z
saving: %sz Failed to pickle cache artifactsTexc_infoN)rY   rL   re   r]   rO   copydeepcopyr\   extendto_bytesrR   	ExceptionrM   )r)   rH   infoartifact_bytess       r   r1   CacheArtifactManager.serialize   s    
 00HIIlH-OO) 1		K ==1DOO""3#;#;< __557N$$**,!'' 	KKK:TKJ	Ks   A;C C#"C#serialized_artifactsc                 
    [         R                  " U [        R                  S9nSSKJn  SSK	J
n  SS	KJn  SS
KJn  U" 5       n[        5       nU GH  n[
        R!                  SU5        UR#                  U5        UR$                  [&        R(                  :X  a(  UR+                  UR,                  UR.                  5        Mq  UR$                  [&        R0                  :X  aO  [2        R4                  R7                  [9        5       UR,                  5      n	UR;                  XR.                  5        M  UR$                  [&        R<                  :X  a)  UR+                  UR,                  UR.                  5        GM%  UR$                  [&        R>                  :X  a%  U" UR,                  UR.                  5      n
U
c   eGMh  [
        R                  SUR$                   35        GM     U$ ! [         a    [
        R                  SSS9   gf = f)zB
Converts the portable format back into various filesystem caches
)deserialize_fnz#Failed to un-pickle cache artifactsTrn   Nr   )write_local_impl)AOTAutogradCache)FxGraphCache)_LocalAutotuneCacheBackendzwriting: %srJ   ) r	   to_listr"   r8   rt   rL   rM   torch._dynamo.pgor{   -torch._functorch._aot_autograd.autograd_cacher|   torch._inductor.codecacher}   &torch._inductor.runtime.autotune_cacher~   rA   re   rO   r$   r   r   _write_to_local_cacher%   r'   r   ospathjoinr   _putr   r   )rx   	artifactsr{   r|   r}   r~   autotune_cacheru   rH   r%   metas              r   r8    CacheArtifactManager.deserialize   sw   
	/77$]5N5NI 	7R:U35{!HIImX.HHX}} 1 : ::228<<AQAQR"3"<"<<ggll9;=##C)9)9:"3"@"@@ 66x||XEUEUV"3"7"77'h6F6FG'''8HI "  9  	KK=KM	s   #G! !HHr   rT   )r   r   r   r   r   rY   rU   r"   r:   r   rZ   r	   r1   r\   rA   r]   classmethodrR   r   r;   r   r>   r   rg   boolrk   r   tupler?   r8   r   r   r   r   rW   rW   W   s   " 13$}-2 2<OZ.= ;R",,;K(7  '[K(    *(* * uj()	*
 
* *, 2t 2 2 (5	)9#:;  & $% $HY4G $ $r   rW   )rp   r<   loggingr   enumr   typingr   r   torch._inductor.remote_cacher   r   %torch._inductor.runtime.runtime_utilsr   &torch.utils._appending_byte_serializerr	   r
   r   torch.utils._ordered_setr   	getLoggerr   rL   r   	dataclassr"   rA   rW   r   r   r   <module>r      s       	  " I ; 
 0 !  d#D D $D. # # #<| |r   