o
    Xi>                    @  s  d Z ddlmZ ddlZddlZg dZddlZddlZddlZddl	m
Z
mZmZ ddlmZmZ ddlZddlZddlZddlmZmZmZmZmZ ejr[ddlm  m  mZ ee Z!dZ"d	Z#d
Z$ej%dedef dZ&G dd de'Z(dddZ)dddZ*ej+dddZ,ej+dd dZ,ej+d d#dZ,ej+d!d&dZ,ej+d"d)dZ,ej+d#d,dZ,ej+d$d/dZ,ej+d%d2dZ,ej+d&d5dZ,ej+d'd8dZ,ej+d(d;dZ,ej+d)d>dZ,d*d@dZ,	d+d,dEdFZ-	Gd-d.dLdMZ.ej+d/dOdPZ/ej+d0dRdPZ/ej+d1dTdPZ/ej+d2dUdPZ/ej+d3dWdPZ/ej+d4dYdPZ/ej+d5d[dPZ/ej+d6d]dPZ/ej+d7d_dPZ/ej+d8dadPZ/d9dbdPZ/G dcdd ddej0Z1d:dgdhZ2d;djdkZ3d<dndoZ4ddpdqZ5d=dwdxZ6ddydzZ7e)d{d| d>ddZ8d?ddZ9e)dd| d%ddZ:e)dd| d@ddZ;e)dd| dAddZ<e)e=d&ddZ>e)e=dBddZ?e)e=dCddZ@e)e=d'ddZAe)dd| 	dDdEddZBdFddZCeCZDd"ddZEe)dd| dGddZFd ddZGe)dd| dHddZHdIddZIe)dd| dJddZJdKddZKdLddZLdMddÄZMdNddȄZNeNZOdOddʄZPdPdd΄ZQdQdd҄ZRe)dd| dRddՄZSddלdSddڄZTe)dd| ddלdTddބZUdUddZVdVddZWe)dd| dWddZXdXddZYe)dd| dYddZZdZddZ[e)dd| d[ddZ\d\ddZ]e)dd| d]ddZ^d^d dZ_ddd_ddZ`e)dDdd|ddd`ddZae)d	d| daddZbdbddZce)dd| dcddZde)dd| 	d+ddddZedS (e  zNSerialize and deserialize the intermediate representation to/from ONNX protos.    )annotationsN)'TensorProtoTensor
from_protofrom_onnx_textdeserialize_attributedeserialize_dimensiondeserialize_functiondeserialize_graphdeserialize_metadata_propsdeserialize_modeldeserialize_nodedeserialize_opset_importdeserialize_tensordeserialize_tensor_shape deserialize_type_proto_for_shapedeserialize_type_proto_for_typedeserialize_value_info_prototo_prototo_onnx_textserialize_attribute_intoserialize_attributeserialize_dimension_intoserialize_function_intoserialize_functionserialize_graph_intoserialize_graphserialize_model_intoserialize_modelserialize_node_intoserialize_nodeserialize_shape_into"serialize_reference_attribute_intoserialize_reference_attributeserialize_tensor_intoserialize_tensorserialize_type_intoserialize_typeserialize_value_intoserialize_value
SerdeError)IterableMappingSequence)AnyCallable)_convenience_core_enums
_protocols_type_castingzFPlease contribute by creating a PR at https://github.com/onnx/onnx-ir.
   quant_parameter_tensor_names_T.)boundc                   @  s   e Zd ZdZdS )r)   z.Error during serialization or deserialization.N)__name__
