
    /;jio;                    |   d dl mZ g dZd dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
 d dlmZmZmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 d d	l3m4Z4m5Z5 d d
l6m7Z7m8Z8m9Z9 d dl:Zd dlm;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF ejG        rd dlHmIZI ejJ        jJ        ZKed         eLz  ZMdZNdCdZOdDdZPdEdZQ	 dFdGdZR	 	 dHdId$ZS	 dFdJd&ZTeNfdKd*ZUeNfdLd+ZV	 dFd,ddd-d,d.dMd7ZW	 dFdNd8ZXeSZYeUZZeWZ[dOd;Z\dPd=Z]dQd?Z^dRdBZ_e\e!_`        e]e_`        e^e_`        dS )S    )annotations)>ONNX_ML
IR_VERSIONIR_VERSION_2017_10_10IR_VERSION_2017_10_30IR_VERSION_2017_11_3IR_VERSION_2019_1_22IR_VERSION_2019_3_18IR_VERSION_2019_9_19IR_VERSION_2020_5_8IR_VERSION_2021_7_30IR_VERSION_2023_5_5IR_VERSION_2024_3_25EXPERIMENTALSTABLEcheckercomposedefs	gen_protohelperhubnumpy_helperparserprintershape_inferenceutilsversion_converterAttributeProtoDeviceConfigurationProtoFunctionProto
GraphProtoIntIntListEntryProtoMapProto
ModelProtoNodeDeviceConfigurationProto	NodeProtoOperatorProtoOperatorSetIdProtoOperatorSetProtoOperatorStatusOptionalProtoSequenceProtoSimpleShardedDimProtoShardedDimProtoShardingSpecProtoSparseTensorProtoStringStringEntryProtoTensorAnnotationTensorProtoTensorShapeProtoTrainingInfoProto	TypeProtoValueInfoProtoVersionconvert_model_to_external_dataload_external_data_for_modelload_model_from_string
load_modelload_tensor_from_stringload_tensor
save_modelsave_tensorwrite_external_data_tensorsN)IOLiteral)serialization)r   )r:   rA   r9   )#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/   r0   r1   r2   r3   r4   r5   r6   r7   r8   )r'   r)   )r#   r+   r,   )r   r   r   r   r   r   r   r   r   r   r   r   )Sequence)protobuf	textprotoonnxtxtjsonrF   fIO[bytes] | str | os.PathLikereturnbytesc                f   t          | d          rOt          t          j        d|           j                  r(t          j        d|                                           }nQt          j        d|           } t          | d          5 }|                                }d d d            n# 1 swxY w Y   |S )Nread	IO[bytes]str | os.PathLikerb)hasattrcallabletypingcastrO   open)rJ   contentreadables      G/root/voice-cloning/.venv/lib/python3.11/site-packages/onnx/__init__.py_load_bytesr[      s    q& &hv{;'B'B'GHH &+k1--2244K+Q//!T]] 	&hmmooG	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&Ns   B&&B*-B*rX   Nonec                n   t          |d          rQt          t          j        d|          j                  r*t          j        d|                              |            d S t          j        d|          }t          |d          5 }|                    |            d d d            d S # 1 swxY w Y   d S )NwriterP   rQ   wb)rS   rT   rU   rV   r^   rW   )rX   rJ   writables      rZ   _save_bytesra      s    q' $xK(C(C(IJJ $K##))'22222K+Q//!T]] 	$hNN7###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   B**B.1B.$IO[bytes] | str | os.PathLike | None
str | Nonec                    t          | t          t          j        f          rt          j                            |           S t          | d          r(| J t          j                            | j                  S d S )Nname)
isinstancestrosPathLikepathabspathrS   re   )rJ   s    rZ   _get_file_pathrl      se    !c2;'(( "wq!!!q& '}}}wqv&&&4    fmt_SupportedFormat | None$str | os.PathLike | IO[bytes] | Noneserialization.ProtoSerializerc                @   | t           j                            |           S t          |          x}At          j                            |          \  }}t           j                            |          } | pt          } | J t           j                            |           S )zQGet the serializer for the given path and format from the serialization registry.)	rD   registrygetrl   rh   rj   splitextget_format_from_file_extension_DEFAULT_FORMAT)rn   rJ   	file_path_exts        rZ   _get_serializerr{      s    
 %))#...#A&&&	3!!),,3$CCCHH 
 C???!%%c***rm   Tformatload_external_databoolr$   c                   t          ||                               t          |           t                                }|r@t	          |           }|r/t
          j                            |          }t          ||           |S )a  Loads a serialized ModelProto into memory.

    Args:
        f: can be a file-like object (has "read" function) or a string/PathLike containing a file name
        format: The serialization format. When it is not specified, it is inferred
            from the file extension when ``f`` is a path. If not specified _and_
            ``f`` is not a path, 'protobuf' is used. The encoding is assumed to
            be "utf-8" when the format is a text format.
        load_external_data: Whether to load the external data.
            Set to True if the data is under the same directory of the model.
            If not, users need to call :func:`load_external_data_for_model`
            with directory to load external data from.

    Returns:
        Loaded in-memory ModelProto.
    )	r{   deserialize_protor[   r$   rl   rh   rj   dirnamer:   )rJ   r|   r}   modelmodel_filepathbase_dirs         rZ   r<   r<      sr    * FA&&88QVVE :'** 	:w~66H(999Lrm   r3   c                |    t          ||                               t          |           t                                S )a  Loads a serialized TensorProto into memory.

    Args:
        f: can be a file-like object (has "read" function) or a string/PathLike containing a file name
        format: The serialization format. When it is not specified, it is inferred
            from the file extension when ``f`` is a path. If not specified _and_
            ``f`` is not a path, 'protobuf' is used. The encoding is assumed to
            be "utf-8" when the format is a text format.

    Returns:
        Loaded in-memory TensorProto.
    )r{   r   r[   r3   )rJ   r|   s     rZ   r>   r>      s.      61%%77AVVVrm   sbytes | str_SupportedFormatc                `    t          |                              | t                                S )a  Loads a binary string (bytes) that contains serialized ModelProto.

    Args:
        s: a string, which contains serialized ModelProto
        format: The serialization format. When it is not specified, it is inferred
            from the file extension when ``f`` is a path. If not specified _and_
            ``f`` is not a path, 'protobuf' is used. The encoding is assumed to
            be "utf-8" when the format is a text format.

    Returns:
        Loaded in-memory ModelProto.
    )r{   r   r$   r   r|   s     rZ   r;   r;     s&      6""44Q
EEErm   c                `    t          |                              | t                                S )a  Loads a binary string (bytes) that contains serialized TensorProto.

    Args:
        s: a string, which contains serialized TensorProto
        format: The serialization format. When it is not specified, it is inferred
            from the file extension when ``f`` is a path. If not specified _and_
            ``f`` is not a path, 'protobuf' is used. The encoding is assumed to
            be "utf-8" when the format is a text format.

    Returns:
        Loaded in-memory TensorProto.
    )r{   r   r3   r   s     rZ   r=   r=     s&      6""44QFFFrm   Fi   )save_as_external_dataall_tensors_to_one_filelocationsize_thresholdconvert_attributeprotoModelProto | bytesr   r   r   r   intr   c                  t          | t                    r4t          t                                        | t                                } |rt          | ||||           t          |          }|/t          j	        
                    |          }	t          | |	          } t          ||                              |           }
t          |
|           dS )a}  Saves the ModelProto to the specified path and optionally, serialize tensors with raw data as external data before saving.

    Args:
        proto: should be a in-memory ModelProto
        f: can be a file-like object (has "write" function) or a string containing
        a file name or a pathlike object
        format: The serialization format. When it is not specified, it is inferred
            from the file extension when ``f`` is a path. If not specified _and_
            ``f`` is not a path, 'protobuf' is used. The encoding is assumed to
            be "utf-8" when the format is a text format.
        save_as_external_data: If true, save tensors to external file(s).
        all_tensors_to_one_file: Effective only if save_as_external_data is True.
            If true, save all tensors to one external file specified by location.
            If false, save each tensor to a file named with the tensor name.
        location: Effective only if save_as_external_data is true.
            Specify the external file that all tensors to save to.
            Path is relative to the model path.
            If not specified, will use the model name.
        size_threshold: Effective only if save_as_external_data is True.
            Threshold for size of data. Only when tensor's data is >= the size_threshold it will be converted
            to external data. To convert every tensor with raw data to external data set size_threshold=0.
        convert_attribute: Effective only if save_as_external_data is True.
            If true, convert all tensors to external data
            If false, convert only non-attribute tensors to external data
    N)rf   rM   r{   rw   r   r$   r9   rl   rh   rj   r   rA   serialize_protora   )r   rJ   r|   r   r   r   r   r   r   basepath
serializeds              rZ   r?   r?   '  s    H % X00BB5*,,WW 
&*HnFW	
 	
 	
 $A&&N!7??>22+E8<< 88HHOOJ
Arm   c                l    t          ||                              |           }t          ||           dS )a  Saves the TensorProto to the specified path.

    Args:
        proto: should be a in-memory TensorProto
        f: can be a file-like object (has "write" function) or a string
        containing a file name or a pathlike object.
        format: The serialization format. When it is not specified, it is inferred
            from the file extension when ``f`` is a path. If not specified _and_
            ``f`` is not a path, 'protobuf' is used. The encoding is assumed to
            be "utf-8" when the format is a text format.
    N)r{   r   ra   )r   rJ   r|   r   s       rZ   r@   r@   \  s7      !++;;EBBJ
Arm   selfrg   c           	     \   | j         rd| j          d}nd}| j        rd| j         d}nd}| j        rd| j         d}nd}| j        rd| j        }nd}| j        rdt          | j                   d}nd}| j        rd	t          | j                   }nd}d
| j         | | | | | | d	S )N
, domain='' z, producer_name='z, producer_version='z, graph=z, functions=<z functions>, opset_import=zModelProto(ir_version=))	domainproducer_nameproducer_versiongraph	functionslenopset_import_operator_set_protos_repr
ir_version)r   r   r   r   r   r   r   s          rZ   _model_proto_reprr   v  s   { ,dk,,, AD,>AAA J$2GJJJz )4:))~ DC$7$7DDD			 W)B4CT)U)UWWDO\6=Zjlqs|rm   r!   c           	        | j         rdt          | j                    d}nd}| j        rdt          | j                   d}nd}| j        rdt          | j                   d}nd}| j        rdt          | j                   d	}nd}| j        rd
t          | j                   d}nd}d| j         d| | | | | d	S )Nz, initializer=<z initializers>r   , node=< nodes>z, value_info=<z value_info>	, input=< inputs>
, output=<	 outputs>zGraphProto('r   r   )initializerr   node
value_infoinputoutputre   )r   r   r   r   r   r   s         rZ   _graph_proto_reprr     s    MD,<(=(=MMMy 1#di..111 Hc$/&:&:HHH


z 5C
OO555{ 9c$+..999U$)UUeUVU[U$U
UUUUrm   r    c                   | j         rd| j          d}nd}| j        rd| j         d}nd}| j        rdt          | j                   d}nd}| j        rd| j         }nd}| j        rdt          | j                   }nd}| j        rd	t          | j                   d
}nd}| j        rdt          | j                   d}nd}d| j	         d| | | | | | | dS )Nr   r   r   z, overload='r   r   z, attribute=r   r   r   r   r   zFunctionProto('r   )
r   overloadr   r   	attributer   r   r   r   re   )r   r   r   r   r   r   r   r   s           rZ   _function_proto_reprr     sL   { ,dk,,,} 2$-222y 1#di..111~ 34>33			 W)B4CT)U)UWWz 5C
OO555{ 9c$+..999jTYjjjj<jjPVjXajcgjjjjrm   protosSequence[OperatorSetIdProto]c                8    d | D             }t          |          S )Nc                (    i | ]}|j         |j        S  )r   version).0r   s     rZ   
<dictcomp>z-_operator_set_protos_repr.<locals>.<dictcomp>  s    EEEUU\5=EEErm   )repr)r   opset_importss     rZ   r   r     s#    EEfEEEMrm   )rJ   rK   rL   rM   )rX   rM   rJ   rK   rL   r\   )rJ   rb   rL   rc   )N)rn   ro   rJ   rp   rL   rq   )NT)rJ   rK   r|   ro   r}   r~   rL   r$   )rJ   rK   r|   ro   rL   r3   )r   r   r|   r   rL   r$   )r   rM   r|   r   rL   r3   )r   r   rJ   rK   r|   ro   r   r~   r   r~   r   rc   r   r   r   r~   rL   r\   )r   r3   rJ   rK   r|   ro   rL   r\   )r   r$   rL   rg   )r   r!   rL   rg   )r   r    rL   rg   )r   r   rL   rg   )a
__future__r   __all__rh   rU   rB   rC   onnxrD   onnx.onnx_cpp2py_exportr   onnx.external_data_helperr:   rA   r9   onnx.onnx_pbr   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/   r0   r1   r2   r3   r4   r5   r6   r7   r8   onnx.onnx_operators_pbr'   r)   onnx.onnx_data_pbr#   r+   r,   onnx.versionr   r   r   r   r   r   r   r   r   r   r   r   TYPE_CHECKINGcollections.abcrE   r   __version__rg   r   rw   r[   ra   rl   r{   r<   r>   r;   r=   r?   r@   loadload_from_stringsaver   r   r   r   __repr__r   rm   rZ   <module>r      s  
 # " " " " "C C CL 
			                + + + + + +         
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $J C B B B B B B B D D D D D D D D D D                                
 )((((((l"
 EFL    $ $ $ $    MQ+ + + + +* '+#    D '+W W W W W*  /F F F F F*  /G G G G G, '+2
 #($(#2 2 2 2 2 2p '+    * ) @ @ @ @8V V V V0k k k k@    (
 '
 -   rm   