o
    Ơi                  
   @   s  d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZmZ d dlZd dlmZmZmZ d dlmZ edg dZejeZejdejd	rQd
ndZejdejd	r`dndZejeeZejeeZej dkZ!ej"eZ#e#pej"eZ$e%e e%dkZ&e!rdndZ'dZ(e Z)e Z*e j+,dre j+,drej-drdZ.ndZ.ndZ.dZ.ee#e$e&e'e(e.e)e!e*	Z/edZ0de1fddZ2dedef dedef fddZ3dedef dedef fddZ4dedef dedef fdd Z5dedef dedef fd!d"Z6dedef dedef fd#d$Z7dedef dedef fd%d&Z8dedef dedef fd'd(Z9	d-d)edef d*e
e	e1  dedef fd+d,Z:dS ).    N)
namedtuple)AnyCallableDictListOptionalTypeTypeVar)check_cross_compile_trt_win_libload_tensorrt_llm_for_ncclsanitized_torch_version)version
FeatureSet)	torchscript_frontendtorch_tensorrt_runtimedynamo_frontendfx_frontendrefit
qdp_pluginwindows_cross_compiletensorrt_rtxtrtllm_for_nccllibwinztorchtrt.dllzlibtorchtrt.soztorchtrt_runtime.dllzlibtorchtrt_runtime.sor   z2.1.devFTztensorrt.pluginztensorrt.plugin._libz10.14.Treturnc                  C   sX   dd } d| t  d| t d| t d| t d| t d| t d	| t d
}|S )Nc                 S   s   | rdS dS )NENABLEDDISABLED )xr   r   L/home/ubuntu/.local/lib/python3.10/site-packages/torch_tensorrt/_features.py<lambda>T   s    z'_enabled_features_str.<locals>.<lambda>z&Enabled Features:
 - Dynamo Frontend: z
 - Torch-TensorRT Runtime: z
 - FX Frontend: z
 - TorchScript Frontend: z
 - Refit: z
 - QDP Plugin: z 
 - TensorRT-RTX: 
)_DYNAMO_FE_AVAIL_TORCHTRT_RT_AVAIL_FX_FE_AVAIL_TS_FE_AVAIL_REFIT_AVAIL_QDP_PLUGIN_AVAIL_TENSORRT_RTX)enabledout_strr   r   r    _enabled_features_strS   s   Lr,   f.c                    *   dt t dtttf dtf fdd}|S )Nargskwargsr   c                     s   t jr
 | i |S td)NzTensorRT-RTX is not availableENABLED_FEATURESr   NotImplementedErrorr/   r0   r-   r   r    wrapperZ   s   z#needs_tensorrt_rtx.<locals>.wrapperr   r   r   strr-   r6   r   r5   r    needs_tensorrt_rtxY   s   &r:   c                    r.   )Nr/   r0   r   c                     s   t js
 | i |S td)NzZThis is only available in non TensorRT-RTX environments, currently running in TensorRT-RTXr1   r4   r5   r   r    r6   d   s
   z'needs_not_tensorrt_rtx.<locals>.wrapperr7   r9   r   r5   r    needs_not_tensorrt_rtxc   s   &r;   c                    r.   )Nr/   r0   r   c                     D   t jr
 | i |S dtt dtttf dtfdd}|| i |S )Nr/   r0   r   c                  _      t d)Nz'Torch-TensorRT Runtime is not availabler3   r4   r   r   r    not_implementedu   s   zFneeds_torch_tensorrt_runtime.<locals>.wrapper.<locals>.not_implemented)r2   r   r   r   r   r8   r/   r0   r?   r5   r   r    r6   p   s   "z-needs_torch_tensorrt_runtime.<locals>.wrapperr7   r9   r   r5   r    needs_torch_tensorrt_runtimeo   s   &
rA   c                    r.   )Nr/   r0   r   c                     r<   )Nr/   r0   r   c                  _   r=   )NzTTensorRT QDP(Quick Deploy Plugins) not available, requires TensorRT 10.7.0 or higherr>   r4   r   r   r    r?         z:needs_qdp_plugin.<locals>.wrapper.<locals>.not_implemented)r2   r   r   r   r   r8   r@   r5   r   r    r6   ~      "z!needs_qdp_plugin.<locals>.wrapperr7   r9   r   r5   r    needs_qdp_plugin}      &rD   c                    r.   )Nr/   r0   r   c                     r<   )Nr/   r0   r   c                  _   r=   NzARefit feature is currently not available in Python 3.13 or higherr>   r4   r   r   r    r?      rB   z5needs_refit.<locals>.wrapper.<locals>.not_implemented)r2   r   r   r   r   r8   r@   r5   r   r    r6      rC   zneeds_refit.<locals>.wrapperr7   r9   r   r5   r    needs_refit   rE   rG   c                    r.   )Nr/   r0   r   c                     r<   )Nr/   r0   r   c                  _   r=   )Nz2Windows cross compilation feature is not availabler>   r4   r   r   r    r?      rB   z=needs_cross_compile.<locals>.wrapper.<locals>.not_implemented)r2   r   r   r   r   r8   r@   r5   r   r    r6      rC   z$needs_cross_compile.<locals>.wrapperr7   r9   r   r5   r    needs_cross_compile   rE   rH   c                    r.   )Nr/   r0   r   c                     r<   )Nr/   r0   r   c                  _   r=   rF   r>   r4   r   r   r    r?      rB   z?needs_trtllm_for_nccl.<locals>.wrapper.<locals>.not_implemented)r2   r   r   r   r   r8   r@   r5   r   r    r6      rC   z&needs_trtllm_for_nccl.<locals>.wrapperr7   r9   r   r5   r    needs_trtllm_for_nccl   rE   rI   	decoratorexcludec                    s0   g |r|dt t dt t f fdd}|S )Nclsr   c                    s<   | j D ]}tt| |r|vrt| | t| | q| S N)__dict__callablegetattrsetattr)rL   attrrJ   exclude_listr   r    decorate   s
   
z!for_all_methods.<locals>.decorate)r   r   )rJ   rK   rU   r   rS   r    for_all_methods   s
    rV   rM   );	importlibossyscollectionsr   typingr   r   r   r   r   r   r	   tensorrttorch_tensorrt._utilsr
   r   r   	packagingr   r   pathdirname__file__trtorch_dirjoinplatform
startswithlinked_filelinked_file_runtimelinked_file_full_pathlinked_file_runtime_full_path_package_namer)   isfiler&   r$   parser#   r%   r'   _WINDOWS_CROSS_COMPILE_TRTLLM_AVAILutil	find_spec__version__r(   r2   r   r8   r,   r:   r;   rA   rD   rG   rH   rI   rV   r   r   r   r    <module>   s    $

""
"""""


