
    `iK                        d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlZd dlm	Z	 d dl
mZmZ d dlmZmZmZmZ d dlmZ  ej        e          Zdedee         d	ed
efdZdeded
efdZ	 	 	 	 ddededededed
efdZdS )    N)IO)config)BuildOptionsBase
CppBuilder)
AOTI_FILESAOTICompiledModelload_pt2package_pt2)FileLikeaoti_dir
aoti_filesso_pathreturnc                 6   dt           dt           ffd}t          j                            |  |d                    }t          j                            |  |d                    }t          j                            |          d         }t          |dz             5 }t          j        |          }d d d            n# 1 swxY w Y   t          di |dt          j
                    i}	t          |||		          }
|
                                }|
                                 t          |d
z             5 }t          j        |          }d d d            n# 1 swxY w Y   t          di |dt          j
                    i}t          t          j                            |          d         ||g||          }|                                }|                                 |dz   }|v rt          |d          5 }|                                }d d d            n# 1 swxY w Y   t          |d          5 }|                                }|                    dd|dz  z
  z             |                    |           d d d            n# 1 swxY w Y   |S )Nsuffixr   c                 d    D ]}|                     |           r|c S t          d|            )Nz Unable to find file with suffix )endswithRuntimeError)r   filer   s     s/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torch/_inductor/package/package.pyget_aoti_file_with_suffixz-compile_so.<locals>.get_aoti_file_with_suffix   sK     	 	D}}V$$ FfFFG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_sorB      s   H# H# H H H H H H w||H&?&?&G&GHHHw||H&?&?&E&EFFH  **1-I 
i//	0	0 %A	!% % % % % % % % % % % % % % % '  
 +1+;+=+=  O  #  N
 2244H 
i..	/	/ $1y||$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ &  
 *0*:*<*<  N W]]7##B'8$"	  J //11I #,.G"G"j00-t44 	2	!*!1!1	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 )U## 	+tiikkGJJtuw67888JJ)***		+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ sI   C  CC8EE E>HH#&H#:AJJJarchive_filec                 $    t          | |          S )a_  
    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
   )rC   r   s     r   package_aotirE   R   s!        r   modelF   r   r$   
model_namerun_single_threadednum_runnersdevice_indexc                 2   	 t          | |||          }||j        vrt          d| d          |j        |         S # t          $ r t                              d           Y nw xY wt          | t          j        t          f          rt          j
        d          5 }|                     d           |                    |                                            t                              d|j                   t           j        j                            |j        ||||          }t)          |          cd d d            S # 1 swxY w Y   t+          j        |           } t           j        j                            | ||||          }t)          |          S )	N)rI   rJ   rK   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seekr0   r.   debugr   torch_C_aotiAOTIModelPackageLoaderr   r#   fspath)r$   rH   rI   rJ   rK   pt2_contentsr4   loaders           r   load_packager^   f   s   R 3#%	
 
 
 \666I
IIIJJJ(44 R R RPQQQQQR $B(( 
-(777 		-1 IIaLLLGGDIIKK   IIA16JJJX^::
$7l F %V,,		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 9T??DX^22j-{L F V$$$s"   ;> $A%$A%BEE
E)rF   FrG   r   )rQ   r(   loggingr#   rS   typingr   rW   torch._inductorr   torch._inductor.cpp_builderr   r   !torch.export.pt2_archive._packager   r   r	   r
   torch.typesr   	getLogger__name__rN   r"   listrB   rE   boolintr^   r!   r   r   <module>rj      s   				   				         " " " " " " D D D D D D D D            !           g!!8 8$s) 8c 8c 8 8 8 8v    ,  %$% $%
$%$% $% 	$%
 $% $% $% $% $% $% $%r   