o
    Ďi                     @  s$  d Z ddlmZ g dZddlZddlZddlmZ ddlZ	ddl
m  mZ ddlmZ er5ddlmZ dZe Zee_d	e	j ie_e Zd<ddZefd=ddZefd>ddZeefd?d d!Zeefd@d$d%ZdefdAd)d*Z eefdBd-d.Z!efdCd1d2Z"	3	3	3dDdEd:d;Z#ej$Z$dS )FzDGraph 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)
IR_VERSION)Messagel         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   H/home/jeff/fluffinator/venv/lib/python3.10/site-packages/onnx/checker.py_ensure_proto_type0   s
   
r   
value_infoonnx.ValueInfoProtoctxC.CheckerContextc                 C     t | tj t|  |S N)r   onnxValueInfoProtor   r
   SerializeToString)r    r"   r   r   r   r
   7      r
   tensoronnx.TensorProtoc                 C  r$   r%   )r   r&   TensorProtor   r	   r(   )r*   r"   r   r   r   r	   >   r)   r	   attronnx.AttributeProtolexical_scope_ctxC.LexicalScopeContextc                 C     t | tj t|  ||S r%   )r   r&   AttributeProtor   r   r(   )r-   r"   r/   r   r   r   r   E      r   nodeonnx.NodeProtoc                 C  r1   r%   )r   r&   	NodeProtor   r   r(   )r4   r"   r/   r   r   r   r   N   r3   r   functiononnx.FunctionProtoC.CheckerContext | Nonec                 C  sX   t | tj |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>b   s    z"check_function.<locals>.<dictcomp>)r   r&   FunctionProtor   CheckerContexthelperfind_min_ir_version_foropset_import
ir_versionopset_importsr   r(   )r7   r"   r/   r   r   r   r   W   s   r   graphonnx.GraphProtoc                 C  r1   r%   )r   r&   
GraphProtor   r   r(   )rG   r"   r/   r   r   r   r   i   r3   r   sparseonnx.SparseTensorProtoc                 C  s    t | tj t|  | d S r%   )r   r&   SparseTensorProtor   r   r(   )rJ   r"   r   r   r   r   r   s   r   Fmodel+onnx.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bytesr(   sys	getsizeofr   
ValueErrorr   )rM   rO   rQ   rR   protobuf_stringr   r   r   r   y   s&   r   )r   r   r   r   r   r   )r    r!   r"   r#   r   r   )r*   r+   r"   r#   r   r   )r-   r.   r"   r#   r/   r0   r   r   )r4   r5   r"   r#   r/   r0   r   r   )r7   r8   r"   r9   r/   r0   r   r   )rG   rH   r"   r#   r/   r0   r   r   )rJ   rK   r"   r#   r   r   )FFF)
rM   rN   rO   rP   rQ   rP   rR   rP   r   r   )%__doc__
__future__r   __all__rT   rY   typingr   	onnx.defsr&   onnx.onnx_cpp2py_export.checkeronnx_cpp2py_exportcheckerr   onnx.onnx_pbr   google.protobuf.messager   r   rA   r   rE   defsonnx_opset_versionrF   LexicalScopeContextr   r   r
   r	   r   r   r   r   r   r   r   r   r   r   r   <module>   sP   
	
	
3