/usr/local/lib/python3.6/site-packages/transformers/onnx/__pycache__
NameSizeModeActions
config.cpython-36.pyc208370644editdlrm
convert.cpython-36.pyc128450644editdlrm
features.cpython-36.pyc102140644editdlrm
utils.cpython-36.pyc15240644editdlrm
__init__.cpython-36.pyc8760644editdlrm
__main__.cpython-36.pyc27020644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/transformers/onnx/__pycache__/convert.cpython-36.pyc (12845B)
3 Eg3J @sddlZddlmZddlmZddlmZddlmZm Z m Z m Z m Z ddl ZddlmZmZddlmZdd lmZmZmZmZmZd d lmZerdd lmZerdd lmZerddl m!Z!ddl"m#Z#ej$e%Z&edZ'edddZ(d%e d&dee)ede e e*e e*fdddZ+d'e d(dee)ede e e*e e*fdddZ,d)e d*e d+ee)ede e e*e e*fdddZ-d,ee d-e d.ee e*e.ddd d!Z/e d/e e*e e0e e*fd"d#d$Z1dS)0N) signature)chain)Path) TYPE_CHECKINGIterableListTupleUnion)Versionparse)PreTrainedTokenizerBase) TensorTypeis_tf_availableis_torch_available+is_torch_onnx_dict_inputs_support_availablelogging) OnnxConfig)PreTrainedModel)TFPreTrainedModel)FeatureExtractionMixin)PreTrainedTokenizerz1.4.0)minimum_versionc CsXy6ddl}t|j}|tkr4td|jd|dWntk rRtdYnXdS)z Check onnxruntime is installed and if the installed version match is recent enough Raises: ImportError: If onnxruntime is not installed or too old version is found rNz*We found an older version of onnxruntime (z&) but we require onnxruntime to be >= zp to enable all the conversions options. Please update onnxruntime by running `pip install --upgrade onnxruntime`zonnxruntime doesn't seem to be currently installed. Please install the onnxruntime by running `pip install onnxruntime` and relaunch the conversion.) onnxruntimer __version__ORT_QUANTIZE_MINIMUM_VERSION ImportError)rrZ ort_versionrC/usr/local/lib/python3.6/site-packages/transformers/onnx/convert.pycheck_onnxruntime_requirements5s r rrr) preprocessormodelconfigopsetoutput tokenizerreturncCsFt|tr|dk rtd|dk rddl }ddl m }tjd|j|jd|j_|j|jdk rtjd t|jd x:|jjD],\}} tjd |d | t|j|| qW|j|tjd } t|| j\} } t|jj} | s*td|jt|jtdkryV||| f|j t|j!j| ddt"|j!j|jjDd|j#|j$d|d WnHt%k r}z*t&|}|dkrd}t%|n|WYdd}~XnXnD||| f|j t|j!j| ddt"|j!j|jjDd|d|j'WdQRX| | fS)a Export a PyTorch model to an ONNX Intermediate Representation (IR) Args: preprocessor: ([`PreTrainedTokenizer`] or [`FeatureExtractionMixin`]): The preprocessor used for encoding the data. model ([`PreTrainedModel`]): The model to export. config ([`~onnx.config.OnnxConfig`]): The ONNX configuration associated with the exported model. opset (`int`): The version of the ONNX operator set to use. output (`Path`): Directory to store the exported ONNX model. Returns: `Tuple[List[str], List[str]]`: A tuple with an ordered list of the model's inputs, and the named inputs from the ONNX configuration. NzKYou cannot provide both a tokenizer and a preprocessor to export the model.ztThe `tokenizer` argument is deprecated and will be removed in version 5 of Transformers. Use `preprocessor` instead.zSOverwriting the `preprocessor` argument with `tokenizer` to generate dummmy inputs.r)exportzUsing framework PyTorch: Tz Overriding z configuration item(s)z - z -> ) frameworkz%Model and config inputs doesn't matchz1.10cSsi|]\}}||qSrr).0nameaxesrrr sz"export_pytorch..)f input_names output_names dynamic_axesdo_constant_foldinguse_external_data_formatZenable_onnx_checker opset_versionzExporting model exceed maximum protobuf size of 2GB. Please call torch.onnx.export without setting use_external_data_format parameter.zExporting model exceed maximum protobuf size of 2GB. Please call torch.onnx.export without setting use_external_data_format parameter or try with torch 1.10+.cSsi|]\}}||qSrr)r*r+r,rrrr-s)r.r/r0r1r2r4)( isinstancer ValueErrorwarningswarn FutureWarningloggerinfo issubclasstypertorchZ torch.onnxr(rZno_gradr# return_dictevalvalues_overridelenitemssetattrgenerate_dummy_inputsrPYTORCH$ensure_model_and_config_inputs_matchkeyslistoutputsZ patch_opsr as_posixinputsrr3Znum_parameters RuntimeErrorstr restore_ops)r!r"r#r$r%r&r>Z onnx_exportoverride_config_keyoverride_config_value model_inputs inputs_matchmatched_inputs onnx_outputserrmessagerrrexport_pytorchRst         rXrcs6ddlddl}ddl}t|tr2|dk r2td|dk rTtjdtt j d|}d|j _ |j dk rt j dt|j dx:|j jD],\}} t j d |d | t|j || qW|j|tjd } t|| j\} } t|jj} fd d | jD}|jj|||d\}}|j||j|j| | fS)a Export a TensorFlow model to an ONNX Intermediate Representation (IR) Args: preprocessor: ([`PreTrainedTokenizer`] or [`FeatureExtractionMixin`]): The preprocessor used for encoding the data. model ([`TFPreTrainedModel`]): The model to export. config ([`~onnx.config.OnnxConfig`]): The ONNX configuration associated with the exported model. opset (`int`): The version of the ONNX operator set to use. output (`Path`): Directory to store the exported ONNX model. Returns: `Tuple[List[str], List[str]]`: A tuple with an ordered list of the model's inputs, and the named inputs from the ONNX configuration. rNzIYou cannot provide both a tokenizer and preprocessor to export the model.ztThe `tokenizer` argument is deprecated and will be removed in version 5 of Transformers. Use `preprocessor` instead.zSOverwriting the `preprocessor` argument with `tokenizer` to generate dummmy inputs.Tz Overriding z configuration item(s)z - z -> )r)cs g|]\}}jj||dqS))r+)Z TensorSpecZ from_tensor)r*keyZtensor)tfrr sz%export_tensorflow..)r$)Z tensorflowonnxtf2onnxr5r r6r7r8r9r:r;r#r?rArBrCrDrEr TENSORFLOWrGrHrIrJconvertZ from_kerassaverKrO)r!r"r#r$r%r&r\r]rPrQrRrSrTrUZinput_signature onnx_model_r)rZrexport_tensorflows2  rccCstp tstdt|tr.|dk r.td|dk rPtjdtt j d|}trddl m }t svtd||jst jd |jd |trtt|trt||||||d Strtt|trt||||||d SdS) a Export a Pytorch or TensorFlow model to an ONNX Intermediate Representation (IR) Args: preprocessor: ([`PreTrainedTokenizer`] or [`FeatureExtractionMixin`]): The preprocessor used for encoding the data. model ([`PreTrainedModel`] or [`TFPreTrainedModel`]): The model to export. config ([`~onnx.config.OnnxConfig`]): The ONNX configuration associated with the exported model. opset (`int`): The version of the ONNX operator set to use. output (`Path`): Directory to store the exported ONNX model. Returns: `Tuple[List[str], List[str]]`: A tuple with an ordered list of the model's inputs, and the named inputs from the ONNX configuration. zrCannot convert because neither PyTorch nor TensorFlow are not installed. Please install torch or tensorflow first.NzKYou cannot provide both a tokenizer and a preprocessor to export the model.ztThe `tokenizer` argument is deprecated and will be removed in version 5 of Transformers. Use `preprocessor` instead.zSOverwriting the `preprocessor` argument with `tokenizer` to generate dummmy inputs.r ) torch_versionz=Unsupported PyTorch version, minimum required is 1.8.0, got: z@Unsupported PyTorch version for this model. Minimum required is z, got: )r&)rrrr5r r6r7r8r9r:r;utilsrdrAssertionErrorZis_torch_support_availablewarningZtorch_onnx_minimum_versionr<r=rrXrrc)r!r"r#r$r%r&rdrrrr(s,   r()r#r!reference_modelraonnx_named_outputsatolr&cCsddlm}m}tjdt|tr4|dk r4td|dk rVtj dt tjd|}t r|t t |tr||j|tjd} n|j|tjd} |} ||j| dgd } |f| } i} xN| jD]B\}}|d krd }t|ttfr|j||}| j|q|| |<qWi}xX| jD]L\}}t|ttfrP|j||}|jd d |jDn |j||<qW| j||}t| jt|}}|j|stjd|d|td|j|ntjd|dxt||D]\}}t rt t |tr| |j j}n | |j}tjd|d|j!|j!ksrtjd|j!d|j!td|j!d|j!dntjd|j!d|j!t"j#|||dstjd|dtdt"j$t"j%||ntjd|dqWdS) Nr)InferenceSessionSessionOptionszValidating ONNX model...zTYou cannot provide both a tokenizer and a preprocessor to validatethe model outputs.ztThe `tokenizer` argument is deprecated and will be removed in version 5 of Transformers. Use `preprocessor` instead.zSOverwriting the `preprocessor` argument with `tokenizer` to generate dummmy inputs.)r)ZCPUExecutionProvider) providersZpast_key_valuesZpresentcSsi|]\}}|j|qSr)numpy)r*Z tensor_nameZ pt_tensorrrrr-usz*validate_model_outputs..z -[x] ONNX model output names z do not match reference model zGOutputs doesn't match between reference model and ONNX exported model: u7 -[✓] ONNX model output names match reference model ()z! - Validating ONNX Model output "z":z -[x] shape z doesn't match zQOutputs shape doesn't match between reference model and ONNX exported model: Got z (reference) and z (ONNX)u -[✓] z matches )rjz& -[x] values not close enough (atol: znOutputs values doesn't match between reference model and ONNX exported model: Got max absolute difference of: u! -[✓] all values close (atol: )&rrkrlr:r;r5r r6r7r8r9rr<r=rrErrFr^rKrCrItupleZ"flatten_output_collection_propertyupdaternrunsetrHissubset differencezipdetachshapenpZallcloseZamaxabs)r#r!rhrarirjr&rkrlZreference_model_inputsoptionssessionZ ref_outputsZref_outputs_dictr+valueZ onnx_inputsrUZref_outputs_setZonnx_outputs_setZ ort_valueZ ref_valuerrrvalidate_model_outputs>sj           r~)r"rRr'csttr"tt|tr"t|jj}n t|jj}t|}t|j }|j |}|j |fdd|j D}||fS)z> :param model_inputs: :param config_inputs: :return: csg|]}|kr|qSrr)r* parameter)matching_inputsrrr[sz8ensure_model_and_config_inputs_match..) rr<r=rrZforward parameterscallrsrHrt intersection)r"rRZforward_parametersZmodel_inputs_setZforward_inputs_setZis_okZordered_inputsr)rrrGs    rG)N)rr)N)rr)N)rr)rr)N)rr)rr)rr)2r7inspectr itertoolsrpathlibrtypingrrrrr rnryZpackaging.versionr r Ztokenization_utils_baser rerrrrrr#rZmodeling_utilsrZmodeling_tf_utilsrZfeature_extraction_utilsrZtokenization_utilsr get_logger__name__r:rr intrNrXrcr(floatr~boolrGrrrrs8          #o?<(c