o
    wi                     @  sl  d Z ddlmZ g dZddlZddlZddlmZmZm	Z	m
Z
 ddlZddlm  mZ ddlZddlmZmZmZmZmZmZmZmZmZ erOddlmZ dZe Zee_ d	ej!" ie_#e$ Z%e
d
e	def dZ&d?ddZ'efd@ddZ(efdAddZ)ee%fdBd#d$Z*ee%fdCd'd(Z+de%fdDd,d-Z,ee%fdEd0d1Z-efdFd4d5Z.	6	6	6dGdHd=d>Z/ej0Z0dS )IzDGraph utilities for checking whether an ONNX proto message is legal.    )annotations)check_attributecheck_functioncheck_graphcheck_model
check_nodecheck_sparse_tensorcheck_tensorcheck_value_infoDEFAULT_CONTEXTLEXICAL_SCOPE_CONTEXTValidationErrorCMAXIMUM_PROTOBUFN)TYPE_CHECKINGAnyCallableTypeVar)	
IR_VERSIONAttributeProtoFunctionProto
GraphProto
ModelProto	NodeProtoSparseTensorProtoTensorProtoValueInfoProto)Messagel         FuncType.)boundprotor   
proto_typetype[Message]returnNonec                 C  s    t | |std|j dd S )Nz'The proto message needs to be of type '')
isinstance	TypeError__name__)r!   r"    r*   I/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/onnx/checker.py_ensure_proto_typeB   s
   
r,   
value_infor   ctxC.CheckerContextc                 C     t | t t|  |S N)r,   r   r   r
   SerializeToString)r-   r.   r*   r*   r+   r
   I   s   
r
   tensorr   c                 C  r0   r1   )r,   r   r   r	   r2   )r3   r.   r*   r*   r+   r	   P   s   
r	   attrr   lexical_scope_ctxC.LexicalScopeContextc                 C     t | t t|  ||S r1   )r,   r   r   r   r2   )r4   r.   r5   r*   r*   r+   r   U      
r   noder   c                 C  r7   r1   )r,   r   r   r   r2   )r9   r.   r5   r*   r*   r+   r   ^   r8   r   functionr   C.CheckerContext | Nonec                 C  sV   t | t |d u r t }tjj| jdd|_dd | jD |_	t
|  || d S )NT)ignore_unknownc                 S  s   i | ]}|j |jqS r*   )domainversion).0domain_versionr*   r*   r+   
<dictcomp>r   s    z"check_function.<locals>.<dictcomp>)r,   r   r   CheckerContextonnxhelperfind_min_ir_version_foropset_import
ir_versionopset_importsr   r2   )r:   r.   r5   r*   r*   r+   r   g   s   
r   graphr   c                 C  r7   r1   )r,   r   r   r   r2   )rI   r.   r5   r*   r*   r+   r   y   r8   r   sparser   c                 C  s   t | t t|  | d S r1   )r,   r   r   r   r2   )rJ   r.   r*   r*   r+   r      s   
r   Fmodel&ModelProto | str | bytes | os.PathLike
full_checkboolskip_opset_compatibility_checkcheck_custom_domainc                 C  sj   t | ttjfrtt| ||| dS t | tr| n|  }t	
|tkr+tdt|||| dS )ar  Check the consistency of a model.

    An exception will be raised if the model's ir_version is not set
    properly or is higher than checker's ir_version, or if the model
    has duplicate keys in metadata_props.

    If IR version >= 3, the model must specify opset_import.
    If IR version < 3, the model cannot have any opset_import specified.

    Args:
        model: Model to check. If model is a path, the function checks model
            path first. If the model bytes size is larger than 2GB, function
            should be called using model path.
        full_check: If True, the function also runs shape inference check.
        skip_opset_compatibility_check: If True, the function skips the check for
            opset compatibility.
        check_custom_domain: If True, the function will check all domains. Otherwise
            only check built-in domains.
    z[This protobuf of onnx model is too large (>2GiB). Call check_model with model path instead.N)r'   strosPathLiker   check_model_pathfspathbytesr2   sys	getsizeofr   
ValueErrorr   )rK   rM   rO   rP   protobuf_stringr*   r*   r+   r      s&   r   )r!   r   r"   r#   r$   r%   )r-   r   r.   r/   r$   r%   )r3   r   r.   r/   r$   r%   )r4   r   r.   r/   r5   r6   r$   r%   )r9   r   r.   r/   r5   r6   r$   r%   )r:   r   r.   r;   r5   r6   r$   r%   )rI   r   r.   r/   r5   r6   r$   r%   )rJ   r   r.   r/   r$   r%   )FFF)
rK   rL   rM   rN   rO   rN   rP   rN   r$   r%   )1__doc__
__future__r   __all__rR   rW   typingr   r   r   r   	onnx.defsrC   onnx.onnx_cpp2py_export.checkeronnx_cpp2py_exportcheckerr   onnx.shape_inferencer   r   r   r   r   r   r   r   r   google.protobuf.messager   r   rB   r   rG   defsonnx_opset_versionrH   LexicalScopeContextr   r   r,   r
   r	   r   r   r   r   r   r   r   r*   r*   r*   r+   <module>   sR   ,

	
3