__module____qualname____doc__ r<   r<   A/home/ubuntu/.local/lib/python3.10/site-packages/onnx_ir/serde.pyr)   Y   s    r)   arg_capturerCallable[..., str]returnCallable[[_T], _T]c                   s   d fdd}|S )z2Decorator to capture errors and display the stack.funcr6   r@   c                   s   t  d fdd}|S )Nargsr-   kwargsr@   c                    sL   z| i |W S  t y% } ztdj d | i | |d }~ww )NzError calling z with: )	Exceptionr)   r8   )rC   rD   e)r>   rB   r<   r=   wrappera   s   z3_capture_errors.<locals>.decorator.<locals>.wrapper)rC   r-   rD   r-   r@   r-   )	functoolswraps)rB   rG   r>   )rB   r=   	decorator`   s   z"_capture_errors.<locals>.decoratorN)rB   r6   r@   r6   r<   )r>   rK   r<   rJ   r=   _capture_errors]   s   rL   np.dtypec                 C  s   t | dS )zCreate a small endian dtype on all platforms.

    This is useful because ONNX always stores raw_data in small endian. On big
    endian platforms, we still need to interpret the raw_data in small endian.
    <)npdtypenewbyteorderrP   r<   r<   r=   _little_endian_dtypeo   s   rS   protoonnx.ModelProto_core.Modelc                 C     d S Nr<   rT   r<   r<   r=   r   x      r   onnx.GraphProto_core.Graphc                 C  rW   rX   r<   rY   r<   r<   r=   r   z   rZ   onnx.NodeProto
_core.Nodec                 C  rW   rX   r<   rY   r<   r<   r=   r   |   rZ   onnx.TensorProto_protocols.TensorProtocolc                 C  rW   rX   r<   rY   r<   r<   r=   r   ~   rZ   onnx.AttributeProto
_core.Attrc                 C  rW   rX   r<   rY   r<   r<   r=   r      rZ   onnx.ValueInfoProto_core.Valuec                 C  rW   rX   r<   rY   r<   r<   r=   r      rZ   onnx.TypeProto_core.TypeAndShapec                 C  rW   rX   r<   rY   r<   r<   r=   r      rZ   onnx.FunctionProto_core.Functionc                 C  rW   rX   r<   rY   r<   r<   r=   r      rZ   onnx.TensorShapeProto_core.Shapec                 C  rW   rX   r<   rY   r<   r<   r=   r      rZ   onnx.TensorShapeProto.Dimension*tuple[int | _core.SymbolicDim, str | None]c                 C  rW   rX   r<   rY   r<   r<   r=   r      s   !Sequence[onnx.OperatorSetIdProto]dict[str, int]c                 C  rW   rX   r<   rY   r<   r<   r=   r      rZ   %Sequence[onnx.StringStringEntryProto]dict[str, str]c                 C  rW   rX   r<   rY   r<   r<   r=   r      rZ   objectc                 C  s4  t | tjr
t| S t | tjrt| S t | tjrt| S t | tjr(t	| S t | tj
r2t| S t | tjr=t| dS t | tjrMtt| t| S t | tjrWt| S t | tjrat| S t | tjjrlt| S t | tr~tdd | D r~t| S t | trtdd | D rt| S tdt|  d)z2Deserialize an ONNX proto message to an IR object.Nc                 s      | ]	}t |tjV  qd S rX   )
isinstanceonnxOperatorSetIdProto.0pr<   r<   r=   	<genexpr>       
zfrom_proto.<locals>.<genexpr>c                 s  rr   rX   )rs   rt   StringStringEntryProtorv   r<   r<   r=   ry      rz   zDeserialization of zY in from_proto is not implemented. Use a specific ir.serde.deserialize* function instead.)rs   rt   
ModelProtor   
GraphProtor	   	NodeProtor   TensorProtor   AttributeProtor   ValueInfoProtor   	TypeProtor0   TypeAndShaper   r   FunctionProtor   TensorShapeProtor   	Dimensionr   r,   allr   r
   NotImplementedErrortyperY   r<   r<   r=   r      sD   
initializers*Iterable[_protocols.TensorProtocol] | None
model_textstrc                C  s|   t j| }t|}t|j}|r<|D ]'}|j}|s"td| ||vr.td| d|| }||_	|j
| q|S )a  Convert the ONNX textual representation to an IR model.

    Read more about the textual representation at: https://onnx.ai/onnx/repo-docs/Syntax.html

    .. versionchanged:: 0.1.2
        Added the ``initializers`` argument.

    Args:
        model_text: The ONNX textual representation of the model.
        initializers: Tensors to be added as initializers. If provided, these tensors
            will be added to the model as initializers. If a name does not exist in the model,
            a ValueError will be raised.

    Returns:
        The IR model corresponding to the ONNX textual representation.

    Raises:
        ValueError: If a tensor name in `initializers` does not match any value in the model.
    zPInitializer tensor must have a name. Please provide a name for the initializer: zValue 'z' does not exist in model.)rt   parserparse_modelr   r/   create_value_mappinggraphname
ValueErrorconst_valueregister_initializer)r   r   rT   modelvaluestensorr   initializerr<   r<   r=   r      s$   r   Fexclude_initializersboolr   _protocols.ModelProtocolc                C  s*   t | }|r|jjdd= tj|}|S )a-  Convert the IR model to the ONNX textual representation.

    .. versionadded:: 0.1.2

    Args:
        model: The IR model to convert.
        exclude_initializers: If True, the initializers will not be included in the output.

    Returns:
        The ONNX textual representation of the model.
    N)r   r   r   rt   printerto_text)r   r   rT   textr<   r<   r=   r      s
   r   	ir_objectc                 C  rW   rX   r<   r   r<   r<   r=   r      rZ   r   _protocols.GraphProtocolc                 C  rW   rX   r<   r   r<   r<   r=   r      rZ   _protocols.NodeProtocolc                 C  rW   rX   r<   r   r<   r<   r=   r      rZ   c                 C  rW   rX   r<   r   r<   r<   r=   r     rZ   _protocols.AttributeProtocolc                 C  rW   rX   r<   r   r<   r<   r=   r     rZ   %_protocols.ReferenceAttributeProtocolc                 C  rW   rX   r<   r   r<   r<   r=   r     rZ   _protocols.ValueProtocolc                 C  rW   rX   r<   r   r<   r<   r=   r     rZ   _protocols.TypeProtocolc                 C  rW   rX   r<   r   r<   r<   r=   r   
  rZ   _protocols.FunctionProtocolc                 C  rW   rX   r<   r   r<   r<   r=   r     rZ   _protocols.GraphViewProtocolc                 C  rW   rX   r<   r   r<   r<   r=   r     rZ   c                 C  s   t | tjr
t| S t | tjrt| S t | tjrt| S t | tjr(t	| S t | tj
r2t| S t | tjr@|  s@t| S t | tjrP|  sLJ t| S t | tjr]tt | S t | tjrgt| S t | tjrqt| S tdt|  d)z"Serialize an IR object to a proto.zSerialization of zU in to_proto is not implemented. Use a specific ir.serde.serialize* function instead.)rs   r2   ModelProtocolr   GraphProtocolr   NodeProtocolr   TensorProtocolr$   ValueProtocolr(   AttributeProtocolis_refr   ReferenceAttributeProtocolr"   TypeProtocolr%   rt   r   GraphViewProtocolFunctionProtocolr   r   r   r   r<   r<   r=   r     s0   c                      s   e Zd ZdZdZd- fddZed.d
dZejd/ddZed0ddZ	ed1ddZ
ed.ddZed2ddZd.ddZd3d4dd Zdd!d5d#d$Zd6d&d'Zd7d(d)Zd8d+d,Z  ZS )9r   z)A tensor initialized from a tensor proto._protorT   r_   r@   Nonec                   s   t  jt|jd || _d S )N)metadata_props)super__init__r
   r   r   )selfrT   	__class__r<   r=   r   4  s   
zTensorProtoTensor.__init__r   c                 C     | j jS rX   )r   r   r   r<   r<   r=   r   8     zTensorProtoTensor.namevalue
str | Nonec                 C  s$   |d u r| j d d S || j _d S )Nr   )r   
ClearFieldr   )r   r   r<   r<   r=   r   <  s   rj   c                 C  s   t j| jjddS )NT)frozen)r0   Shaper   dimsr   r<   r<   r=   shapeC  s   zTensorProtoTensor.shape_enums.DataTypec                 C  s   t | jjS rX   )r1   DataTyper   	data_typer   r<   r<   r=   rP   G     zTensorProtoTensor.dtypec                 C  r   rX   )r   
doc_stringr   r<   r<   r=   r   K  r   zTensorProtoTensor.doc_stringc                 C     | j S rX   r   r   r<   r<   r=   rawO  s   zTensorProtoTensor.rawc                 C  sb   | j dkr&t|  d}ddd |D }|   d| d| jdS |   d	| jdS )
Nr4   
 c                 s  s    | ]}|  V  qd S rX   )strip)rw   liner<   r<   r=   ry   V  s    z-TensorProtoTensor.__repr__.<locals>.<genexpr>(z, name=)z(name=)sizereprnumpysplitjoin
_repr_baser   )r   tensor_linestensor_textr<   r<   r=   __repr__S  s
   
zTensorProtoTensor.__repr__NrP   r-   
np.ndarrayc                 C  s   |   |S )z=Return the tensor as a numpy array, compatible with np.array.)r   	__array__)r   rP   r<   r<   r=   r   Z  r   zTensorProtoTensor.__array__streamr   c                C  s   |   j|dS )Nr   )r   
__dlpack__)r   r   r<   r<   r=   r   ^  s   zTensorProtoTensor.__dlpack__tuple[int, int]c                 C  s   |    S rX   )r   __dlpack_device__r   r<   r<   r=   r   a  s   z#TensorProtoTensor.__dlpack_device__c                 C  s  | j }|tjjkrtd| jjtjj	krtd| jj
}| jdrd|jdkr;ttj| jjtjd|| S |jdkrSttj| jjtjd|| S tj| jj| dd|S |tjjkrtt| jj|S | jjr,|tjjtjjtjjtjjtjj tjj!tjj"tjj#tjj$tjj%tjj&tjj'tjj(tjj)tjj*tjj+tjj,tjj-hv sJ d| d	tj| jjt.tj/d}|jd
kr||S |jdkr|0tj1| |S |jdkr|0tj| |S |jdkrt|0tj|| S |jdkr!t|0tj|| S td| d|j | jj2rP|tjj3hv sAJ d| dtj| jj2t.tj4d|S | jj5r|tjj6tjj7hv shJ d| dtj| jj5t.tj8d}|tjj7kr|0tj9|S ||S | jj:r|tjj;tjj<hv sJ d| dtj| jj:t.tj=d}|tjj<kr|tj>|S ||S | jj?r|tjj@tjjAhv sJ d| dtj| jj?t.tjBd}|tjjAkr|tjC|S ||S tjD|| dS )a  Return the tensor as a numpy array.

        This is an improved version of onnx.numpy_helper.to_array.
        It first reads the data using the dtype corresponding to the tensor
        proto data field, then converts it to the correct dtype and shape.
        Special cases are bfloat16, complex and int4 where we need to
        reinterpret the data. Other types can simply be casted.

        When the data type is not supported by numpy, the dtypes from the ``ml_dtype``
        package are used. The values can be reinterpreted as bit representations
        using the ``.view()`` method.

        When the data type is a string, this method returns a numpy array
        of bytes instead of a numpy array of strings, to follow the ONNX
        specification.

        External tensors are not supported by this class. Use
        :class:`onnx_ir.ExternalTensor` instead.

        Raises:
            ValueError: If the data type is UNDEFINED.
        z/Cannot convert UNDEFINED tensor to numpy array.zMCannot convert external tensor to numpy array. Use ir.ExternalTensor instead.raw_data   rR      rN   zUnsupported dtype z for int32_data          z for int32_data with bitwidth z for int64_dataz for uint64_dataz for float_dataz for double_data)ErP   r1   r   	UNDEFINEDr   r   data_locationrt   r   EXTERNALr   HasFieldbitwidthr3   unpack_4bitx2rO   
frombufferr   uint8viewr   unpack_2bitx4rQ   reshapeSTRINGarraystring_data
int32_dataBFLOAT16BOOLFLOAT16
FLOAT4E2M1FLOAT8E4M3FNFLOAT8E4M3FNUZ
FLOAT8E5M2FLOAT8E5M2FNUZ
FLOAT8E8M0INT16INT32INT2INT4INT8UINT16UINT2UINT4UINT8rS   int32astypeuint16
int64_dataINT64int64uint64_dataUINT64UINT32uint64uint32
float_dataFLOAT	COMPLEX64float32	complex64double_dataDOUBLE
COMPLEX128float64
complex128zeros)r   rP   r   r   r<   r<   r=   r   d  s   
























zTensorProtoTensor.numpybytesc                 C  s  | j jtjjkrtd| jtjj	krtd| jtjj
kr"td| j dr,| j jS | j jr>tj| j jttjd S | j jrtj| j jtjd}| jtjjtjjtjjtjjhv rg|ttj S | jtjjtjjtjjtjjtjjtjj tjj!tjj"tjj#tjj$tjj%tjj&tjj'hv r|ttj( S | jtjj)ksJ | S | j j*rtj| j j*ttj+d S | j j,rtj| j j,ttj-d S | j j.rtj| j j.ttj/d}| jtjj0kr|ttj1 S | jtjj2ksJ | S dS )a  Return the tensor as a byte string conformed to the ONNX specification, in little endian.

        Raises:
            ValueError: If the tensor is a string tensor or an external tensor.
            ValueError: If the tensor is of UNDEFINED data type.
        zGCannot convert external tensor to bytes. Use ir.ExternalTensor instead.z&Cannot convert string tensor to bytes.z)Cannot convert UNDEFINED tensor to bytes.r   rR       )3r   r   rt   r   r   r   rP   r1   r   r   r   r   r   r  rO   r   rS   r  tobytesr   r  r  r  r   r   r  r  r  r  r   r   r   r   r  r  r  r  r	  r
  r   r   r  r  r  r  r  r  r  r  r  r  )r   r   r<   r<   r=   r$    s|   zTensorProtoTensor.tobytes)rT   r_   r@   r   )r@   r   )r   r   r@   r   )r@   rj   )r@   r   )r@   r_   rX   )rP   r-   r@   r   )r   r-   r@   r-   )r@   r   )r@   r   )r@   r"  )r8   r9   r:   r;   	__slots__r   propertyr   setterr   rP   r   r   r   r   r   r   r   r$  __classcell__r<   r<   r   r=   r   /  s,    


}r   r-   fieldc                 C  s   |  |r
t| |S d S rX   )r   getattr)rT   r)  r<   r<   r=   
_get_field'  s   

r+  protosc                 C  s   dd | D S )zDeserialize a sequence of OperatorSetIdProto to opset imports mapping.

    Args:
        protos: The sequence of ONNX OperatorSetIdProto objects.

    Returns:
        A dictionary mapping domain strings to version integers.
    c                 S     i | ]}|j |jqS r<   domainversion)rw   opsetr<   r<   r=   
<dictcomp>;      z,deserialize_opset_import.<locals>.<dictcomp>r<   )r,  r<   r<   r=   r   0  s   r   r   tuple[str, str, str] | Nonec                 C  sR   |  d}d}t||krdS |\}}| d}t||kr dS |\}}|||fS )aw  Get the function domain, name and value name if the value info is for a function.

    The experimental format is:
    {function_domain}::{function_name}/{value_name}

    Args:
        name: The name stored in the value info.

    Returns:
        A tuple of the function domain, function name and value name if the value info is for a function.
        None otherwise.
    /r   N::)r   len)r   partsexpected_partsfunction
value_namefunction_domainfunction_namer<   r<   r=   ,_parse_experimental_function_value_info_name>  s   


r>  c                 C  s   t | jg }|jt| j g }| jD ]	}|t| qt	j
|| jt| dt| dt| dt| dt| d|t| jd	}|jtk rLt|j| jj |S )zDeserialize an ONNX ModelProto into an IR Model.

    Args:
        proto: The ONNX ModelProto to deserialize.

    Returns:
        An IR Model object representing the ONNX model.
    producer_nameproducer_versionr/  model_versionr   )
ir_versionr?  r@  r/  rA  r   	functionsr   )_deserialize_graphr   opset_importsupdater   opset_importrC  appendr   r0   ModelrB  r+  r
   r   &_FUNCTION_VALUE_INFO_SUPPORTED_VERSION6_deserialized_experimental_value_info_for_function_ir9
value_info)rT   r   rC  rB   r   r<   r<   r=   r   [  s*   	


r   rC  6Mapping[_protocols.OperatorIdentifier, _core.Function]value_info_protosSequence[onnx.ValueInfoProto]r   c                 C  s   t t}|D ]0}t|j }du rq|\}}}d}|||f}	| |	}
|
du r1td|	|j q|||	 |< q|  D ]7\}	}
|
j	D ]}|j||	 v rVt
||	 |j | qC|
D ]}|jD ]}|j||	 v rqt
||	 |j | q^qYq<dS )zDeserialize value info for functions when they are stored in an experimental format.

    The experimental format is:
    {function_domain}::{function_name}/{value_name}
    N zTFunction with ID '%s' not found in model functions. Value info '%s' will be ignored.)collectionsdefaultdictdictr>  r   getloggerdebugitemsinputsr   outputs)rC  rN  !function_value_value_info_mappingvalue_info_protoparsedr<  r=  r;  function_overloadfunction_idr:  inputnodeoutputr<   r<   r=   rK    sJ   




rK  c                 C  
   t | g S )zDeserialize a graph proto, recursively if needed.

    Args:
        proto: The graph proto to deserialize.

    Returns:
        IR Graph.

    .. versionadded:: 0.1.3
        Support for `quantization_annotation` is added.
    rD  rY   r<   r<   r=   r	     s   
r	   c                 C  r   rX   r   rT   scoped_valuesr<   r<   r=   <lambda>      rg  rf  list[dict[str, _core.Value]]c              	     s  dd | j D  dd | jD }t| j|D ]\}}t|| |j v r,t |j | qdd |D }| dd | jD dd | jD }g }t	|D ]M\}}	|	j}
|
s_t
d| qO|
|v rk||
 }|	|_n,tjd	d	|
t|	j|	j|	d
}|
v rt|
 | |j v rt |j | |||
< || qO| jD ]
}t|| d q fdd| jD }g }| jD ]$}|j}||vrt
d| tj|d}n|| }t|| || q  tj||||t| dt| dt| jdS )a  Deserialize a graph proto, recursively if needed.

    Args:
        proto: The graph proto to deserialize.
        scoped_values: A list of dictionaries mapping value names to their corresponding Value objects.
            Every time we enter a new graph, a new scope is created and appended to this list to include
            all values defined in the scope.
        scoped_value_info: A list of dictionaries mapping value names to their corresponding ValueInfoProto.

    Returns:
        IR Graph.
    c                 S     i | ]}|j |qS r<   )tensor_name)rw   
annotationr<   r<   r=   r2        z&_deserialize_graph.<locals>.<dictcomp>c                 S  s   g | ]	}t j|jd qS rd  )r0   Valuer   rw   infor<   r<   r=   
<listcomp>  s    z&_deserialize_graph.<locals>.<listcomp>c                 S  rj  r<   rd  rw   vr<   r<   r=   r2        c                 S  rj  r<   rd  rp  r<   r<   r=   r2    ru  c                 S     g | ]}t |qS r<   r   )rw   r   r<   r<   r=   rr    ru  zbInitializer tensor must have a name but the %s-th initializer does not. Skipping this initializer.N)indexr   r   r   r   rL  quantization_annotationsc                   s   g | ]	}t | qS r<   _deserialize_noderw   r`  rz  rf  rL  r<   r=   rr    s    zHOutput '%s' is not produced by any node. The graph has an invalid outputrd  r   r   )nodesr   r   r   r   )quantization_annotationr_  zipr   r   $_deserialize_quantization_annotationrH  rL  r   	enumeraterU  warningr   r0   ro  
TensorTyperP   r   r`  _declare_node_outputsra  popGraphr+  r
   r   )rT   rf  rX  rq  r   r   initializer_tensorsinitializer_valuesir   initializer_nameinitializer_valuer`  r  rY  output_namer<   r~  r=   rD    s   









