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 ee j	eej	dd Z	eej
jj	dd	 Zeej
jjd
d ZdS )    N   )tensorrt_converter   )get_dyn_rangemark_as_int8_layerc           	      C   s   t dd | D }|dkr|\}}n|d |d }}|d dks%J tdd	 ||fD s4td
| ||tjj}||_|	dS )Nc                 S   s   g | ]}|d kr|qS )_itensor_to_tensor_meta ).0xr   r   T/home/ubuntu/.local/lib/python3.10/site-packages/torch_tensorrt/fx/converters/add.py
<listcomp>   s    zadd.<locals>.<listcomp>r   inputotheralphar   c                 s       | ]
}t |tjjV  qd S N
isinstancetrttensorrtITensor)r	   argr   r   r   	<genexpr>       zadd.<locals>.<genexpr>z@add() received an input that is not part of the TensorRT region!)
lenkeysallRuntimeErroradd_elementwiser   ElementWiseOperationSUMname
get_output)	networktargetargskwargs
layer_name
len_kwargslhs_valrhs_vallayerr   r   r   add   s   

r,   c           	      C   sr   |d |d }}t dd ||fD std| ||tjj}||_t|d |d tj	}t
|| |dS )	Nqaqbc                 s   r   r   r   r	   ir   r   r   r   '   r   z quantized_add.<locals>.<genexpr>zHQuantized add received an input that is not part of the TensorRT region!scale
zero_pointr   )r   r   r   r   r   r    r!   r   torchquint8r   r"   )	r#   r$   r%   r&   r'   r)   r*   r+   	dyn_ranger   r   r   quantized_add#   s   

r6   c           	      C   s   |d |d }}t dd ||fD std| ||tjj}| d|_t|d |d tj	}t
|| | j|d	tjjd
}| d|_t
|| |d	S )Nr-   r.   c                 s   r   r   r   r/   r   r   r   r   8   r   z%quantized_add_relu.<locals>.<genexpr>zMQuantized add_relu received an input that is not part of the TensorRT region!_addr1   r2   r   )r   type_relu)r   r   r   r   r   r    r!   r   r3   r4   r   add_activationr"   ActivationTypeRELU)	r#   submodr%   r&   r'   r)   r*   r+   r5   r   r   r   quantized_add_relu4   s   


r>   )operatorr   r   r3   converter_registryr   converter_utilsr   r   r,   ops	quantizedr6   add_relur>   r   r   r   r   <module>   s    
