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,258 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License.
|
|
4
|
+
# --------------------------------------------------------------------------
|
|
5
|
+
from logging import getLogger
|
|
6
|
+
|
|
7
|
+
from fusion_base import Fusion
|
|
8
|
+
from onnx import helper
|
|
9
|
+
from onnx_model import OnnxModel
|
|
10
|
+
|
|
11
|
+
logger = getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class FusionGelu(Fusion):
|
|
15
|
+
def __init__(self, model: OnnxModel):
|
|
16
|
+
super().__init__(model, "Gelu", "Erf")
|
|
17
|
+
|
|
18
|
+
def fuse(self, erf_node, input_name_to_nodes: dict, output_name_to_node: dict):
|
|
19
|
+
if self.fuse_1(erf_node, input_name_to_nodes, output_name_to_node):
|
|
20
|
+
return
|
|
21
|
+
if self.fuse_2(erf_node, input_name_to_nodes, output_name_to_node):
|
|
22
|
+
return
|
|
23
|
+
self.fuse_3(erf_node, input_name_to_nodes, output_name_to_node)
|
|
24
|
+
|
|
25
|
+
def fuse_1(self, erf_node, input_name_to_nodes: dict, output_name_to_node: dict) -> bool | None:
|
|
26
|
+
"""
|
|
27
|
+
This pattern is from PyTorch model
|
|
28
|
+
Fuse Gelu with Erf into one node:
|
|
29
|
+
Pattern 1:
|
|
30
|
+
+-------Mul(0.5)---------------------+
|
|
31
|
+
| |
|
|
32
|
+
| v
|
|
33
|
+
[root] --> Div -----> Erf --> Add --> Mul -->
|
|
34
|
+
(B=1.4142...) (1)
|
|
35
|
+
|
|
36
|
+
Pattern 2:
|
|
37
|
+
+------------------------------------+
|
|
38
|
+
| |
|
|
39
|
+
| v
|
|
40
|
+
[root] --> Div -----> Erf --> Add --> Mul -->Mul -->
|
|
41
|
+
(B=1.4142...) (1) (0.5)
|
|
42
|
+
|
|
43
|
+
Note that constant input for Add and Mul could be first or second input: like either A=0.5 or B=0.5 is fine.
|
|
44
|
+
"""
|
|
45
|
+
if erf_node.output[0] not in input_name_to_nodes:
|
|
46
|
+
return
|
|
47
|
+
children = input_name_to_nodes[erf_node.output[0]]
|
|
48
|
+
if len(children) != 1 or children[0].op_type != "Add":
|
|
49
|
+
return
|
|
50
|
+
add_after_erf = children[0]
|
|
51
|
+
|
|
52
|
+
if not self.model.has_constant_input(add_after_erf, 1):
|
|
53
|
+
return
|
|
54
|
+
|
|
55
|
+
if add_after_erf.output[0] not in input_name_to_nodes:
|
|
56
|
+
return
|
|
57
|
+
children = input_name_to_nodes[add_after_erf.output[0]]
|
|
58
|
+
if len(children) != 1 or children[0].op_type != "Mul":
|
|
59
|
+
return
|
|
60
|
+
mul_after_erf = children[0]
|
|
61
|
+
|
|
62
|
+
div = self.model.match_parent(erf_node, "Div", 0, output_name_to_node)
|
|
63
|
+
if div is None:
|
|
64
|
+
return
|
|
65
|
+
|
|
66
|
+
if self.model.find_constant_input(div, 1.4142, delta=0.001) != 1:
|
|
67
|
+
return
|
|
68
|
+
|
|
69
|
+
subgraph_input = div.input[0]
|
|
70
|
+
|
|
71
|
+
another = 1 if mul_after_erf.input[0] == add_after_erf.output[0] else 0
|
|
72
|
+
if subgraph_input == mul_after_erf.input[another]: # pattern 2
|
|
73
|
+
children = input_name_to_nodes[mul_after_erf.output[0]]
|
|
74
|
+
if len(children) != 1 or children[0].op_type != "Mul":
|
|
75
|
+
return
|
|
76
|
+
mul_half = children[0]
|
|
77
|
+
if not self.model.has_constant_input(mul_half, 0.5):
|
|
78
|
+
return
|
|
79
|
+
subgraph_output = mul_half.output[0]
|
|
80
|
+
else: # pattern 1
|
|
81
|
+
mul_half = self.model.match_parent(mul_after_erf, "Mul", another, output_name_to_node)
|
|
82
|
+
if mul_half is None:
|
|
83
|
+
return
|
|
84
|
+
|
|
85
|
+
if not self.model.has_constant_input(mul_half, 0.5):
|
|
86
|
+
return
|
|
87
|
+
|
|
88
|
+
if subgraph_input not in mul_half.input:
|
|
89
|
+
return
|
|
90
|
+
|
|
91
|
+
subgraph_output = mul_after_erf.output[0]
|
|
92
|
+
|
|
93
|
+
subgraph_nodes = [div, erf_node, add_after_erf, mul_after_erf, mul_half]
|
|
94
|
+
if not self.model.is_safe_to_fuse_nodes(
|
|
95
|
+
subgraph_nodes, [subgraph_output], input_name_to_nodes, output_name_to_node
|
|
96
|
+
):
|
|
97
|
+
return
|
|
98
|
+
|
|
99
|
+
self.nodes_to_remove.extend(subgraph_nodes)
|
|
100
|
+
fused_node = helper.make_node(
|
|
101
|
+
"Gelu", inputs=[subgraph_input], outputs=[subgraph_output], name=self.model.create_node_name("Gelu")
|
|
102
|
+
)
|
|
103
|
+
fused_node.domain = "com.microsoft"
|
|
104
|
+
self.nodes_to_add.append(fused_node)
|
|
105
|
+
self.node_name_to_graph_name[fused_node.name] = self.this_graph_name
|
|
106
|
+
self.increase_counter("Gelu")
|
|
107
|
+
return True
|
|
108
|
+
|
|
109
|
+
def fuse_2(self, erf_node, input_name_to_nodes: dict, output_name_to_node: dict) -> bool | None:
|
|
110
|
+
"""
|
|
111
|
+
This pattern is from Keras model
|
|
112
|
+
Fuse Gelu with Erf into one node:
|
|
113
|
+
+------------------------------------------+
|
|
114
|
+
| |
|
|
115
|
+
| v
|
|
116
|
+
[root] --> Div -----> Erf --> Add --> Mul -->Mul
|
|
117
|
+
(B=1.4142...) (A=1) (A=0.5)
|
|
118
|
+
|
|
119
|
+
Note that constant input for Add and Mul could be first or second input: like either A=0.5 or B=0.5 is fine.
|
|
120
|
+
"""
|
|
121
|
+
if erf_node.output[0] not in input_name_to_nodes:
|
|
122
|
+
return
|
|
123
|
+
children = input_name_to_nodes[erf_node.output[0]]
|
|
124
|
+
if len(children) != 1 or children[0].op_type != "Add":
|
|
125
|
+
return
|
|
126
|
+
add_after_erf = children[0]
|
|
127
|
+
|
|
128
|
+
if not self.model.has_constant_input(add_after_erf, 1):
|
|
129
|
+
return
|
|
130
|
+
|
|
131
|
+
if add_after_erf.output[0] not in input_name_to_nodes:
|
|
132
|
+
return
|
|
133
|
+
children = input_name_to_nodes[add_after_erf.output[0]]
|
|
134
|
+
if len(children) != 1 or children[0].op_type != "Mul":
|
|
135
|
+
return
|
|
136
|
+
mul_after_erf = children[0]
|
|
137
|
+
|
|
138
|
+
if not self.model.has_constant_input(mul_after_erf, 0.5):
|
|
139
|
+
return
|
|
140
|
+
|
|
141
|
+
if mul_after_erf.output[0] not in input_name_to_nodes:
|
|
142
|
+
return
|
|
143
|
+
children = input_name_to_nodes[mul_after_erf.output[0]]
|
|
144
|
+
if len(children) != 1 or children[0].op_type != "Mul":
|
|
145
|
+
return
|
|
146
|
+
mul = children[0]
|
|
147
|
+
|
|
148
|
+
div = self.model.match_parent(erf_node, "Div", 0, output_name_to_node)
|
|
149
|
+
if div is None:
|
|
150
|
+
return
|
|
151
|
+
|
|
152
|
+
sqrt_node = None
|
|
153
|
+
if self.model.find_constant_input(div, 1.4142, delta=0.001) != 1:
|
|
154
|
+
sqrt_node = self.model.match_parent(div, "Sqrt", 1, output_name_to_node)
|
|
155
|
+
if sqrt_node is None:
|
|
156
|
+
return
|
|
157
|
+
if not self.model.has_constant_input(sqrt_node, 2.0):
|
|
158
|
+
return
|
|
159
|
+
|
|
160
|
+
root_node = self.model.get_parent(div, 0, output_name_to_node)
|
|
161
|
+
if root_node is None:
|
|
162
|
+
return
|
|
163
|
+
|
|
164
|
+
if root_node.output[0] not in mul.input:
|
|
165
|
+
return
|
|
166
|
+
|
|
167
|
+
subgraph_nodes = [div, erf_node, add_after_erf, mul_after_erf, mul]
|
|
168
|
+
if sqrt_node:
|
|
169
|
+
subgraph_nodes.append(sqrt_node)
|
|
170
|
+
|
|
171
|
+
if not self.model.is_safe_to_fuse_nodes(
|
|
172
|
+
subgraph_nodes, [mul.output[0]], input_name_to_nodes, output_name_to_node
|
|
173
|
+
):
|
|
174
|
+
return
|
|
175
|
+
|
|
176
|
+
self.nodes_to_remove.extend(subgraph_nodes)
|
|
177
|
+
fused_node = helper.make_node(
|
|
178
|
+
"Gelu", inputs=[root_node.output[0]], outputs=[mul.output[0]], name=self.model.create_node_name("Gelu")
|
|
179
|
+
)
|
|
180
|
+
fused_node.domain = "com.microsoft"
|
|
181
|
+
self.nodes_to_add.append(fused_node)
|
|
182
|
+
self.node_name_to_graph_name[fused_node.name] = self.this_graph_name
|
|
183
|
+
self.increase_counter("Gelu")
|
|
184
|
+
return True
|
|
185
|
+
|
|
186
|
+
def fuse_3(self, erf_node, input_name_to_nodes: dict, output_name_to_node: dict) -> bool | None:
|
|
187
|
+
"""
|
|
188
|
+
This pattern is from TensorFlow model
|
|
189
|
+
Fuse Gelu with Erf into one node:
|
|
190
|
+
+----------------------------------------------+
|
|
191
|
+
| |
|
|
192
|
+
| v
|
|
193
|
+
[root] --> Mul -----> Erf --> Add --> Mul -->Mul
|
|
194
|
+
(A=0.7071067690849304) (B=1) (B=0.5)
|
|
195
|
+
|
|
196
|
+
Note that constant input for Add and Mul could be first or second input: like either A=0.5 or B=0.5 is fine.
|
|
197
|
+
"""
|
|
198
|
+
|
|
199
|
+
if erf_node.output[0] not in input_name_to_nodes:
|
|
200
|
+
return
|
|
201
|
+
children = input_name_to_nodes[erf_node.output[0]]
|
|
202
|
+
if len(children) != 1 or children[0].op_type != "Add":
|
|
203
|
+
return
|
|
204
|
+
add_after_erf = children[0]
|
|
205
|
+
|
|
206
|
+
if not self.model.has_constant_input(add_after_erf, 1):
|
|
207
|
+
return
|
|
208
|
+
|
|
209
|
+
if add_after_erf.output[0] not in input_name_to_nodes:
|
|
210
|
+
return
|
|
211
|
+
children = input_name_to_nodes[add_after_erf.output[0]]
|
|
212
|
+
if len(children) != 1 or children[0].op_type != "Mul":
|
|
213
|
+
return
|
|
214
|
+
mul_half = children[0]
|
|
215
|
+
|
|
216
|
+
if not self.model.has_constant_input(mul_half, 0.5):
|
|
217
|
+
return
|
|
218
|
+
|
|
219
|
+
first_mul = self.model.match_parent(erf_node, "Mul", 0, output_name_to_node)
|
|
220
|
+
if first_mul is None:
|
|
221
|
+
return
|
|
222
|
+
|
|
223
|
+
i = self.model.find_constant_input(first_mul, 0.7071067690849304, delta=0.001)
|
|
224
|
+
if i < 0:
|
|
225
|
+
return
|
|
226
|
+
|
|
227
|
+
root_node = self.model.get_parent(first_mul, 0 if i == 1 else 1, output_name_to_node)
|
|
228
|
+
if root_node is None:
|
|
229
|
+
return
|
|
230
|
+
|
|
231
|
+
if mul_half.output[0] not in input_name_to_nodes:
|
|
232
|
+
return
|
|
233
|
+
children = input_name_to_nodes[mul_half.output[0]]
|
|
234
|
+
if len(children) != 1 or children[0].op_type != "Mul":
|
|
235
|
+
return
|
|
236
|
+
last_mul = children[0]
|
|
237
|
+
|
|
238
|
+
if not (last_mul.input[0] == root_node.output[0] or last_mul.input[1] == root_node.output[0]):
|
|
239
|
+
return
|
|
240
|
+
|
|
241
|
+
subgraph_nodes = [first_mul, erf_node, add_after_erf, mul_half, last_mul]
|
|
242
|
+
if not self.model.is_safe_to_fuse_nodes(
|
|
243
|
+
subgraph_nodes,
|
|
244
|
+
[last_mul.output[0]],
|
|
245
|
+
input_name_to_nodes,
|
|
246
|
+
output_name_to_node,
|
|
247
|
+
):
|
|
248
|
+
return
|
|
249
|
+
|
|
250
|
+
self.nodes_to_remove.extend(subgraph_nodes)
|
|
251
|
+
fused_node = helper.make_node(
|
|
252
|
+
"Gelu", inputs=[root_node.output[0]], outputs=[last_mul.output[0]], name=self.model.create_node_name("Gelu")
|
|
253
|
+
)
|
|
254
|
+
fused_node.domain = "com.microsoft"
|
|
255
|
+
self.nodes_to_add.append(fused_node)
|
|
256
|
+
self.node_name_to_graph_name[fused_node.name] = self.this_graph_name
|
|
257
|
+
self.increase_counter("Gelu")
|
|
258
|
+
return True
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License.
|
|
4
|
+
# --------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
from fusion_base import Fusion
|
|
7
|
+
from onnx import helper
|
|
8
|
+
from onnx_model import OnnxModel
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class FusionGeluApproximation(Fusion):
|
|
12
|
+
def __init__(self, model: OnnxModel):
|
|
13
|
+
super().__init__(model, "FastGelu", ["Gelu", "BiasGelu"], "GeluApproximation")
|
|
14
|
+
|
|
15
|
+
def fuse(self, node, input_name_to_nodes, output_name_to_node):
|
|
16
|
+
new_node = helper.make_node(
|
|
17
|
+
"FastGelu",
|
|
18
|
+
inputs=node.input,
|
|
19
|
+
outputs=node.output,
|
|
20
|
+
name=self.model.create_node_name("FastGelu", node.op_type + "_Approximation"),
|
|
21
|
+
)
|
|
22
|
+
new_node.domain = "com.microsoft"
|
|
23
|
+
self.nodes_to_remove.append(node)
|
|
24
|
+
self.nodes_to_add.append(new_node)
|
|
25
|
+
self.node_name_to_graph_name[new_node.name] = self.this_graph_name
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License.
|
|
4
|
+
# --------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
from logging import getLogger
|
|
7
|
+
|
|
8
|
+
from fusion_base import Fusion
|
|
9
|
+
from fusion_utils import NumpyHelper
|
|
10
|
+
from onnx import NodeProto, TensorProto, helper
|
|
11
|
+
from onnx_model import OnnxModel
|
|
12
|
+
|
|
13
|
+
logger = getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class FusionGemmFastGelu(Fusion):
|
|
17
|
+
def __init__(self, model: OnnxModel):
|
|
18
|
+
super().__init__(model, "GemmFastGelu", "FastGelu", "GemmFastGelu")
|
|
19
|
+
self.shape_infer = None
|
|
20
|
+
self.shape_infer_done = False
|
|
21
|
+
|
|
22
|
+
def get_dimensions_from_tensor_proto(self, tensor_proto: TensorProto) -> int | None:
|
|
23
|
+
if tensor_proto.type.tensor_type.HasField("shape"):
|
|
24
|
+
return len(tensor_proto.type.tensor_type.shape.dim)
|
|
25
|
+
else:
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
def get_dimensions(self, input_name: str) -> int | None:
|
|
29
|
+
graph_input = self.model.find_graph_input(input_name)
|
|
30
|
+
if graph_input:
|
|
31
|
+
return self.get_dimensions_from_tensor_proto(graph_input)
|
|
32
|
+
|
|
33
|
+
if not self.shape_infer_done:
|
|
34
|
+
self.shape_infer = self.model.infer_runtime_shape(update=True)
|
|
35
|
+
self.shape_infer_done = True
|
|
36
|
+
|
|
37
|
+
if self.shape_infer is not None:
|
|
38
|
+
return self.get_dimensions_from_tensor_proto(self.shape_infer.known_vi_[input_name])
|
|
39
|
+
|
|
40
|
+
return None
|
|
41
|
+
|
|
42
|
+
def fuse(
|
|
43
|
+
self,
|
|
44
|
+
node: NodeProto,
|
|
45
|
+
input_name_to_nodes: dict[str, list[NodeProto]],
|
|
46
|
+
output_name_to_node: dict[str, NodeProto],
|
|
47
|
+
):
|
|
48
|
+
"""
|
|
49
|
+
This pattern is from PyTorch bert model
|
|
50
|
+
Fuse MatMul with FastGelu into one node:
|
|
51
|
+
|
|
52
|
+
[root] --> MatMul --> FastGelu -->
|
|
53
|
+
|
|
54
|
+
"""
|
|
55
|
+
has_bias = False
|
|
56
|
+
if len(node.input) == 2:
|
|
57
|
+
has_bias = True
|
|
58
|
+
|
|
59
|
+
match_nodes = self.model.match_parent_path(node, ["MatMul"], [0])
|
|
60
|
+
if match_nodes is None:
|
|
61
|
+
return
|
|
62
|
+
matmul = match_nodes[0]
|
|
63
|
+
|
|
64
|
+
# matmul input X should >= two dimension, input weight should be two dimension
|
|
65
|
+
weight_index = -1
|
|
66
|
+
x_dims = 0
|
|
67
|
+
weight = None
|
|
68
|
+
|
|
69
|
+
for i, input in enumerate(matmul.input):
|
|
70
|
+
initializer = self.model.get_initializer(input)
|
|
71
|
+
if initializer is None:
|
|
72
|
+
x_dims = self.get_dimensions(matmul.input[i])
|
|
73
|
+
else:
|
|
74
|
+
weight_index = i
|
|
75
|
+
weight = NumpyHelper.to_array(initializer)
|
|
76
|
+
if weight is None:
|
|
77
|
+
return
|
|
78
|
+
if len(weight.shape) != 2:
|
|
79
|
+
return
|
|
80
|
+
if x_dims < len(weight.shape):
|
|
81
|
+
return
|
|
82
|
+
|
|
83
|
+
# bias weight should be one dimension
|
|
84
|
+
bias_index = -1
|
|
85
|
+
if has_bias:
|
|
86
|
+
bias_weight = None
|
|
87
|
+
for i, input in enumerate(node.input):
|
|
88
|
+
initializer = self.model.get_initializer(input)
|
|
89
|
+
if initializer is None:
|
|
90
|
+
continue
|
|
91
|
+
bias_index = i
|
|
92
|
+
bias_weight = NumpyHelper.to_array(initializer)
|
|
93
|
+
break
|
|
94
|
+
if bias_weight is None:
|
|
95
|
+
return
|
|
96
|
+
if len(bias_weight.shape) != 1:
|
|
97
|
+
return
|
|
98
|
+
|
|
99
|
+
subgraph_nodes = [node, matmul]
|
|
100
|
+
if not self.model.is_safe_to_fuse_nodes(
|
|
101
|
+
subgraph_nodes, [node.output[0]], input_name_to_nodes, output_name_to_node
|
|
102
|
+
):
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
self.nodes_to_remove.extend(subgraph_nodes)
|
|
106
|
+
|
|
107
|
+
inputs = (
|
|
108
|
+
[matmul.input[1 - weight_index], matmul.input[weight_index], node.input[bias_index]]
|
|
109
|
+
if has_bias
|
|
110
|
+
else [matmul.input[1 - weight_index], matmul.input[weight_index]]
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
fused_node = helper.make_node(
|
|
114
|
+
"GemmFastGelu",
|
|
115
|
+
inputs=inputs,
|
|
116
|
+
outputs=node.output,
|
|
117
|
+
name=self.model.create_node_name("GemmFastGelu"),
|
|
118
|
+
)
|
|
119
|
+
fused_node.domain = "com.microsoft"
|
|
120
|
+
self.nodes_to_add.append(fused_node)
|
|
121
|
+
self.node_name_to_graph_name[fused_node.name] = self.this_graph_name
|