rD  current_value_scopedict[str, _core.Value]rL  dict[str, onnx.ValueInfoProto]rz   dict[str, onnx.TensorAnnotation]c                 C  s   | j D ]K}|dkr
q||v r#td| d||  d| j d| j d	tj|d}|||< ||v r9t|| | n
td|| j| j ||v rNt	|| | qd	S )
a  Declare outputs for a node in the current graph scope.

    This is necessary to handle the case where a node in a subgraph uses a value that is declared
    out of order in the outer graph. Declaring the values first allows us to find the values later
    when deserializing the nodes in subgraphs.

    Args:
        proto: The ONNX NodeProto to declare outputs for.
        current_value_scope: The current scope of values, mapping value names to their corresponding Value objects.
        value_info: A dictionary mapping value names to their corresponding ValueInfoProto.
        quantization_annotations: A dictionary mapping tensor names to their corresponding TensorAnnotation.

    Raises:
        ValueError: If an output name is redeclared in the current graph scope.
    rP  Output 'zA' is redeclared in the current graph scope. Original declaration z . New declaration: by operator 'z' of node 'z'. The model is invalidrd  zBValueInfoProto not found for output '%s' in node '%s' of type '%s'N)
ra  r   op_typer   r0   ro  r   rU  rV  r  )rT   r  rL  rz  r  r   r<   r<   r=   r  =  s6   
r  c                 C  r   rX   rd  rY   r<   r<   r=   rg  n  rh  c              
     s  dd | j D }dd |D dd t| dg D  | jD ]
}t| i d q fdd| jD }fd	d| jD }tj|||d
t| dt| j	t
| drb| jrb| j d| j d| j  ndt| jd}dd | jD }|dd | jD 7 }tj| j| jt| dd||dS )zDeserialize an ONNX FunctionProto into an IR Function.

    Args:
        proto: The ONNX FunctionProto to deserialize.

    Returns:
        An IR Function object representing the ONNX function.
    c                 S  s   g | ]}t j|d qS rn  )r0   ro  rw   r   r<   r<   r=   rr  x  s    z(deserialize_function.<locals>.<listcomp>c                 S  rj  r<   rd  rs  r<   r<   r=   r2  y  ru  z(deserialize_function.<locals>.<dictcomp>c                 S  rj  r<   rd  rp  r<   r<   r=   r2  z  ru  rL  ry  c                   s   g | ]}t |g i d qS )ry  r{  r}  rL  r   r<   r=   rr    s    c                   s   g | ]} | qS r<   r<   r  )r   r<   r=   rr    ru  r<   r   overload___rP  )r  r   r   rE  r   r   c                 S  s   g | ]}t |g qS r<   _deserialize_attribute)rw   attrr<   r<   r=   rr    r3  c                 S  s   g | ]}t |tjjd qS rX   )r0   Attrr1   AttributeTyper   r  r<   r<   r=   rr    s    )r/  r   r  r   
