onnxruntime-directml 1.24.1__cp314-cp314-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- onnxruntime/LICENSE +21 -0
- onnxruntime/Privacy.md +21 -0
- onnxruntime/ThirdPartyNotices.txt +6121 -0
- onnxruntime/__init__.py +418 -0
- onnxruntime/backend/__init__.py +6 -0
- onnxruntime/backend/backend.py +175 -0
- onnxruntime/backend/backend_rep.py +52 -0
- onnxruntime/capi/DirectML.dll +0 -0
- onnxruntime/capi/__init__.py +4 -0
- onnxruntime/capi/_ld_preload.py +7 -0
- onnxruntime/capi/_pybind_state.py +33 -0
- onnxruntime/capi/build_and_package_info.py +2 -0
- onnxruntime/capi/convert_npz_to_onnx_adapter.py +48 -0
- onnxruntime/capi/onnxruntime.dll +0 -0
- onnxruntime/capi/onnxruntime_collect_build_info.py +47 -0
- onnxruntime/capi/onnxruntime_inference_collection.py +1440 -0
- onnxruntime/capi/onnxruntime_providers_shared.dll +0 -0
- onnxruntime/capi/onnxruntime_pybind11_state.pyd +0 -0
- onnxruntime/capi/onnxruntime_validation.py +154 -0
- onnxruntime/capi/version_info.py +2 -0
- onnxruntime/datasets/__init__.py +18 -0
- onnxruntime/datasets/logreg_iris.onnx +0 -0
- onnxruntime/datasets/mul_1.onnx +0 -0
- onnxruntime/datasets/sigmoid.onnx +13 -0
- onnxruntime/quantization/CalTableFlatBuffers/KeyValue.py +78 -0
- onnxruntime/quantization/CalTableFlatBuffers/TrtTable.py +90 -0
- onnxruntime/quantization/CalTableFlatBuffers/__init__.py +0 -0
- onnxruntime/quantization/__init__.py +19 -0
- onnxruntime/quantization/base_quantizer.py +529 -0
- onnxruntime/quantization/calibrate.py +1267 -0
- onnxruntime/quantization/execution_providers/qnn/__init__.py +2 -0
- onnxruntime/quantization/execution_providers/qnn/fusion_lpnorm.py +132 -0
- onnxruntime/quantization/execution_providers/qnn/fusion_spacetodepth.py +162 -0
- onnxruntime/quantization/execution_providers/qnn/mixed_precision_overrides_utils.py +413 -0
- onnxruntime/quantization/execution_providers/qnn/preprocess.py +353 -0
- onnxruntime/quantization/execution_providers/qnn/quant_config.py +389 -0
- onnxruntime/quantization/fusions/__init__.py +4 -0
- onnxruntime/quantization/fusions/fusion.py +311 -0
- onnxruntime/quantization/fusions/fusion_gelu.py +272 -0
- onnxruntime/quantization/fusions/fusion_layernorm.py +146 -0
- onnxruntime/quantization/fusions/replace_upsample_with_resize.py +96 -0
- onnxruntime/quantization/matmul_bnb4_quantizer.py +239 -0
- onnxruntime/quantization/matmul_nbits_quantizer.py +1638 -0
- onnxruntime/quantization/neural_compressor/__init__.py +1 -0
- onnxruntime/quantization/neural_compressor/onnx_model.py +1251 -0
- onnxruntime/quantization/neural_compressor/util.py +80 -0
- onnxruntime/quantization/neural_compressor/weight_only.py +932 -0
- onnxruntime/quantization/onnx_model.py +600 -0
- onnxruntime/quantization/onnx_quantizer.py +1163 -0
- onnxruntime/quantization/operators/__init__.py +2 -0
- onnxruntime/quantization/operators/activation.py +119 -0
- onnxruntime/quantization/operators/argmax.py +18 -0
- onnxruntime/quantization/operators/attention.py +73 -0
- onnxruntime/quantization/operators/base_operator.py +26 -0
- onnxruntime/quantization/operators/binary_op.py +72 -0
- onnxruntime/quantization/operators/concat.py +62 -0
- onnxruntime/quantization/operators/conv.py +260 -0
- onnxruntime/quantization/operators/direct_q8.py +78 -0
- onnxruntime/quantization/operators/embed_layernorm.py +121 -0
- onnxruntime/quantization/operators/gather.py +64 -0
- onnxruntime/quantization/operators/gavgpool.py +62 -0
- onnxruntime/quantization/operators/gemm.py +172 -0
- onnxruntime/quantization/operators/lstm.py +121 -0
- onnxruntime/quantization/operators/matmul.py +231 -0
- onnxruntime/quantization/operators/maxpool.py +34 -0
- onnxruntime/quantization/operators/norm.py +40 -0
- onnxruntime/quantization/operators/pad.py +172 -0
- onnxruntime/quantization/operators/pooling.py +67 -0
- onnxruntime/quantization/operators/qdq_base_operator.py +22 -0
- onnxruntime/quantization/operators/resize.py +34 -0
- onnxruntime/quantization/operators/softmax.py +74 -0
- onnxruntime/quantization/operators/split.py +63 -0
- onnxruntime/quantization/operators/where.py +87 -0
- onnxruntime/quantization/preprocess.py +141 -0
- onnxruntime/quantization/qdq_loss_debug.py +389 -0
- onnxruntime/quantization/qdq_quantizer.py +1477 -0
- onnxruntime/quantization/quant_utils.py +1051 -0
- onnxruntime/quantization/quantize.py +953 -0
- onnxruntime/quantization/registry.py +110 -0
- onnxruntime/quantization/shape_inference.py +204 -0
- onnxruntime/quantization/static_quantize_runner.py +256 -0
- onnxruntime/quantization/tensor_quant_overrides.py +520 -0
- onnxruntime/tools/__init__.py +10 -0
- onnxruntime/tools/check_onnx_model_mobile_usability.py +47 -0
- onnxruntime/tools/convert_onnx_models_to_ort.py +380 -0
- onnxruntime/tools/file_utils.py +47 -0
- onnxruntime/tools/logger.py +11 -0
- onnxruntime/tools/make_dynamic_shape_fixed.py +73 -0
- onnxruntime/tools/mobile_helpers/__init__.py +0 -0
- onnxruntime/tools/mobile_helpers/coreml_supported_mlprogram_ops.md +53 -0
- onnxruntime/tools/mobile_helpers/coreml_supported_neuralnetwork_ops.md +43 -0
- onnxruntime/tools/mobile_helpers/nnapi_supported_ops.md +58 -0
- onnxruntime/tools/mobile_helpers/usability_checker.py +738 -0
- onnxruntime/tools/offline_tuning.py +169 -0
- onnxruntime/tools/onnx_model_utils.py +416 -0
- onnxruntime/tools/onnx_randomizer.py +85 -0
- onnxruntime/tools/onnxruntime_test.py +164 -0
- onnxruntime/tools/optimize_onnx_model.py +56 -0
- onnxruntime/tools/ort_format_model/__init__.py +27 -0
- onnxruntime/tools/ort_format_model/operator_type_usage_processors.py +653 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/__init__.py +0 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/ArgType.py +7 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/ArgTypeAndIndex.py +67 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/Attribute.py +337 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/AttributeType.py +18 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/Checkpoint.py +125 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/DeprecatedKernelCreateInfos.py +120 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/DeprecatedNodeIndexAndKernelDefHash.py +68 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/DeprecatedSessionState.py +96 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/DeprecatedSubGraphSessionState.py +72 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/Dimension.py +71 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/DimensionValue.py +80 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/DimensionValueType.py +8 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/EdgeEnd.py +32 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/FloatProperty.py +67 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/Graph.py +320 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/InferenceSession.py +88 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/IntProperty.py +67 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/KernelTypeStrArgsEntry.py +91 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/KernelTypeStrResolver.py +78 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/MapType.py +71 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/Model.py +223 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/ModuleState.py +141 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/Node.py +317 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/NodeEdge.py +126 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/NodeType.py +7 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/NodesToOptimizeIndices.py +160 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/OpIdKernelTypeStrArgsEntry.py +91 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/OperatorSetId.py +67 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/OptimizerGroup.py +117 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/ParameterOptimizerState.py +91 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/PropertyBag.py +152 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/RuntimeOptimizationRecord.py +105 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/RuntimeOptimizationRecordContainerEntry.py +91 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/RuntimeOptimizations.py +79 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/SequenceType.py +58 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/Shape.py +78 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/SparseTensor.py +114 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/StringProperty.py +67 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/StringStringEntry.py +67 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/Tensor.py +203 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/TensorDataType.py +26 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/TensorTypeAndShape.py +71 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/TypeInfo.py +83 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/TypeInfoValue.py +9 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/ValueInfo.py +84 -0
- onnxruntime/tools/ort_format_model/ort_flatbuffers_py/fbs/__init__.py +6 -0
- onnxruntime/tools/ort_format_model/ort_model_processor.py +86 -0
- onnxruntime/tools/ort_format_model/types.py +85 -0
- onnxruntime/tools/ort_format_model/utils.py +61 -0
- onnxruntime/tools/pytorch_export_contrib_ops.py +129 -0
- onnxruntime/tools/pytorch_export_helpers.py +131 -0
- onnxruntime/tools/qdq_helpers/__init__.py +0 -0
- onnxruntime/tools/qdq_helpers/optimize_qdq_model.py +37 -0
- onnxruntime/tools/qnn/add_trans_cast.py +292 -0
- onnxruntime/tools/qnn/gen_qnn_ctx_onnx_model.py +364 -0
- onnxruntime/tools/qnn/preprocess.py +165 -0
- onnxruntime/tools/reduced_build_config_parser.py +203 -0
- onnxruntime/tools/remove_initializer_from_input.py +37 -0
- onnxruntime/tools/symbolic_shape_infer.py +3094 -0
- onnxruntime/tools/update_onnx_opset.py +31 -0
- onnxruntime/transformers/__init__.py +8 -0
- onnxruntime/transformers/affinity_helper.py +40 -0
- onnxruntime/transformers/benchmark.py +942 -0
- onnxruntime/transformers/benchmark_helper.py +643 -0
- onnxruntime/transformers/bert_perf_test.py +629 -0
- onnxruntime/transformers/bert_test_data.py +641 -0
- onnxruntime/transformers/compare_bert_results.py +256 -0
- onnxruntime/transformers/constants.py +47 -0
- onnxruntime/transformers/convert_generation.py +3605 -0
- onnxruntime/transformers/convert_tf_models_to_pytorch.py +205 -0
- onnxruntime/transformers/convert_to_packing_mode.py +385 -0
- onnxruntime/transformers/dynamo_onnx_helper.py +205 -0
- onnxruntime/transformers/float16.py +501 -0
- onnxruntime/transformers/fusion_attention.py +1189 -0
- onnxruntime/transformers/fusion_attention_clip.py +340 -0
- onnxruntime/transformers/fusion_attention_sam2.py +533 -0
- onnxruntime/transformers/fusion_attention_unet.py +1307 -0
- onnxruntime/transformers/fusion_attention_vae.py +300 -0
- onnxruntime/transformers/fusion_bart_attention.py +435 -0
- onnxruntime/transformers/fusion_base.py +141 -0
- onnxruntime/transformers/fusion_bias_add.py +57 -0
- onnxruntime/transformers/fusion_biasgelu.py +66 -0
- onnxruntime/transformers/fusion_biassplitgelu.py +110 -0
- onnxruntime/transformers/fusion_conformer_attention.py +222 -0
- onnxruntime/transformers/fusion_constant_fold.py +144 -0
- onnxruntime/transformers/fusion_embedlayer.py +810 -0
- onnxruntime/transformers/fusion_fastgelu.py +492 -0
- onnxruntime/transformers/fusion_gelu.py +258 -0
- onnxruntime/transformers/fusion_gelu_approximation.py +25 -0
- onnxruntime/transformers/fusion_gemmfastgelu.py +121 -0
- onnxruntime/transformers/fusion_gpt_attention.py +546 -0
- onnxruntime/transformers/fusion_gpt_attention_megatron.py +355 -0
- onnxruntime/transformers/fusion_gpt_attention_no_past.py +260 -0
- onnxruntime/transformers/fusion_group_norm.py +180 -0
- onnxruntime/transformers/fusion_layernorm.py +489 -0
- onnxruntime/transformers/fusion_mha_mmdit.py +667 -0
- onnxruntime/transformers/fusion_nhwc_conv.py +99 -0
- onnxruntime/transformers/fusion_options.py +340 -0
- onnxruntime/transformers/fusion_qordered_attention.py +420 -0
- onnxruntime/transformers/fusion_qordered_gelu.py +118 -0
- onnxruntime/transformers/fusion_qordered_layernorm.py +122 -0
- onnxruntime/transformers/fusion_qordered_matmul.py +216 -0
- onnxruntime/transformers/fusion_quickgelu.py +74 -0
- onnxruntime/transformers/fusion_reshape.py +173 -0
- onnxruntime/transformers/fusion_rotary_attention.py +1591 -0
- onnxruntime/transformers/fusion_shape.py +109 -0
- onnxruntime/transformers/fusion_simplified_layernorm.py +165 -0
- onnxruntime/transformers/fusion_skip_group_norm.py +254 -0
- onnxruntime/transformers/fusion_skiplayernorm.py +209 -0
- onnxruntime/transformers/fusion_transpose.py +167 -0
- onnxruntime/transformers/fusion_utils.py +321 -0
- onnxruntime/transformers/huggingface_models.py +74 -0
- onnxruntime/transformers/import_utils.py +20 -0
- onnxruntime/transformers/io_binding_helper.py +487 -0
- onnxruntime/transformers/large_model_exporter.py +395 -0
- onnxruntime/transformers/machine_info.py +230 -0
- onnxruntime/transformers/metrics.py +163 -0
- onnxruntime/transformers/models/bart/__init__.py +12 -0
- onnxruntime/transformers/models/bart/export.py +98 -0
- onnxruntime/transformers/models/bert/__init__.py +12 -0
- onnxruntime/transformers/models/bert/eval_squad.py +329 -0
- onnxruntime/transformers/models/gpt2/__init__.py +12 -0
- onnxruntime/transformers/models/gpt2/benchmark_gpt2.py +413 -0
- onnxruntime/transformers/models/gpt2/convert_to_onnx.py +566 -0
- onnxruntime/transformers/models/gpt2/gpt2_helper.py +1031 -0
- onnxruntime/transformers/models/gpt2/gpt2_parity.py +513 -0
- onnxruntime/transformers/models/gpt2/gpt2_tester.py +501 -0
- onnxruntime/transformers/models/gpt2/parity_check_helper.py +146 -0
- onnxruntime/transformers/models/llama/__init__.py +12 -0
- onnxruntime/transformers/models/llama/benchmark.py +700 -0
- onnxruntime/transformers/models/llama/benchmark_all.py +488 -0
- onnxruntime/transformers/models/llama/benchmark_e2e.py +608 -0
- onnxruntime/transformers/models/llama/convert_to_onnx.py +1064 -0
- onnxruntime/transformers/models/llama/dist_settings.py +57 -0
- onnxruntime/transformers/models/llama/llama_inputs.py +504 -0
- onnxruntime/transformers/models/llama/llama_parity.py +343 -0
- onnxruntime/transformers/models/llama/llama_torch.py +47 -0
- onnxruntime/transformers/models/llama/quant_kv_dataloader.py +108 -0
- onnxruntime/transformers/models/longformer/__init__.py +12 -0
- onnxruntime/transformers/models/longformer/benchmark_longformer.py +821 -0
- onnxruntime/transformers/models/longformer/convert_to_onnx.py +413 -0
- onnxruntime/transformers/models/longformer/generate_test_data.py +347 -0
- onnxruntime/transformers/models/longformer/longformer_helper.py +76 -0
- onnxruntime/transformers/models/phi2/__init__.py +12 -0
- onnxruntime/transformers/models/phi2/convert_to_onnx.py +590 -0
- onnxruntime/transformers/models/phi2/inference_example.py +414 -0
- onnxruntime/transformers/models/sam2/__init__.py +12 -0
- onnxruntime/transformers/models/sam2/benchmark_sam2.py +638 -0
- onnxruntime/transformers/models/sam2/convert_to_onnx.py +270 -0
- onnxruntime/transformers/models/sam2/image_decoder.py +272 -0
- onnxruntime/transformers/models/sam2/image_encoder.py +236 -0
- onnxruntime/transformers/models/sam2/mask_decoder.py +208 -0
- onnxruntime/transformers/models/sam2/nvtx_helper.py +33 -0
- onnxruntime/transformers/models/sam2/prompt_encoder.py +189 -0
- onnxruntime/transformers/models/sam2/sam2_demo.py +321 -0
- onnxruntime/transformers/models/sam2/sam2_image_onnx_predictor.py +279 -0
- onnxruntime/transformers/models/sam2/sam2_utils.py +147 -0
- onnxruntime/transformers/models/stable_diffusion/__init__.py +12 -0
- onnxruntime/transformers/models/stable_diffusion/benchmark.py +1519 -0
- onnxruntime/transformers/models/stable_diffusion/benchmark_controlnet.py +426 -0
- onnxruntime/transformers/models/stable_diffusion/demo_txt2img.py +103 -0
- onnxruntime/transformers/models/stable_diffusion/demo_txt2img_xl.py +269 -0
- onnxruntime/transformers/models/stable_diffusion/demo_utils.py +778 -0
- onnxruntime/transformers/models/stable_diffusion/diffusion_models.py +1318 -0
- onnxruntime/transformers/models/stable_diffusion/diffusion_schedulers.py +1179 -0
- onnxruntime/transformers/models/stable_diffusion/engine_builder.py +295 -0
- onnxruntime/transformers/models/stable_diffusion/engine_builder_ort_cuda.py +387 -0
- onnxruntime/transformers/models/stable_diffusion/engine_builder_ort_trt.py +288 -0
- onnxruntime/transformers/models/stable_diffusion/engine_builder_tensorrt.py +395 -0
- onnxruntime/transformers/models/stable_diffusion/engine_builder_torch.py +108 -0
- onnxruntime/transformers/models/stable_diffusion/optimize_pipeline.py +590 -0
- onnxruntime/transformers/models/stable_diffusion/ort_optimizer.py +136 -0
- onnxruntime/transformers/models/stable_diffusion/pipeline_stable_diffusion.py +831 -0
- onnxruntime/transformers/models/stable_diffusion/trt_utilities.py +12 -0
- onnxruntime/transformers/models/t5/__init__.py +12 -0
- onnxruntime/transformers/models/t5/convert_to_onnx.py +318 -0
- onnxruntime/transformers/models/t5/t5_decoder.py +437 -0
- onnxruntime/transformers/models/t5/t5_encoder.py +70 -0
- onnxruntime/transformers/models/t5/t5_encoder_decoder_init.py +361 -0
- onnxruntime/transformers/models/t5/t5_helper.py +302 -0
- onnxruntime/transformers/models/whisper/__init__.py +12 -0
- onnxruntime/transformers/models/whisper/benchmark.py +585 -0
- onnxruntime/transformers/models/whisper/benchmark_all.py +526 -0
- onnxruntime/transformers/models/whisper/convert_to_onnx.py +609 -0
- onnxruntime/transformers/models/whisper/whisper_chain.py +334 -0
- onnxruntime/transformers/models/whisper/whisper_decoder.py +464 -0
- onnxruntime/transformers/models/whisper/whisper_encoder.py +164 -0
- onnxruntime/transformers/models/whisper/whisper_encoder_decoder_init.py +371 -0
- onnxruntime/transformers/models/whisper/whisper_helper.py +1035 -0
- onnxruntime/transformers/models/whisper/whisper_inputs.py +380 -0
- onnxruntime/transformers/models/whisper/whisper_jump_times.py +477 -0
- onnxruntime/transformers/onnx_exporter.py +719 -0
- onnxruntime/transformers/onnx_model.py +1636 -0
- onnxruntime/transformers/onnx_model_bart.py +141 -0
- onnxruntime/transformers/onnx_model_bert.py +488 -0
- onnxruntime/transformers/onnx_model_bert_keras.py +474 -0
- onnxruntime/transformers/onnx_model_bert_tf.py +588 -0
- onnxruntime/transformers/onnx_model_clip.py +42 -0
- onnxruntime/transformers/onnx_model_conformer.py +32 -0
- onnxruntime/transformers/onnx_model_gpt2.py +101 -0
- onnxruntime/transformers/onnx_model_mmdit.py +112 -0
- onnxruntime/transformers/onnx_model_phi.py +929 -0
- onnxruntime/transformers/onnx_model_sam2.py +137 -0
- onnxruntime/transformers/onnx_model_t5.py +985 -0
- onnxruntime/transformers/onnx_model_tnlr.py +226 -0
- onnxruntime/transformers/onnx_model_unet.py +258 -0
- onnxruntime/transformers/onnx_model_vae.py +42 -0
- onnxruntime/transformers/onnx_utils.py +55 -0
- onnxruntime/transformers/optimizer.py +620 -0
- onnxruntime/transformers/past_helper.py +149 -0
- onnxruntime/transformers/profile_result_processor.py +358 -0
- onnxruntime/transformers/profiler.py +434 -0
- onnxruntime/transformers/quantize_helper.py +76 -0
- onnxruntime/transformers/shape_infer_helper.py +121 -0
- onnxruntime/transformers/shape_optimizer.py +400 -0
- onnxruntime/transformers/torch_onnx_export_helper.py +74 -0
- onnxruntime_directml-1.24.1.dist-info/METADATA +216 -0
- onnxruntime_directml-1.24.1.dist-info/RECORD +322 -0
- onnxruntime_directml-1.24.1.dist-info/WHEEL +5 -0
- onnxruntime_directml-1.24.1.dist-info/entry_points.txt +2 -0
- onnxruntime_directml-1.24.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License.
|
|
4
|
+
# --------------------------------------------------------------------------
|
|
5
|
+
import tensorrt as trt
|
|
6
|
+
|
|
7
|
+
TRT_LOGGER = trt.Logger(trt.Logger.ERROR)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def init_trt_plugins():
|
|
11
|
+
# Register TensorRT plugins
|
|
12
|
+
trt.init_libnvinfer_plugins(TRT_LOGGER, "")
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License.
|
|
4
|
+
# --------------------------------------------------------------------------
|
|
5
|
+
import os.path
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
sys.path.append(os.path.dirname(__file__))
|
|
9
|
+
|
|
10
|
+
transformers_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
|
11
|
+
if transformers_dir not in sys.path:
|
|
12
|
+
sys.path.append(transformers_dir)
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import copy
|
|
9
|
+
import logging
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
import torch
|
|
13
|
+
from benchmark_helper import (
|
|
14
|
+
Precision,
|
|
15
|
+
create_onnxruntime_session,
|
|
16
|
+
prepare_environment,
|
|
17
|
+
setup_logger,
|
|
18
|
+
)
|
|
19
|
+
from onnx.shape_inference import infer_shapes_path
|
|
20
|
+
from t5_helper import PRETRAINED_MT5_MODELS, PRETRAINED_T5_MODELS, T5Helper
|
|
21
|
+
from transformers import MT5Config, T5Config
|
|
22
|
+
|
|
23
|
+
logger = logging.getLogger("")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def parse_arguments():
|
|
27
|
+
parser = argparse.ArgumentParser()
|
|
28
|
+
|
|
29
|
+
pretrained_models = PRETRAINED_T5_MODELS + PRETRAINED_MT5_MODELS
|
|
30
|
+
parser.add_argument(
|
|
31
|
+
"-m",
|
|
32
|
+
"--model_name_or_path",
|
|
33
|
+
required=False,
|
|
34
|
+
default=PRETRAINED_T5_MODELS[0],
|
|
35
|
+
type=str,
|
|
36
|
+
help="Model path, or pretrained model name in the list: " + ", ".join(pretrained_models),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
parser.add_argument(
|
|
40
|
+
"--model_type",
|
|
41
|
+
required=False,
|
|
42
|
+
type=str,
|
|
43
|
+
default="t5",
|
|
44
|
+
choices=["t5", "mt5"],
|
|
45
|
+
help="Model type: either t5 (default) or mt5",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
parser.add_argument(
|
|
49
|
+
"--cache_dir",
|
|
50
|
+
required=False,
|
|
51
|
+
type=str,
|
|
52
|
+
default=os.path.join(".", "cache_models"),
|
|
53
|
+
help="Directory to cache pre-trained models",
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
parser.add_argument(
|
|
57
|
+
"--output",
|
|
58
|
+
required=False,
|
|
59
|
+
type=str,
|
|
60
|
+
default=os.path.join(".", "onnx_models"),
|
|
61
|
+
help="Output directory",
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
parser.add_argument(
|
|
65
|
+
"-o",
|
|
66
|
+
"--optimize_onnx",
|
|
67
|
+
required=False,
|
|
68
|
+
action="store_true",
|
|
69
|
+
help="Use optimizer.py to optimize onnx model",
|
|
70
|
+
)
|
|
71
|
+
parser.set_defaults(optimize_onnx=False)
|
|
72
|
+
|
|
73
|
+
parser.add_argument("--use_gpu", required=False, action="store_true", help="use GPU for inference")
|
|
74
|
+
parser.set_defaults(use_gpu=False)
|
|
75
|
+
|
|
76
|
+
parser.add_argument(
|
|
77
|
+
"-p",
|
|
78
|
+
"--precision",
|
|
79
|
+
required=False,
|
|
80
|
+
type=str,
|
|
81
|
+
default=Precision.FLOAT32.value,
|
|
82
|
+
choices=[Precision.FLOAT32.value, Precision.FLOAT16.value],
|
|
83
|
+
help="Precision of model to run. fp32 for full precision, fp16 for half precision",
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
parser.add_argument("--verbose", required=False, action="store_true")
|
|
87
|
+
parser.set_defaults(verbose=False)
|
|
88
|
+
|
|
89
|
+
parser.add_argument("-e", "--use_external_data_format", required=False, action="store_true")
|
|
90
|
+
parser.set_defaults(use_external_data_format=False)
|
|
91
|
+
|
|
92
|
+
parser.add_argument(
|
|
93
|
+
"-s",
|
|
94
|
+
"--use_decoder_start_token",
|
|
95
|
+
required=False,
|
|
96
|
+
action="store_true",
|
|
97
|
+
help="Use config.decoder_start_token_id. Otherwise, add an extra graph input for decoder_input_ids.",
|
|
98
|
+
)
|
|
99
|
+
parser.set_defaults(use_decoder_start_token=False)
|
|
100
|
+
|
|
101
|
+
parser.add_argument(
|
|
102
|
+
"-w",
|
|
103
|
+
"--overwrite",
|
|
104
|
+
required=False,
|
|
105
|
+
action="store_true",
|
|
106
|
+
help="overwrite existing ONNX model",
|
|
107
|
+
)
|
|
108
|
+
parser.set_defaults(overwrite=False)
|
|
109
|
+
|
|
110
|
+
parser.add_argument(
|
|
111
|
+
"--disable_auto_mixed_precision",
|
|
112
|
+
required=False,
|
|
113
|
+
action="store_true",
|
|
114
|
+
help="do not use auto mixed precision conversion",
|
|
115
|
+
)
|
|
116
|
+
parser.set_defaults(disable_auto_mixed_precision=False)
|
|
117
|
+
|
|
118
|
+
parser.add_argument(
|
|
119
|
+
"--force_fp16_io",
|
|
120
|
+
required=False,
|
|
121
|
+
action="store_true",
|
|
122
|
+
help="Force to convert all float inputs and outputs to fp16 when precision is fp16.",
|
|
123
|
+
)
|
|
124
|
+
parser.set_defaults(force_fp16_io=False)
|
|
125
|
+
|
|
126
|
+
parser.add_argument(
|
|
127
|
+
"--use_int64_inputs",
|
|
128
|
+
required=False,
|
|
129
|
+
action="store_true",
|
|
130
|
+
help="Use int64 instead of int32 for input_ids, position_ids and attention_mask.",
|
|
131
|
+
)
|
|
132
|
+
parser.set_defaults(use_int64_inputs=False)
|
|
133
|
+
|
|
134
|
+
parser.add_argument(
|
|
135
|
+
"--state_dict_path",
|
|
136
|
+
type=str,
|
|
137
|
+
default="",
|
|
138
|
+
help="filepath to load pre-trained model with custom state dictionary (e.g. pytorch_model.bin)",
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
parser.add_argument(
|
|
142
|
+
"--encoder_decoder_init",
|
|
143
|
+
required=False,
|
|
144
|
+
action="store_true",
|
|
145
|
+
help="Combine encoder and decoder kv cache initialization into one model. It is legacy format that will be deprecated.",
|
|
146
|
+
)
|
|
147
|
+
parser.set_defaults(encoder_decoder_init=False)
|
|
148
|
+
|
|
149
|
+
args = parser.parse_args()
|
|
150
|
+
|
|
151
|
+
return args
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def export_onnx_models(
|
|
155
|
+
model_name_or_path: str,
|
|
156
|
+
cache_dir: str,
|
|
157
|
+
output_dir: str,
|
|
158
|
+
use_gpu: bool = False,
|
|
159
|
+
use_external_data_format: bool = False,
|
|
160
|
+
optimize_onnx: bool = False,
|
|
161
|
+
precision: str = Precision.FLOAT32.value,
|
|
162
|
+
verbose: bool = False,
|
|
163
|
+
use_decoder_start_token: bool = False,
|
|
164
|
+
overwrite: bool = False,
|
|
165
|
+
disable_auto_mixed_precision: bool = False,
|
|
166
|
+
use_int32_inputs: bool = True,
|
|
167
|
+
model_type: str = "t5",
|
|
168
|
+
state_dict_path: str = "",
|
|
169
|
+
encoder_decoder_init: bool = False,
|
|
170
|
+
force_fp16_io: bool = False,
|
|
171
|
+
shape_infer_before_optimization: bool = False,
|
|
172
|
+
):
|
|
173
|
+
assert precision in [Precision.FLOAT32.value, Precision.FLOAT16.value], (
|
|
174
|
+
f"Invalid precision: {precision}. Use 'fp32' or 'fp16'."
|
|
175
|
+
)
|
|
176
|
+
device = torch.device("cuda:0" if use_gpu else "cpu")
|
|
177
|
+
|
|
178
|
+
models = T5Helper.load_model(
|
|
179
|
+
model_name_or_path,
|
|
180
|
+
cache_dir,
|
|
181
|
+
device,
|
|
182
|
+
model_type,
|
|
183
|
+
state_dict_path,
|
|
184
|
+
encoder_decoder_init=encoder_decoder_init,
|
|
185
|
+
)
|
|
186
|
+
config: T5Config | MT5Config = models["decoder"].config
|
|
187
|
+
|
|
188
|
+
if (not use_external_data_format) and (config.num_layers > 24):
|
|
189
|
+
logger.info("Try use_external_data_format when model size > 2GB")
|
|
190
|
+
|
|
191
|
+
output_paths = []
|
|
192
|
+
for name, model in models.items():
|
|
193
|
+
model.to(device)
|
|
194
|
+
filename_suffix = "_" + name
|
|
195
|
+
|
|
196
|
+
onnx_path = T5Helper.get_onnx_path(
|
|
197
|
+
output_dir,
|
|
198
|
+
model_name_or_path,
|
|
199
|
+
suffix=filename_suffix,
|
|
200
|
+
new_folder=False,
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
if overwrite or not os.path.exists(onnx_path):
|
|
204
|
+
logger.info(f"Exporting ONNX model to {onnx_path}")
|
|
205
|
+
# We have to clone model before exporting onnx, otherwise verify_onnx will report large difference.
|
|
206
|
+
cloned_model = copy.deepcopy(model).to(device)
|
|
207
|
+
T5Helper.export_onnx(
|
|
208
|
+
cloned_model,
|
|
209
|
+
device,
|
|
210
|
+
onnx_path,
|
|
211
|
+
verbose,
|
|
212
|
+
use_external_data_format,
|
|
213
|
+
use_decoder_input_ids=not use_decoder_start_token,
|
|
214
|
+
use_int32_inputs=use_int32_inputs,
|
|
215
|
+
)
|
|
216
|
+
else:
|
|
217
|
+
logger.info(f"Skip exporting: existed ONNX model {onnx_path}")
|
|
218
|
+
|
|
219
|
+
# Optimize ONNX graph.
|
|
220
|
+
# The precision shall be compared with string value. It is because the Precision enum loaded from local file
|
|
221
|
+
# (like by transformers test in CI pipeline) are not same as Precision enum from package.
|
|
222
|
+
if optimize_onnx or precision != Precision.FLOAT32.value:
|
|
223
|
+
onnx_shape_path = None
|
|
224
|
+
if shape_infer_before_optimization:
|
|
225
|
+
onnx_shape_path = T5Helper.get_onnx_path(
|
|
226
|
+
output_dir,
|
|
227
|
+
model_name_or_path,
|
|
228
|
+
suffix=filename_suffix + "_shape",
|
|
229
|
+
new_folder=False,
|
|
230
|
+
)
|
|
231
|
+
infer_shapes_path(onnx_path, onnx_shape_path)
|
|
232
|
+
|
|
233
|
+
output_path = T5Helper.get_onnx_path(
|
|
234
|
+
output_dir,
|
|
235
|
+
model_name_or_path,
|
|
236
|
+
suffix=filename_suffix + "_" + str(precision),
|
|
237
|
+
new_folder=False,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
if overwrite or not os.path.exists(output_path):
|
|
241
|
+
logger.info(f"Optimizing model to {output_path}")
|
|
242
|
+
T5Helper.optimize_onnx(
|
|
243
|
+
onnx_shape_path or onnx_path,
|
|
244
|
+
output_path,
|
|
245
|
+
precision == Precision.FLOAT16.value,
|
|
246
|
+
config.num_heads,
|
|
247
|
+
config.hidden_size,
|
|
248
|
+
use_external_data_format,
|
|
249
|
+
auto_mixed_precision=not disable_auto_mixed_precision,
|
|
250
|
+
use_gpu=use_gpu,
|
|
251
|
+
force_fp16_io=force_fp16_io,
|
|
252
|
+
)
|
|
253
|
+
else:
|
|
254
|
+
logger.info(f"Skip optimizing: existed ONNX model {output_path}")
|
|
255
|
+
else:
|
|
256
|
+
output_path = onnx_path
|
|
257
|
+
|
|
258
|
+
ort_session = create_onnxruntime_session(
|
|
259
|
+
output_path,
|
|
260
|
+
use_gpu=use_gpu,
|
|
261
|
+
verbose=verbose,
|
|
262
|
+
)
|
|
263
|
+
if ort_session is None:
|
|
264
|
+
break
|
|
265
|
+
|
|
266
|
+
with torch.no_grad():
|
|
267
|
+
max_diff = T5Helper.verify_onnx(model, ort_session, device, use_int32_inputs)
|
|
268
|
+
logger.info(f"PyTorch and OnnxRuntime results max difference = {max_diff}")
|
|
269
|
+
|
|
270
|
+
# The threshold cannot apply to fp16 model, which need a larger threshold.
|
|
271
|
+
if precision == Precision.FLOAT32.value and max_diff > 1e-4:
|
|
272
|
+
logger.warning("PyTorch and OnnxRuntime results are NOT close")
|
|
273
|
+
|
|
274
|
+
output_paths.append(output_path)
|
|
275
|
+
|
|
276
|
+
return output_paths
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def main():
|
|
280
|
+
args = parse_arguments()
|
|
281
|
+
|
|
282
|
+
setup_logger(args.verbose)
|
|
283
|
+
|
|
284
|
+
logger.info(f"Arguments:{args}")
|
|
285
|
+
|
|
286
|
+
cache_dir = args.cache_dir
|
|
287
|
+
output_dir = args.output if not args.output.endswith(".onnx") else os.path.dirname(args.output)
|
|
288
|
+
prepare_environment(cache_dir, output_dir, args.use_gpu)
|
|
289
|
+
|
|
290
|
+
if args.precision != Precision.FLOAT32.value:
|
|
291
|
+
assert args.optimize_onnx, "fp16/int8 requires --optimize_onnx"
|
|
292
|
+
|
|
293
|
+
if args.precision == Precision.FLOAT16.value:
|
|
294
|
+
assert args.use_gpu, "fp16 requires --use_gpu"
|
|
295
|
+
|
|
296
|
+
output_paths = export_onnx_models(
|
|
297
|
+
args.model_name_or_path,
|
|
298
|
+
cache_dir,
|
|
299
|
+
output_dir,
|
|
300
|
+
args.use_gpu,
|
|
301
|
+
args.use_external_data_format,
|
|
302
|
+
args.optimize_onnx,
|
|
303
|
+
args.precision,
|
|
304
|
+
args.verbose,
|
|
305
|
+
args.use_decoder_start_token,
|
|
306
|
+
args.overwrite,
|
|
307
|
+
args.disable_auto_mixed_precision,
|
|
308
|
+
not args.use_int64_inputs,
|
|
309
|
+
args.model_type,
|
|
310
|
+
encoder_decoder_init=args.encoder_decoder_init,
|
|
311
|
+
force_fp16_io=args.force_fp16_io,
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
logger.info(f"Done! Outputs: {output_paths}")
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
if __name__ == "__main__":
|
|
318
|
+
main()
|