o
    Uôj¹  ã                   @  sd  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  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 ¡ 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j/Z/d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)ÚAnyÚCallableÚTypeVar)ÚMessage)	Ú
IR_VERSIONÚAttributeProtoÚFunctionProtoÚ
GraphProtoÚ
ModelProtoÚ	NodeProtoÚSparseTensorProtoÚTensorProtoÚValueInfoProtoi ”5wÚ Ú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)   ú_/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/onnx/checker.pyÚ_ensure_proto_typeA   s
   
ÿÿr+   Ú
value_infor   ÚctxúC.CheckerContextc                 C  ó   t | tƒ t |  ¡ |¡S ©N)r+   r   r   r
   ÚSerializeToString)r,   r-   r)   r)   r*   r
   H   s   
r
   Útensorr   c                 C  r/   r0   )r+   r   r   r	   r1   )r2   r-   r)   r)   r*   r	   O   s   
r	   Úattrr   Úlexical_scope_ctxúC.LexicalScopeContextc                 C  ó   t | tƒ t |  ¡ ||¡S r0   )r+   r   r   r   r1   )r3   r-   r4   r)   r)   r*   r   T   ó   
r   Únoder   c                 C  r6   r0   )r+   r   r   r   r1   )r8   r-   r4   r)   r)   r*   r   ]   r7   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)Zignore_unknownc                 S  s   i | ]}|j |j“qS r)   )ÚdomainÚversion)Ú.0Zdomain_versionr)   r)   r*   Ú
<dictcomp>q   s    ÿÿz"check_function.<locals>.<dictcomp>)r+   r   r   ÚCheckerContextÚonnxÚhelperZfind_min_ir_version_forZopset_importÚ
ir_versionÚopset_importsr   r1   )r9   r-   r4   r)   r)   r*   r   f   s   
ÿþr   Úgraphr   c                 C  r6   r0   )r+   r   r   r   r1   )rD   r-   r4   r)   r)   r*   r   x   r7   r   Úsparser   c                 C  s   t | tƒ t |  ¡ |¡ d S r0   )r+   r   r   r   r1   )rE   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.
    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Úbytesr1   ÚsysÚ	getsizeofr   Ú
ValueErrorr   )rF   rH   rJ   rK   Zprotobuf_stringr)   r)   r*   r   ˆ   s&   üÿÿür   )r    r   r!   r"   r#   r$   )r,   r   r-   r.   r#   r$   )r2   r   r-   r.   r#   r$   )r3   r   r-   r.   r4   r5   r#   r$   )r8   r   r-   r.   r4   r5   r#   r$   )r9   r   r-   r:   r4   r5   r#   r$   )rD   r   r-   r.   r4   r5   r#   r$   )rE   r   r-   r.   r#   r$   )FFF)
rF   rG   rH   rI   rJ   rI   rK   rI   r#   r$   )0Ú__doc__Ú
__future__r   Ú__all__rM   rR   Útypingr   r   r   Úgoogle.protobuf.messager   Z	onnx.defsr@   Zonnx.onnx_cpp2py_export.checkerÚonnx_cpp2py_exportÚcheckerr   Zonnx.shape_inferencer   r   r   r   r   r   r   r   r   r   r?   r   rB   ÚdefsÚonnx_opset_versionrC   ÚLexicalScopeContextr   r   r+   r
   r	   r   r   r   r   r   r   r   r)   r)   r)   r*   Ú<module>   sP   ,
ÿýýýý
ÿ	ü
3