U
    <cc                     @   sF   d Z ddlZddlm  mZ ddlmZmZ G dd dZ	e	 Z
dS )zGlobals used internally by the ONNX exporter.

Do not use this module outside of `torch.onnx` and its tests.

Be very judicious when adding any new global variables. Do not create new global
variables unless they are absolutely necessary.
    N)
_constants_exporter_statesc                   @   s   e Zd ZdZdd Zedd Zejej	dddZee
dd	d
Zeje
ddd
ZeedddZejedddZdS )_InternalGlobalszGlobals used internally by ONNX exporter.

    NOTE: Be very judicious when adding any new variables. Do not create new
    global variables unless they are absolutely necessary.
    c                 C   sp   t j| _tjj| _d| _d| _tj	j
| _d| _tddkrHtjj| _n$tddkrbtjj| _n
tjj| _d S )NFTZ*TORCH_ONNX_EXPERIMENTAL_RUNTIME_TYPE_CHECKERRORSDISABLED)r   ZONNX_DEFAULT_OPSET_export_onnx_opset_version_C_onnxTrainingModeZEVAL_training_mode_in_onnx_exportZexport_trainingZOperatorExportTypesZONNXZoperator_export_typeZonnx_shape_inferenceosgetenvr   ZRuntimeTypeCheckStater   Zruntime_type_check_stater   ZWARNINGSself r   7/tmp/pip-unpacked-wheel-gikjz4vx/torch/onnx/_globals.py__init__   s    
z_InternalGlobals.__init__c                 C   s   | j S )z#The training mode for the exporter.)r
   r   r   r   r   training_mode1   s    z_InternalGlobals.training_mode)r   c                 C   s   t |tjstd|| _d S )Nz\training_mode must be of type 'torch.onnx.TrainingMode'. This is likely a bug in torch.onnx.)
isinstancer   r	   	TypeErrorr
   )r   r   r   r   r   r   6   s
    )returnc                 C   s   | j S )z!Opset version used during export.)r   r   r   r   r   export_onnx_opset_version?   s    z*_InternalGlobals.export_onnx_opset_version)valuec                 C   s2   t tjtjd }||kr(td| || _d S )N   z Unsupported ONNX opset version: )ranger   ZONNX_MIN_OPSETZONNX_MAX_OPSET
ValueErrorr   )r   r   Zsupported_versionsr   r   r   r   D   s     c                 C   s   | j S )z+Whether it is in the middle of ONNX export.)r   r   r   r   r   in_onnx_exportM   s    z_InternalGlobals.in_onnx_exportc                 C   s   t |tk	rtd|| _d S )Nz in_onnx_export must be a boolean)typeboolr   r   )r   r   r   r   r   r   R   s    N)__name__
__module____qualname____doc__r   propertyr   setterr   r	   intr   r   r   r   r   r   r   r      s   
r   )r"   r   Ztorch._C._onnxZ_CZ_onnxr   Z
torch.onnxr   r   r   ZGLOBALSr   r   r   r   <module>   s
   H