attributes)r_  r*  r`  r  ra  r0   r  r+  r   rG  hasattrr  r   r/  r
   r   attribute_proto	attributeFunction)rT   rX  r`  r  rY  r   r  r<   r  r=   r   n  sN   

 
r   c                 C     t | S rX   r   rT   r   r<   r<   r=   rg        r   _core.Value | Nonec                 C  s\   |du rt j| jd}t| j|_t| j|_t| j}|dur&|j	| t
| d|_|S )a'  Deserialize an ONNX ValueInfoProto into an IR Value.

    Args:
        proto: The ONNX ValueInfoProto to deserialize.
        value: An existing Value to update, or None to create a new one.

    Returns:
        An IR Value object with type and shape information populated from the proto.
    Nrd  r   )r0   ro  r   r   r   r   r   r
   r   rF  r+  r   )rT   r   r   r<   r<   r=   r     s   
r   c                 C  r  rX   r  r  r<   r<   r=   rg    r  onnx.TensorAnnotationc                 C  s   t | j|jt< dS )zDeserialize a quantization_annotation as TensorAnnotation into a Value.

    This function is marked private because we don't expect users to call it directly.
    N)_deserialize_string_string_mapsr5   meta#_QUANT_PARAMETER_TENSOR_NAMES_FIELDr  r<   r<   r=   r    s   r  c                 C  s@   | j }dd |D }dd |D }dd |D }tj||ddS )zDeserialize an ONNX TensorShapeProto into an IR Shape.

    Args:
        proto: The ONNX TensorShapeProto to deserialize.

    Returns:
        An IR Shape object representing the tensor shape.
    c                 S  rv  r<   )r   )rw   	dim_protor<   r<   r=   rr    rm  z,deserialize_tensor_shape.<locals>.<listcomp>c                 S  s   g | ]\}}|qS r<   r<   )rw   dimr  r<   r<   r=   rr    ru  c                 S  s   g | ]\}}|qS r<   r<   )rw   r  
