o
    }oi"                     @   s   d dl Z d dlZd dlmZmZ dZzd dlmZ W n ey%   dZY nw d dl	m
Z
 dZzd dlmZ W n eyA   dZY nw edZG d	d
 d
eZdS )    N)ABCabstractmethodT)TrainerF)ITritonDeployable)ModelPTNeMoc                   @   s   e Zd Z												d!d
edededededefddZedd Zedd Zedd Z	edd Z
dd Zdd Zedefdd ZdS )"
DeployBase   N   @  A  0.0.0.0TFr   triton_model_nametriton_model_versioncheckpoint_pathmax_batch_size	http_port	grpc_portc                 C   sn   || _ || _|| _|| _|| _|| _|| _|| _d | _|	| _	|
| _
|| _|| _|d u r3|d u r5tdd S d S )Nz3Either checkpoint_path or model should be provided.)r   r   r   r   modelr   r   addresstriton
allow_grpc
allow_http	streamingpytriton_log_verbose	Exception)selfr   r   r   r   r   r   r   r   r   r   r   r    r   K/home/ubuntu/.local/lib/python3.10/site-packages/nemo/deploy/deploy_base.py__init__&   s    zDeployBase.__init__c                 C      d S Nr   r   r   r   r   deployF      zDeployBase.deployc                 C   r    r!   r   r"   r   r   r   serveJ   r$   zDeployBase.servec                 C   r    r!   r   r"   r   r   r   runN   r$   zDeployBase.runc                 C   r    r!   r   r"   r   r   r   stopR   r$   zDeployBase.stopc              
   C   s   | j d urMtj| j dd}t|j\}}tt||}|j| j t	 d| _
| j
  z	d | j
j
jj_W n tyL } zt| W Y d }~nd }~ww | j
d u rVtd|   d S )NT)return_config)restore_pathtrainerzThere is no model to deploy.)r   r   restore_fromr   get_module_and_classtargetgetattr	importlibimport_moduler   r   freezelanguage_modelencoderactivations_checkpoint_methodAttributeErrorLOGGERwarningr   _is_model_deployable)r   model_configmodule_path
class_nameclser   r   r   _init_nemo_modelV   s   


zDeployBase._init_nemo_modelc                 C   s   t t| jtstddS )Nz^This model is not deployable to Triton.nemo.deploy.ITritonDeployable class should be inheritedT)
issubclasstyper   r   r   r"   r   r   r   r8   i   s
   zDeployBase._is_model_deployabler-   c                 C   s*   |  d}| d| | |d t|  fS )N.r   r	   )rindexlen)r-   lnr   r   r   r,   q   s   
 zDeployBase.get_module_and_class)r	   NNr
   r   r   r   TTFr   )__name__
__module____qualname__strintr   r   r#   r%   r&   r'   r>   r8   staticmethodr,   r   r   r   r   r   %   sJ    
 



r   )r/   loggingabcr   r   use_pytorch_lightninglightning.pytorchr   r   nemo.deploy.triton_deployabler   use_nemonemo.core.classes.modelPTr   	getLoggerr6   r   r   r   r   r   <module>   s$   
