
    8he                        S SK r S SKrS SKrS SKrS SKrS SKJr  S SKrS SKJ	r	  S SK
JrJr  S SKJrJrJrJr  S SKJr  \R(                  " \5      rS\S\\   S	\S
\4S jrS\S\S
\4S jr    SS\S\S\S\S\S
\4S jjrg)    N)IO)config)BuildOptionsBase
CppBuilder)
AOTI_FILESAOTICompiledModelload_pt2package_pt2)FileLikeaoti_dir
aoti_filesso_pathreturnc                   ^ S[         S[         4U4S jjn[        R                  R                  X" S5      5      n[        R                  R                  X" S5      5      n[        R                  R	                  U5      S   n[        US-   5       n[        R                  " U5      nS S S 5        [        S0 WDS[        R                  " 5       0D6n	[        UUU	S	9n
U
R                  5       nU
R                  5         [        US
-   5       n[        R                  " U5      nS S S 5        [        S0 WDS[        R                  " 5       0D6n[        [        R                  R                  U5      S   X/UUS9nUR                  5       nUR                  5         US-   nUT;   aw  [        US5       nUR                  5       nS S S 5        [        US5       nUR!                  5       nUR#                  SSUS-  -
  -  5        UR#                  W5        S S S 5        U$ U$ ! , (       d  f       GN|= f! , (       d  f       GN= f! , (       d  f       N= f! , (       d  f       U$ = f)Nsuffixr   c                 f   > T H  nUR                  U 5      (       d  M  Us  $    [        SU  35      e)Nz Unable to find file with suffix )endswithRuntimeError)r   filer   s     Y/var/www/fran/franai/venv/lib/python3.13/site-packages/torch/_inductor/package/package.pyget_aoti_file_with_suffix-compile_so.<locals>.get_aoti_file_with_suffix   s6    D}}V$$  =fXFGG    z.cppz.or   z_compile_flags.jsonuse_relative_path)namesourcesBuildOptionz_linker_flags.json)r   r   r   
output_dirz_serialized_weights.binrbza+b    i @   )strospathjoinsplitextopenjsonloadr   r   	is_fbcoder   get_target_file_pathbuildsplitreadtellwrite)r   r   r   r   cpp_fileconsts_o	file_namefcompile_flagscompile_optionsobject_builderoutput_olinker_flagslinker_options
so_builder	output_soserialized_weights_filename	f_weightsserialized_weightsf_soso_sizes    `                   r   
compile_sorC      s(   H# H# H ww||H&?&GHHww||H&?&EFH  *1-I 
i//	0A		! 
1 ' 
+1+;+;+=O  #N
 224H 
i..	/1yy| 
0 & 
*0*:*:*<N WW]]7#B'$"	J //1I #,.G"G"j0-t4	!*!1 5 )U#tiikGJJtuw678JJ)*	 $ 9U 
1	0 
0	/$ 54 $# s0   H
H./I <I
H+.
H= 
I
I archive_filec                     [        U US9$ )aC  
Saves the AOTInductor generated files to the PT2Archive format.

Args:
    archive_file: The file name to save the package to.
    aoti_files: This can either be a singular path to a directory containing
    the AOTInductor files, or a dictionary mapping the model name to the
    path to its AOTInductor generated files.
)r   )r
   )rD   r   s     r   package_aotirF   R   s      r   r%   
model_namerun_single_threadednum_runnersdevice_indexc                      [        U UUUS9nXR                  ;  a  [        SU S35      eUR                  U   $ ! [         a    [        R	                  S5         Of = f[        U [        R                  [        45      (       a  [        R                  " SS9 nU R                  S5        UR                  U R                  5       5        [        R                  SUR                  5        [         R"                  R$                  R'                  UR                  XX45      n[)        U5      sS S S 5        $ ! , (       d  f       O= f[*        R,                  " U 5      n [         R"                  R$                  R'                  XX#U5      n[)        U5      $ )	N)rH   rI   rJ   zModel z not found in packagez:Loading outdated pt2 file. Please regenerate your package.z.pt2)r   r   z)Writing buffer to tmp file located at %s.)r	   aoti_runnersr   logwarning
isinstanceioIOBaser   tempfileNamedTemporaryFileseekr1   r/   debugr   torch_C_aotiAOTIModelPackageLoaderr   r$   fspath)r%   rG   rH   rI   rJ   pt2_contentsr5   loaders           r   load_packager]   f   s>   R 3#%	
 666
|3HIJJ((44 RPQR $B((((71 IIaLGGDIIK IIA166JXX^^::
F %V, 877 99T?DXX^^22-LF V$$s   8; AABD33
E)modelF   r   )rP   r)   loggingr$   rR   typingr   rV   torch._inductorr   torch._inductor.cpp_builderr   r   !torch.export.pt2_archive._packager   r   r	   r
   torch.typesr   	getLogger__name__rM   r#   listrC   rF   boolintr]   r"   r   r   <module>rk      s    	   	    " D  ! !8 8$s) 8c 8c 8v ,  %$%
$%$% $% 	$%
 $% $%r   