denotationr<   r<   r=   rr    ru  T)denotationsr   )r  r0   r   )rT   
dim_protosdeserialized_dim_denotationsr   r  r<   r<   r=   r     s   r   _core.Shape | Nonec                 C  s   |  drt| jd }du rdS t|S |  dr*t| jd }du r&dS t|S |  dr?t| jd }du r;dS t|S |  drTt| jd }du rPdS t|S |  dr`td	t	 dS )
zExtract and deserialize shape information from an ONNX TypeProto.

    Args:
        proto: The ONNX TypeProto to extract shape from.

    Returns:
        An IR Shape object if shape information is present, None otherwise.
    tensor_typer   Nsparse_tensor_typesequence_type	elem_typeoptional_typemap_type!Map types are not supported yet. )
r   r+  r  r   r  r  r   r  r   _PLEASE_CONTRIBUTE)rT   shape_protor  r<   r<   r=   r     s&   





r   _protocols.TypeProtocol | Nonec                 C  sB  t | d}| dr t | jd }du rdS tjt||dS | dr;t | jd }du r1dS tjt||dS | drgt | j	d }du rQt
d|  t|}|du r`t
d	|  tj||dS | d
rt | jd }du r}t
d|  t|}|du rt
d	|  tj||dS | drtdt dS )a  Extract and deserialize type information from an ONNX TypeProto.

    Args:
        proto: The ONNX TypeProto to extract type from.

    Returns:
        An IR type object (TensorType, SequenceType, etc.) if type information is present, None otherwise.
    r  r  r  N)r  r  r  z+SequenceTypeProto must have elem_type set: z&SequenceType must have elem_type set: r  r  r  )r+  r   r  r0   r  r1   r   r  SparseTensorTyper  r   r   SequenceTyper  OptionalTyper   r  )rT   r  r  nested_typer<   r<   r=   r     s4   





r   c                 C  sZ   |  d}t| d}|dur&t| |}|dkr||fS |dkr&t||fS td|fS )zDeserialize a dimension proto into (dimension, denotation).

    Args:
        proto: The dimension proto to deserialize.

    Returns:
        A tuple of the dimension and its denotation.
    r   r  N	dim_value	dim_param)
WhichOneofr+  r*  r0   SymbolicDim)rT   value_fieldr  r   r<   r<   r=   r   +  s   


r   c                 C  r   rX   rd  )rT   	base_pathr<   r<   r=   rg  B  rh  rP  r  str | os.PathLikec                 C  s   | j tjjkr/tj| }tj|j|j	|j
t| j|t| dt| jt| dt| jd	S | jtjjkrTt| d}t| d}t| j}tj| jt| j|||dS t| S )Nr   r   )offsetlengthrP   base_dirr   r   r   r   )r   r   r   r   )r   rt   r   r   external_data_helperExternalDataInfor0   ExternalTensorlocationr  r  r1   r   r   r+  r   r   r
   r   r   StringTensorr   r   )rT   r  external_infor   r   r   r<   r<   r=   r   B  s2   





r   dict[str, str] | Nonec                 C  s   t | dkrd S dd | D S )Nr   c                 S  r-  r<   keyr   )rw   entryr<   r<   r=   r2  h  r3  z.deserialize_metadata_props.<locals>.<dictcomp>)r7  rY   r<   r<   r=   r
   b  s   r
   c                 C  rb  )zDeserialize an ONNX AttributeProto into an IR Attribute.

    Args:
        proto: The ONNX AttributeProto to deserialize.

    Returns:
        An IR Attribute object representing the ONNX attribute.
    r  rY   r<   r<   r=   r   n  s   
	r   c                 C  r  rX   r  re  r<   r<   r=   rg  z  r  c           
   	     s  | j }t| d}t| j}t| d}|rtj||||dS |tjjkr-tj|| j	|dS |tjj
kr<tj|| j|dS |tjjkriztj|| jd|dW S  tyh   td| tj||| j|d Y S w |tjjkrxtj|| j|dS |tjjkrtj|| j|dS |tjjkrtj|dd | jD |dS |tjjkrtj|t | j!|dS |tjj"krtj#|t$| j% |dS |tjj&krtj'|dd | j(D |dS |tjj)krtj*| fd	d| j+D |dS |tjj,krt-d
t. |tjj/krt-d
t. |tjj0kr t1| j2}t3| j2}tj4|t5|||dS |tjj6krIg }| j7D ]}	t1|	}t3|	}|8t5|| q,tj9|||dS |tjj:krYtj||d |dS t;d| d)Nr   ref_attr_name)r   utf-8zAttribute %r contains invalid UTF-8 bytes. ONNX spec requires string attributes to be UTF-8 encoded so the model is invalid. We will skip decoding the attribute and use the bytes as attribute valuec                 S     g | ]}| d qS r  )decoderw   sr<   r<   r=   rr    r3  z*_deserialize_attribute.<locals>.<listcomp>c                 S  rv  r<   rw  )rw   tr<   r<   r=   rr    ru  c                      g | ]}t | qS r<   rc  )rw   grf  r<   r=   rr    r3  &Sparse tensors are not supported yet. zUnsupported attribute type: '')<r   r+  r1   r  r   r0   RefAttrINT	AttrInt64r  r  AttrFloat32fr   
AttrStringr  r  UnicodeDecodeErrorrU  r  r  INTS
AttrInt64sintsFLOATSAttrFloat32sfloatsSTRINGSAttrStringsstringsTENSOR
AttrTensorr   r  GRAPH	AttrGraphrD  r  TENSORSAttrTensorstensorsGRAPHS
AttrGraphsgraphsSPARSE_TENSORr   r  SPARSE_TENSORS
TYPE_PROTOr   tpr   AttrTypeProtor   TYPE_PROTOStype_protosrH  AttrTypeProtosr   r   )
rT   rf  r   r   type_r  ir_typer   type_and_shapes
type_protor<   r  r=   r  z  s   




