o
    i	                     @  s   d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	 e	dej
ed\ZZer/d dlmZ n
e	dej
ed\ZZG d	d
 d
ZdS )    )annotations)TYPE_CHECKING)trt_compile)
IgniteInfomin_versionoptional_importzignite.engineEvents)Enginer	   c                   @  s.   e Zd ZdZdddZdd	d
ZdddZdS )
TrtHandlera  
    TrtHandler acts as an Ignite handler to apply TRT acceleration to the model.
    Usage example::
        handler = TrtHandler(model=model, base_path="/test/checkpoint.pt", args={"precision": "fp16"})
        handler.attach(engine)
        engine.run()
    Nc                 C  s   || _ || _|| _|| _dS )a  
        Args:
            base_path: TRT path basename. TRT plan(s) saved to "base_path[.submodule].plan"
            args: passed to trt_compile(). See trt_compile() for details.
            submodule : Hierarchical ids of submodules to convert, e.g. 'image_decoder.decoder'
        N)model	base_pathargs	submodule)selfr   r   r   r    r   \/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/handlers/trt_handler.py__init__#   s   
zTrtHandler.__init__enginer	   returnNonec                 C  s   |j | _ |tj|  dS )g
        Args:
            engine: Ignite Engine, it can be a trainer, validator or evaluator.
        N)loggeradd_event_handlerr   STARTEDr   r   r   r   r   attach/   s   zTrtHandler.attachc                 C  s    t | j| j| j| j| jd dS )r   )r   r   r   N)r   r   r   r   r   r   r   r   r   r   __call__7   s    zTrtHandler.__call__)NN)r   r	   r   r   )__name__
__module____qualname____doc__r   r   r   r   r   r   r   r
      s
    

r
   N)
__future__r   typingr   monai.networksr   monai.utilsr   r   r   OPT_IMPORT_VERSIONr   _ignite.enginer	   r
   r   r   r   r   <module>   s   