o
    wi                     @  s   d dl mZ d dlZd dlZd dlmZ d dlZdgZdgZG dd dej	j
ZejG dd	 d	ejZed
kr>e  dS dS )    )annotationsN)Listfp32fp16c                      s(   e Zd Z fddZddddZ  ZS )ListAddc                   s   t    d S N)super__init__self	__class__ Z/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/tests/export/test_trt_compile.pyr	      s   zListAdd.__init__皙?xList[torch.Tensor]ytorch.Tensorzbsfloatc           	      C  s@   |  }| }|| }|D ]}|| | }q|||g|| fS r   )clonecopy)	r   r   r   r   r   y1x1z1xir   r   r   forward   s   zListAdd.forward)r   )r   r   r   r   r   r   r   r   )__name__
__module____qualname__r	   r   __classcell__r   r   r   r   r      s    r   c                   @  s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestTRTCompilec                 C  s   t j | _d S r   )torchcudacurrent_device
gpu_devicer
   r   r   r   setUp+   s   zTestTRTCompile.setUpc                 C  s*   t j }|| jkrt j| j d S d S r   )r$   r%   r&   r'   
set_device)r   r&   r   r   r   tearDown.   s   

zTestTRTCompile.tearDownc           	      C  s   t jjt j t j g }| }t dg|d< t dg|d< || |  t dd	d}t
 =}dg d	d
}|f}|| }t|| d|d | |jj || }| |jj t jj||ddd W d    d S 1 sxw   Y  d S )Nr   z0.weightg?z1.weight      r%   	torch_trt)r+         )methoddynamic_batchsize/test_listsargs{Gz?rtolatol)r$   nn
SequentialPReLU
state_dicttensorload_state_dictr%   randntotempfileTemporaryDirectorytrt_compileassertIsNone_trt_compilerengineassertIsNotNonetestingassert_close)	r   modeldata1r   tempdirr4   input_exampleoutput_example
trt_outputr   r   r   test_torch_trt3   s.   

"zTestTRTCompile.test_torch_trtc           
      C  s  t   }t  t }ddiddgddgddggddgddgddggddgddgddggddgddgddggddgddgddggdgd	gdgg gd
}tddd}tddd}tddd}|||g| | f}|| }t	|| d|d | 
|jj || }	| |jj tjj|	|ddd W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )NdynamoFr+   r/      r,       )x_0x_1x_2r   r   )export_argsinput_profilesoutput_listsr%   z/test_dynamo_trtr3   r5   r6   r   r%   r$   no_gradrA   rB   r?   r@   r   rC   rD   rE   rF   rG   rH   rI   
r   rJ   tmpdirr4   r   r   r   rM   rN   rO   r   r   r   test_profilesO   s8   
	PzTestTRTCompile.test_profilesc           
   	   C  s*  t   }t  t e}ddidgdgg gd}tddd}tddd}tddd}|||g| | f}|| }t	|| d	|d
 | 
|jj || }	| |jj tjj|	|ddd W d    n1 svw   Y  W d    d S W d    d S 1 sw   Y  d S )NrQ   TrW   rR   )rX   rZ   r+   r,   r%   r2   r3   r5   r6   r[   r]   r   r   r   
test_listsr   s*   
PzTestTRTCompile.test_listsN)r   r    r!   r(   r*   rP   r_   r`   r   r   r   r   r#   (   s    #r#   __main__)
__future__r   rA   unittesttypingr   r$   TEST_CASE_1TEST_CASE_2r9   Moduler   skipTestCaser#   r   mainr   r   r   r   <module>   s   d