r  c                 C  s&   i }t | |i i d t| |gi i dS )zDeserialize an ONNX NodeProto into an IR Node.

    Args:
        proto: The ONNX NodeProto to deserialize.

    Returns:
        An IR Node object representing the ONNX node.
    ry  )rf  rL  rz  )r  r|  )rT   value_scoper<   r<   r=   r     s   	
r   c                 C  r  rX   r  )rT   rf  rL  rz  r<   r<   r=   rg    r  c                   s  g }| j D ]l}|dkr|d  qd}t D ]}||vrq|||  d}~ |sqtd|| j| j| jt| ddt	  t	 dkrJtd t
j|d}||v r[t|| | ||v rft|| | || | d	 |< qg }	| jD ])}
|
dkr|	t
jdd qw d	 }|
|v sJ d
|
 d||
 }|	| qwt
j| j| j| fdd| jD t| dd|	| jt| dt| jd	S )NrP  FTzInput '%s' of node '%s' (%s::%s:%s) cannot be found in any scope. The model is invalid but we will still create a new input for the node (current depth: %s)r     zCaveat: The value is created in the subgraph. If the node is referencing a value that is not in the current graph, it is impossible to create it in the correct scope.rd  r  z4' not found in the current scope. This is unexpectedc                   r  r<   r  )rw   ar  r<   r=   rr  7  r3  z%_deserialize_node.<locals>.<listcomp>r   )r  rY  r   r   r   )r_  rH  reversedrU  r  r   r/  r  r*  r7  r0   ro  r   r  ra  Noder  r+  r
   r   )rT   rf  rL  rz  node_inputs
input_namefoundr   r   node_outputsr  current_scoper<   r  r=   r|    sv   








r|  c                 C  s   t t | dS )zSerialize an IR Model to an ONNX ModelProto.

    Args:
        model: The IR Model to serialize.

    Returns:
        The serialized ONNX ModelProto object.
    from_)r   rt   r|   )r   r<   r<   r=   r   C  s   	r   c              	   C  s&   d|j  d|j d|j d|j d	S )Nzir_version=z, producer_name=z, producer_version=z	, domain=z, )rB  r?  r@  r/  )model_protor  r<   r<   r=   rg  P  s
   r  r  c                 C  s   |j | _ |jr|j| _|jr|j| _|jr|j| _|jr |j| _|jr'|j| _t| j|j |j	r8t
| j	|j	 t| j|j |j tk}|j D ]}t| j ||d |s]t| j| qI| S )z-Serialize an IR model to an ONNX model proto.r  create_value_info)rB  r?  r@  r/  rA  r   _serialize_opset_imports_intorG  rE  r   _serialize_metadata_props_intor   r   rJ  rC  r   r   add8_serialize_experimental_value_info_for_function_ir9_into)r  r  create_value_info_in_functionsrB   r<   r<   r=   r   O  s4   

r   c                 C  s>   | j du r| jdu r| js| jsdS | jstd|  dS dS )zCheck if value info should be created for a value.

    Args:
        value: The value to check.

    Returns:
        True if value info should be created for the value.
    NFz0Did not serialize '%s' because its name is emptyT)r   r   r   r   r   rU  rV  )r   r<   r<   r=   #_should_create_value_info_for_valuew  s   

r  graph_protor:  c                   s   |j  d|j  d fdd}|jD ]}|js td | qt|s%qt| j |||jd q|D ]%}|j	D ]}|jsGtd	 | q:t|sLq:t| j |||jd q:q5d
S )a  Serialize value info for functions in an experimental format for IR version 9.

    Because IRv9 and older does not have ValueInfoProto for functions, we give the value info
    special names and store them in the main graph instead.

    The experimental format is:
    {function_domain}::{function_name}/{value_name}

    Args:
        graph_proto: The graph proto to create ValueInfoProto in.
        function: The function to serialize.
    r6  r;  r   r@   c                   s     d|  S )Nr5  r<   )r;  function_qualified_namer<   r=   format_name  s   zM_serialize_experimental_value_info_for_function_ir9_into.<locals>.format_namez8Function '%s': Value name not set for function input: %srd  z5Function '%s': Value name not set for node output: %sN)r;  r   r@   r   )
r/  r   rX  rU  r  r  r'   rL  r  rY  )r  r:  r"  r_  r`  node_outputr<   r   r=   r    s>   

r  	opset_idsIproto_containers.RepeatedCompositeFieldContainer[onnx.OperatorSetIdProto]Mapping[str, int]c                 C  s$   |  D ]\}}| j||d qdS )zSerialize opset imports into a repeated field of OperatorSetId protos.

    Args:
        opset_ids: The repeated field to serialize into.
        from_: The mapping of opset domains to versions to serialize.
    r.  N)rW  r  )r$  r  r/  r0  r<   r<   r=   r    s   r  string_string_entriesMproto_containers.RepeatedCompositeFieldContainer[onnx.StringStringEntryProto]Mapping[str, str]c                 C  s$   t |D ]}| j||| d qdS )zSerialize a <str, str> mapping into a repeated field of string-string entries.

    Args:
        string_string_entries: The repeated field to serialize into.
        from_: The mapping of a <str, str> mapping to serialize.
    r  N)sortedr  )r'  r  r  r<   r<   r=   _serialize_string_string_maps  s   r+  c                 C  s,   |j t }rt| j |j| d S d S rX   )r  rT  r  !_serialize_tensor_annotation_intor  r  r   )r  r   r  r<   r<   r=   "_maybe_add_quantization_annotation  s
   r-  tensor_annotation_protork  c                 C  s   || _ t| j| d S rX   )rk  r+  r5   )r.  rk  r5   r<   r<   r=   r,    s   r,  r   7_protocols.GraphProtocol | _protocols.GraphViewProtocolc                 C     t  }t|| d |S )a
  Serializes the given graph into an :class:`onnx.GraphProto`.

    When the graph initializers do not have `const_value` set, they will be skipped.

    Args:
        graph: The graph to be serialized.

    Returns:
        The serialized ONNX GraphProto object.
    r  )rt   r}   r   )r   r  r<   r<   r=   r     s   r   c                 C  sJ   d|j  d|j dt|j dt|j dt| dt|j d|j S )Nzname=z, doc_string=z, len(inputs)=z, len(initializers)=z, len(nodes)=z, len(outputs)=z, metadata_props=)r   r   r7  rX  r   rY  r   )r  r  r<   r<   r=   rg    s   c                 C  sl  |j r|j | _ |jr|j| _|jD ]}t| j | |j |jvr&t| | qdd |jD }|j D ]4}t| | t	|rL|j |vrLt| j
 | |jd u rYtd|j  q4|j |j_ t| j |jd q4|D ](}t| j |d |jD ]}| rqyt| | t	|sqyt| j
 | qyqk|jD ]}t| j |d t| | q|jrt| j|j d S d S )Nc                 S  s   h | ]}|j qS r<   rd  )rw   input_r<   r<   r=   	<setcomp>   s    z'serialize_graph_into.<locals>.<setcomp>z4Initializer '%s' does not have a constant value set.r  )r   r   rX  r'   r_  r  r   r-  r   r  rL  r   rU  r  r#   r   r   r`  rY  is_graph_outputra  r   r  )r  r  r1  input_namesr   r`  r#  ra  r<   r<   r=   r     sF   








