
    bIg                    :   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	 ddl
mZ ddlZddlmc 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 dZ ej:                         Zee_        d	ej@                  jC                         ie_"         ejF                         Z$ e	d
edef         Z%ddZ&ef	 	 	 	 	 ddZ'efddZ(ee$f	 	 	 	 	 	 	 ddZ)ee$f	 	 	 	 	 	 	 ddZ*de$f	 	 	 	 	 	 	 ddZ+ee$f	 	 	 	 	 	 	 ddZ,ef	 	 	 	 	 ddZ-	 	 	 d	 	 	 	 	 	 	 	 	 ddZ.ej^                  Z/y) zDGraph 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)AnyCallableTypeVar)Message)	
IR_VERSIONAttributeProtoFunctionProto
GraphProto
ModelProto	NodeProtoSparseTensorProtoTensorProtoValueInfoProtoi 5w FuncType.)boundc                N    t        | |      st        d|j                   d      y )Nz'The proto message needs to be of type '')
isinstance	TypeError__name__)proto
proto_types     I/var/www/html/answerous/venv/lib/python3.12/site-packages/onnx/checker.py_ensure_proto_typer)   A   s1    eZ(5j6I6I5J!L
 	
 )    c                j    t        | t               t        j                  | j	                         |      S N)r)   r   r   r   SerializeToString)
value_infoctxs     r(   r   r   H   s*     z>2j::<cBBr*   c                j    t        | t               t        j                  | j	                         |      S r,   )r)   r   r   r
   r-   )tensorr/   s     r(   r
   r
   O   s&    v{+>>&224c::r*   c                l    t        | t               t        j                  | j	                         ||      S r,   )r)   r   r   r   r-   )attrr/   lexical_scope_ctxs      r(   r   r   T   s-    
 t^,T335s<MNNr*   c                l    t        | t               t        j                  | j	                         ||      S r,   )r)   r   r   r   r-   )noder/   r4   s      r(   r   r   ]   s+    
 tY'<<..0#7HIIr*   c                l   t        | t               |xt        j                         }t        j
                  j                  | j                  d      |_        | j                  D ci c]  }|j                  |j                   c}|_        t        j                  | j                         ||       y c c}w )NT)ignore_unknown)r)   r   r   CheckerContextonnxhelperfind_min_ir_version_foropset_import
ir_versiondomainversionopset_importsr   r-   )functionr/   r4   domain_versions       r(   r   r   f   s    
 x/
{ <<!!$ = 

 #+"7"7
 !!>#9#99
 X//138IJ	
s   %B1c                l    t        | t               t        j                  | j	                         ||      S r,   )r)   r   r   r   r-   )graphr/   r4   s      r(   r   r   x   s+    
 uj)==002C9JKKr*   c                l    t        | t               t        j                  | j	                         |       y r,   )r)   r   r   r	   r-   )sparser/   s     r(   r	   r	      s(     v01&224c:r*   c                ^   t        | t        t        j                  f      r,t	        j
                  t        j                  |       |||       yt        | t              r| n| j                         }t        j                  |      t        kD  rt        d      t	        j                  ||||       y)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.
    zZThis protobuf of onnx model is too large (>2GB). Call check_model with model path instead.N)r#   strosPathLiker   check_model_pathfspathbytesr-   sys	getsizeofr   
ValueErrorr   )model
full_checkskip_opset_compatibility_checkcheck_custom_domainprotobuf_strings        r(   r   r      s    4 %#r{{+,	IIe*		
  u-E53J3J3L 	
 ==),<<l  	
*		
r*   )r&   r   r'   ztype[Message]returnNone)r.   r   r/   C.CheckerContextrW   rX   )r1   r   r/   rY   rW   rX   )r3   r   r/   rY   r4   C.LexicalScopeContextrW   rX   )r6   r   r/   rY   r4   rZ   rW   rX   )rB   r   r/   zC.CheckerContext | Noner4   rZ   rW   rX   )rE   r   r/   rY   r4   rZ   rW   rX   )rG   r   r/   rY   rW   rX   )FFF)
rR   z&ModelProto | str | bytes | os.PathLikerS   boolrT   r[   rU   r[   rW   rX   )0__doc__
__future__r   __all__rJ   rO   typingr   r   r   google.protobuf.messager   	onnx.defsr:   onnx.onnx_cpp2py_export.checkeronnx_cpp2py_exportcheckerr   onnx.shape_inferencer   r   r   r   r   r   r   r   r   r   r9   r   r>   defsonnx_opset_versionrA   LexicalScopeContextr   r   r)   r   r
   r   r   r   r   r	   r   r    r*   r(   <module>rj      s#   K "  
 
 ) ) +  + + 
 
 
   #!""$' !#TYY%A%A%C D ---/  :Xc3h%78
 9HCC%5C	C ?N ; ,/DO
O	O -O 
	O ,/DJ
J	J -J 
	J $(/DKK	 K -K 
	K( ,/DLL	L -L 
	L 8G;;$4;	; +0 %	0
10
0
 %)0
 	0

 
0
f ##r*   