a
    .=icL                     @   s   d Z ddlZddlmZ ddlmZ eddd Zedddd	d
ZedddddZ	edddd Z
eddddddddd	dd ZG dd dZdS )a&  This file exports ONNX ops for opset 14.

Note [ONNX operators that are added/updated in opset 14]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
New operators:
    HardSwish, Trilu

Updated operators:
    Reshape
    Add, Sub, Mul, Div
    GRU, LSTM, RNN
    BatchNorm, Cumsum, Relu
    N)symbolic_helper)GLOBALSvc                 C   s   |  d|S )NZ	HardSwish)op)gself r   l/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/torch/onnx/symbolic_opset14.py	hardswish   s    r
   ic                 C   s,   | j dtj|tjdd}| j d||ddS )NConstantZdtypeZvalue_tTrilur   Zupper_ir   torchZtensorint64r   r   Zdiagonaloutkr   r   r	   tril   s    r   c                 C   s,   | j dtj|tjdd}| j d||ddS )Nr   r   r   r      r   r   r   r   r   r	   triu"   s    r   c                 C   s   t j| ||ddS )Nr   )Z	allowzero)r   Z_reshape_helper)r   r   shaper   r   r	   reshape(   s    r   fc
                 C   s   t  r6t|||||gs6tjdk r6tddddS t|d t| |||||\}}}}| j	d||||||d| |s~dnd|sdndd	
}
|s|
S |
\}}}|
|  |
|  |S d S )
N   ZBatchNormalization   zaAll input tensors must have the same `dtype`. Turn off Autocast or export using opset version 15.
batch_normr   r      )Z	epsilon_fZ
momentum_fZtraining_mode_ioutputs)r   Zis_autocast_enabledr   Zargs_have_same_dtyper   Zexport_onnx_opset_versionZ _onnx_opset_unsupported_detailedZcheck_training_modeZ_batchnorm_helperr   ZsetTypetype)r   inputweightZbiasZrunning_meanZrunning_varZtrainingZmomentumZepsZcudnn_enabledr   resZnew_running_meanZnew_running_varr   r   r	   r   /   sH    


r   c                   @   s    e Zd ZdZdZedd ZdS )	Quantizedz^
    https://github.com/pytorch/pytorch/wiki/PyTorch-ONNX-exporter#quantized-model-export
    Z	quantizedc                 C   s.   t | |\}}}}t| |}t | |||S )N)r   Zdequantize_helperr
   Zquantize_helper)r   xZop_scaleZop_zero_point_outputr   r   r	   r
   l   s    
zQuantized.hardswishN)__name__
__module____qualname____doc__domainstaticmethodr
   r   r   r   r	   r&   e   s   r&   )N)N)r-   r   Z
torch.onnxr   Ztorch.onnx._globalsr   
parse_argsr
   r   r   r   r   r&   r   r   r   r	   <module>   s   





5