r   T)r  r  c                C     t  }t|| |d |S )a   Serialize an IR function as a FunctionProto.

    Args:
        function: The function to serialize.
        create_value_info: Whether to create ValueInfoProto for nodes in the function. This is supported
            starting from ONNX IR version 10.
    r  )rt   r   r   )r:  r  function_protor<   r<   r=   r   B  s
   
r   c                 C     t |S rX   r   )r6  r  r  r<   r<   r=   rg  S  r  r6  c                C  s<  |j r|j | _ |jr|j| _|jr|j| _|jr|j| _|jr&t| j|j |jr0t| j|j |j	D ]}| j
|j t|sAq3|sDq3t| j | q3|j D ]}|jdurct| j |d qR| j|j qR|jD ]	}| j|j qn|D ]!}t| j |d |jD ]}t|sq|sqt| j | qqzdS )a4  Serialize an IR function into a FunctionProto.

    Args:
        function_proto: The proto to serialize into.
        from_: The function to serialize.
        create_value_info: Whether to create ValueInfoProto for nodes in the function. This is supported
            starting from ONNX IR version 10.
    Nr  )r/  r   r  r   rE  r  rG  r   r  rX  r_  rH  r  r'   rL  r  r  r   r   r   r  r  rY  ra  r   r`  )r6  r  r  r1  r  func_outputr`  r#  r<   r<   r=   r   S  sF   



r   r`  c                 C  r0  )zSerialize an IR Node to an ONNX NodeProto.

    Args:
        node: The IR Node to serialize.

    Returns:
        The serialized ONNX NodeProto object.
    r  )rt   r~   r   )r`  
node_protor<   r<   r=   r        	r   rY  "Sequence[_protocols.ValueProtocol]c                 C  s8   t t| D ]\}}|jr| dt| |    S qg S )zRemove trailing outputs that have empty names.

    Args:
        outputs: The outputs to remove trailing outputs from.

    Returns:
        The outputs with trailing outputs removed.
    N)r  r  r   r7  )rY  r  ra  r<   r<   r=   _remove_trailing_outputs  s
   r=  c                 C  r7  rX   r8  )r:  r  r<   r<   r=   rg    r  r:  c                 C  s   |j | _ |jr|j| _|jr|j| _|jr|j| _|jr |j| _|jr*t| j|j |jD ]}|d u r:| j	d q-| j	|j q-t
|jD ]	}| j	|j qG|j D ]}| sft| j |d qVt| j |d qVd S )NrP  r  )r  r/  r   r  r   r   r  rX  r_  rH  r=  rY  ra  r  r   r   r   r  r  r!   )r:  r  r1  ra  r  r<   r<   r=   r     s,   
r   r   c                 C  r0  )zSerialize an IR Tensor to an ONNX TensorProto.

    Args:
        tensor: The IR Tensor to serialize.

    Returns:
        The serialized ONNX TensorProto object.
    r  )rt   r   r#   )r   tensor_protor<   r<   r=   r$     r;  r$   c                 C  r7  rX   r8  )r>  r  r<   r<   r=   rg    r  r>  c                 C  s   t |tr| |j |jrt| j|j d S |jr|j| _|jr%|j| _|jj	| _
| j|j  t |tjrctjj| _t|j|j|jd D ]\}}|d ura| j }||_t||_	qLnt |tjrr| j |   n|! | _"t| j|j d S )N)r  r  r  )#rs   r   CopyFromr   r   r  r   r   rP   r   r   r   extendr   r   r0   r  rt   r   r   r   osfspathr  r  r  rW  external_datar  r  r   r  r   r$  r   )r>  r  krt  r  r<   r<   r=   r#     s:   






	
r#   r  c                 C  r0  )zSerialize an IR Attribute to an ONNX AttributeProto.

    Args:
        attribute: The IR Attribute to serialize.

    Returns:
        The serialized ONNX AttributeProto object.
    r  )rt   r   r   )r  r  r<   r<   r=   r     r;  r   c                 C  r7  rX   r8  r  r  r<   r<   r=   rg    r  r  c                 C  s*   |j | _ |jr|j| _t| |j|j d S rX   )r   r   _fill_in_value_for_attributer   r   rE  r<   r<   r=   r     s   r   r  _enums.AttributeTypec                 C  s  |t jjkr|| _tjj| _d S |t jjkr || _tjj| _d S |t jj	krDt|t
u r7td| j || _n|d| _tjj	| _d S |t jjkrW| j| tjj| _d S |t jjkrj| j| tjj| _d S |t jjkr| jdd |D  tjj| _d S |t jjkrt| j| tjj| _d S |t jjkrt| j| tjj| _d S |t jjkr|D ]
}t| j | qtjj| _d S |t jj kr|D ]
}t| j! | qtjj | _d S |t jj"krt#dt$ |t jj%krt#dt$ |t jj&kr|jd ur
t'| j(|j |j)d urt*| j(|j) tjj&| _d S |t jj+krO|D ] }| j, }|jd ur:t'||j |j)d urFt*||j) q'tjj+| _d S t-d| )NzValue in attribute %r should be a string but is instead bytes. ONNX spec requires string attributes to be UTF-8 encoded so the model is invalid. We will skip encoding the attribute and use the bytes as attribute valuer  c                 S  r  r  )encoder  r<   r<   r=   rr  ;  r3  z0_fill_in_value_for_attribute.<locals>.<listcomp>r  zUnsupported attribute type: ).r1   r  r  r  rt   r   r   r  r  r   r"  rU  r  r   r  rH  r  r  r@  r  r  r  r  r  r#   r  r  r   r  r  r  r  r  r  r  r   r  r  r  r%   r   r   r    r  r  	TypeError)r  r  r   r   r   r  r  r<   r<   r=   rF    s|   
rF  c                 C  r7  rX   r8  rE  r<   r<   r=   rg  m  r  c                 C  s8   |j | _ |j| _|jr|j| _ttjj|jj	| _d S rX   )
r   r  r   typingcastrt   r   r  r   r   rE  r<   r<   r=   r!   m  s
   r!   r  c                 C  s   t  }t||  |S rX   )rt   r   r!   )r  
attr_protor<   r<   r=   r"   x  s   
r"   rd  c                C  r5  )zSerialize a value into a ValueInfoProto.

    Args:
        value: The proto to serialize into.
        from_: The value to serialize.
        name: A custom name to set for the value info. If not provided, the name from the value will be used.
    rd  )rt   r   r'   )r   r   r[  r<   r<   r=   r(     s   r(   c                 C  r7  rX   r8  r[  r  r   r<   r<   r=   rg    r  r[  c                C  sn   |r|| _ n|j | _ |jrt| j|j |jdur t| j|j |jdur,t| j|j |jr5|j| _dS dS )a  Serialize a value into a ValueInfoProto.

    Args:
        value_info_proto: The proto to serialize into.
        from_: The value to serialize.
        name: A custom name to set for the value info. If not provided, the name from the value will be used.
    N)r   r   r  r   r%   r   r    r   rM  r<   r<   r=   r'     s   

r'   c                 C  r7  rX   r8  r  r  r<   r<   r=   rg    r  r  c                 C  s   |j r|j | _ t|tjr| j}|jj|_d S t|tjr'| j	}|jj|_d S t|tj
r9| j}t|j|j d S t|tjrK| j}t|j|j d S td| )NzUnsupported type: )r  rs   r0   r  r  rP   r   r  r  r  r  r  r%   r  r  rI  )r  r  tensor_type_protosparse_tensor_type_protosequence_type_protooptional_type_protor<   r<   r=   r%     s   r%   type_protocolc                 C  r0  )zSerialize an IR Type to an ONNX TypeProto.

    Args:
        type_protocol: The IR Type to serialize.

    Returns:
        The serialized ONNX TypeProto object.
    r  )rt   r   r%   )rS  r  r<   r<   r=   r&     r;  r&   c                 C  r7  rX   r8  rN  r<   r<   r=   rg    r  _protocols.ShapeProtocolc                 C  s   |  d}|d u rtd| d S t| |}t|jts;|j} |  d}|d u r0td| d S t| |}t|jtr|jd t	|D ]\}}|
|}t|jj || qEd S )Nr   z_The value type for shape %s is not known. Please set type for the value. Skipping serializationr  )r  rU  r  r*  rs   r  intr   r   r  get_denotationr   r  r  )r  r  r  r  r  r  r  r<   r<   r=   r      s0   




r    c                 C  r  rX   r8  r  r  r  r<   r<   r=   rg    r  r  r  $int | _protocols.SymbolicDimProtocolr  r   c                 C  sR   |r|| _ t|tr|| _d S t|tjtjfr%|jd ur't	|j| _
d S d S d S rX   )r  rs   rU  r  r0   r  r2   SymbolicDimProtocolr   r   r  rW  r<   r<   r=   r     s   


r   )r>   r?   r@   rA   )r@   rM   )rT   rU   r@   rV   )rT   r[   r@   r\   )rT   r]   r@   r^   )rT   r_   r@   r`   )rT   ra   r@   rb   )rT   rc   r@   rd   )rT   re   r@   rf   )rT   rg   r@   rh   )rT   ri   r@   rj   )rT   rk   r@   rl   )rT   rm   r@   rn   )rT   ro   r@   rp   )rT   rq   r@   rq   rX   )r   r   r   r   r@   rV   )F)r   r   r   r   r@   r   )r   r   r@   rU   )r   r   r@   r[   )r   r   r@   r]   )r   r`   r@   r_   )r   r   r@   ra   )r   r   r@   ra   )r   r   r@   rc   )r   r   r@   re   )r   r   r@   rg   )r   r   r@   r[   )r   rq   r@   rq   )rT   r-   r)  r   r@   r-   )r,  rm   r@   rn   )r   r   r@   r4  )rC  rM  rN  rO  r@   r   )rT   r[   rf  ri  r@   r\   )
rT   r]   r  r  rL  r  rz  r  r@   r   )rT   rc   r   r  r@   rd   )rT   r  r   rd   r@   r   )rT   re   r@   r  )rT   re   r@   r  )rP  )rT   r_   r  r  r@   r`   )rT   ro   r@   r  )rT   ra   rf  ri  r@   rb   )
rT   r]   rf  ri  rL  r  rz  r  r@   r^   )r   r   r@   rU   )r  rU   r  r   r@   rU   )r   r   r@   r   )r  r[   r:  r   r@   r   )r$  r%  r  r&  r@   r   )r'  r(  r  r)  r@   r   )r  r[   r   r   r@   r   )r.  r  rk  r   r5   rp   r@   r   )r   r/  r@   r[   )r  r[   r  r/  r@   r   )r:  r   r  r   r@   rg   )r6  rg   r  r   r  r   r@   r   )r`  r   r@   r]   )rY  r<  r@   r<  )r:  r]   r  r   r@   r   )r   r`   r@   r_   )r>  r_   r  r`   r@   r   )r  r   r@   ra   )r  ra   r  r   r@   r   )r  ra   r  rG  r   r-   r@   r   )r  ra   r  r   r@   r   )r  r   r@   ra   )r   r   r   r   r@   rc   )r[  rc   r  r   r   r   r@   r   )r  re   r  r   r@   r   )rS  r   r@   re   )r  re   r  rT  r@   r   )r  rk   r  rX  r  r   r@   r   )fr;   
__future__r   rH   rJ  __all__rQ  loggingrA  collections.abcr*   r+   r,   r-   r.   r   rO   rt   onnx.external_data_helperonnx_irr/   r0   r1   r2   r3   TYPE_CHECKING#google.protobuf.internal.containersprotobufinternal
containersproto_containers	getLoggerr8   rU  r  rJ  r  TypeVarr6   RuntimeErrorr)   rL   rS   r  r   r   r   r   
TensorBaser   r+  r   r>  r   rK  r	   rD  r  r   r   r  r   r   r   r   r   r   r
   r  r   r  r   r|  r   r   r  r  r  r+  r  r-  r,  r   r   r   r   r   r=  r   r$   r#   r   r   rF  r!   r"   r(   r'   r%   r&   r    r   r<   r<   r<   r=   <module>   s>  -
	*- y	%1
|
1
6
 +
	
P
b"5	0
;

#
	
V
