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,132 @@
|
|
|
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
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import onnx
|
|
9
|
+
|
|
10
|
+
from ...fusions import Fusion
|
|
11
|
+
from ...onnx_model import ONNXModel
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class FusionLpNormalization(Fusion):
|
|
15
|
+
def __init__(self, model: ONNXModel, epsilon: float = 1e-12):
|
|
16
|
+
super().__init__(model, "LpNormalization", "ReduceL2")
|
|
17
|
+
self.epsilon = epsilon
|
|
18
|
+
|
|
19
|
+
def fuse(
|
|
20
|
+
self,
|
|
21
|
+
reduce_node: onnx.NodeProto,
|
|
22
|
+
input_name_to_nodes: dict[str, list[onnx.NodeProto]],
|
|
23
|
+
output_name_to_node: dict[str, onnx.NodeProto],
|
|
24
|
+
):
|
|
25
|
+
"""
|
|
26
|
+
Interface function that tries to fuse a node sequence containing a ReduceL2 node into a single
|
|
27
|
+
LpNormalization node.
|
|
28
|
+
|
|
29
|
+
Pattern 1:
|
|
30
|
+
[root] --> ReduceL2 -----> Clip --> Expand ----> Div -->
|
|
31
|
+
| (axis=-1) (min=epsilon) (shape=root) ^
|
|
32
|
+
| (keepdims=True) |
|
|
33
|
+
| |
|
|
34
|
+
+-----------------------------------------------+
|
|
35
|
+
Notes:
|
|
36
|
+
- ReduceL2 must use the last axis, and keepdims == True
|
|
37
|
+
- Clip must only have a min attribute that is ~1e-12
|
|
38
|
+
- Expand must restore the shape to root.shape
|
|
39
|
+
- The output of Expand must be the second input to Div.
|
|
40
|
+
"""
|
|
41
|
+
if reduce_node.output[0] not in input_name_to_nodes:
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
# ReduceL2 must have one Clip child
|
|
45
|
+
children = input_name_to_nodes[reduce_node.output[0]]
|
|
46
|
+
if len(children) != 1 or children[0].op_type != "Clip":
|
|
47
|
+
return
|
|
48
|
+
|
|
49
|
+
# ReduceL2 must have keepdims == True
|
|
50
|
+
keepdims = self.get_node_attribute(reduce_node, "keepdims")
|
|
51
|
+
if not keepdims:
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
# ReduceL2 axes must refer only to the last dimension.
|
|
55
|
+
# Axes became an input in opset 18. Before then, axes was an attribute
|
|
56
|
+
reduce_input_ttype = self.model.get_tensor_type(reduce_node.input[0])
|
|
57
|
+
if not reduce_input_ttype:
|
|
58
|
+
return
|
|
59
|
+
|
|
60
|
+
reduce_input_shape = self.tensor_shape_to_list(reduce_input_ttype)
|
|
61
|
+
if not reduce_input_shape:
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
axes = self.get_node_attribute(reduce_node, "axes")
|
|
65
|
+
if not axes and len(reduce_node.input) > 1:
|
|
66
|
+
axes = self.model.get_constant_value(reduce_node.input[1])
|
|
67
|
+
|
|
68
|
+
if not axes or len(axes) != 1:
|
|
69
|
+
return
|
|
70
|
+
|
|
71
|
+
last_dim = len(reduce_input_shape) - 1
|
|
72
|
+
if axes[0] != -1 and axes[0] != last_dim:
|
|
73
|
+
return
|
|
74
|
+
|
|
75
|
+
# Clip node must have a min attribute approximately equal to 1e-12
|
|
76
|
+
clip_node = children[0]
|
|
77
|
+
clip_min = self.get_node_attribute(clip_node, "min")
|
|
78
|
+
if clip_min is None and len(clip_node.input) > 1:
|
|
79
|
+
clip_min = self.model.get_constant_value(clip_node.input[1])
|
|
80
|
+
|
|
81
|
+
clip_max = self.get_node_attribute(clip_node, "max") # TODO: clip_max could be FLOAT_MAX
|
|
82
|
+
if clip_max is None and len(clip_node.input) > 2:
|
|
83
|
+
clip_max = self.model.get_constant_value(clip_node.input[2])
|
|
84
|
+
|
|
85
|
+
if not (clip_max is None and clip_min is not None and clip_min > 0 and abs(clip_min - self.epsilon) < 1e-13):
|
|
86
|
+
return
|
|
87
|
+
|
|
88
|
+
if clip_node.output[0] not in input_name_to_nodes:
|
|
89
|
+
return
|
|
90
|
+
|
|
91
|
+
# Clip must have a single Expand child.
|
|
92
|
+
children = input_name_to_nodes[clip_node.output[0]]
|
|
93
|
+
if len(children) != 1 or children[0].op_type != "Expand":
|
|
94
|
+
return
|
|
95
|
+
|
|
96
|
+
expand_node = children[0]
|
|
97
|
+
if expand_node.output[0] not in input_name_to_nodes:
|
|
98
|
+
return
|
|
99
|
+
|
|
100
|
+
# Expand must have a single Div child
|
|
101
|
+
children = input_name_to_nodes[expand_node.output[0]]
|
|
102
|
+
if len(children) != 1 or children[0].op_type != "Div":
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
div_node = children[0]
|
|
106
|
+
|
|
107
|
+
# The first input to Div must be the root of the subgraph (i.e., reduce_node.input[0])
|
|
108
|
+
# The second input to Div must be the output of the Expand.
|
|
109
|
+
# As long as these two inputs go to the same Div node, then ONNX validation will ensure that
|
|
110
|
+
# their shapes match.
|
|
111
|
+
if div_node.input[0] != reduce_node.input[0]:
|
|
112
|
+
return
|
|
113
|
+
if div_node.input[1] != expand_node.output[0]:
|
|
114
|
+
return
|
|
115
|
+
|
|
116
|
+
subgraph_input = reduce_node.input[0]
|
|
117
|
+
subgraph_output = div_node.output[0]
|
|
118
|
+
|
|
119
|
+
subgraph_nodes = [reduce_node, clip_node, expand_node, div_node]
|
|
120
|
+
if not self.is_safe_to_fuse_nodes(subgraph_nodes, [subgraph_output], input_name_to_nodes, output_name_to_node):
|
|
121
|
+
return
|
|
122
|
+
|
|
123
|
+
self.nodes_to_remove.extend(subgraph_nodes)
|
|
124
|
+
fused_node = onnx.helper.make_node(
|
|
125
|
+
self.fused_op_type,
|
|
126
|
+
name=self.create_unique_node_name(),
|
|
127
|
+
inputs=[subgraph_input],
|
|
128
|
+
outputs=[subgraph_output],
|
|
129
|
+
p=2,
|
|
130
|
+
axis=-1,
|
|
131
|
+
)
|
|
132
|
+
self.nodes_to_add.append(fused_node)
|
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
"""Define SpaceToDepth fusion."""
|
|
7
|
+
|
|
8
|
+
import onnx
|
|
9
|
+
|
|
10
|
+
from ... import fusions, onnx_model
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FusionSpaceToDepth(fusions.Fusion):
|
|
14
|
+
"""Fusion for SpaceToDepth."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, model: onnx_model.ONNXModel):
|
|
17
|
+
"""Initialize.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
model: An onnx_model.ONNXModel instance.
|
|
21
|
+
"""
|
|
22
|
+
super().__init__(model, "SpaceToDepth", "Reshape")
|
|
23
|
+
|
|
24
|
+
def _fuse_yolo(
|
|
25
|
+
self,
|
|
26
|
+
node: onnx.NodeProto,
|
|
27
|
+
input_name_to_nodes: dict[str, list[onnx.NodeProto]],
|
|
28
|
+
output_name_to_node: dict[str, onnx.NodeProto],
|
|
29
|
+
):
|
|
30
|
+
"""Fuse for early version of YOLO.
|
|
31
|
+
|
|
32
|
+
Pattern:
|
|
33
|
+
|
|
34
|
+
| [N, C, H, W]
|
|
35
|
+
Reshape
|
|
36
|
+
| [N, C, H/blk, blk, W/blk, blk]
|
|
37
|
+
Transpose
|
|
38
|
+
| [N, C, H/blk, W/blk, blk, blk]
|
|
39
|
+
Reshape
|
|
40
|
+
| [N, C, H/blk * W/blk, blk * blk]
|
|
41
|
+
Transpose
|
|
42
|
+
| [N, C, blk * blk, H/blk * W/blk]
|
|
43
|
+
Reshape
|
|
44
|
+
| [N, C, blk * blk, H/blk, W/blk]
|
|
45
|
+
Transpose
|
|
46
|
+
| [N, blk * blk, C, H/blk, W/blk]
|
|
47
|
+
Reshape
|
|
48
|
+
| [N, blk * blk * C, H/blk, W/blk]
|
|
49
|
+
|
|
50
|
+
This sequence can be fused into a single SpaceToDepth with blocksize `blk`. Note that unlike DepthToSpace
|
|
51
|
+
supporting DCR or CRD mode, SpaceToDepth only supports DCR mode in its latest opset version (13), which matches
|
|
52
|
+
the pattern here.
|
|
53
|
+
"""
|
|
54
|
+
reshape_node1 = node
|
|
55
|
+
|
|
56
|
+
def get_target_child(parent_node, target_op_type):
|
|
57
|
+
"""Get target child of given node."""
|
|
58
|
+
if parent_node.output[0] not in input_name_to_nodes:
|
|
59
|
+
return None
|
|
60
|
+
|
|
61
|
+
children = input_name_to_nodes[parent_node.output[0]]
|
|
62
|
+
if len(children) > 1 or children[0].op_type != target_op_type:
|
|
63
|
+
return None
|
|
64
|
+
|
|
65
|
+
return children[0]
|
|
66
|
+
|
|
67
|
+
if (
|
|
68
|
+
(transpose_node1 := get_target_child(reshape_node1, "Transpose")) is None
|
|
69
|
+
or (reshape_node2 := get_target_child(transpose_node1, "Reshape")) is None
|
|
70
|
+
or (transpose_node2 := get_target_child(reshape_node2, "Transpose")) is None
|
|
71
|
+
or (reshape_node3 := get_target_child(transpose_node2, "Reshape")) is None
|
|
72
|
+
or (transpose_node3 := get_target_child(reshape_node3, "Transpose")) is None
|
|
73
|
+
or (reshape_node4 := get_target_child(transpose_node3, "Reshape")) is None
|
|
74
|
+
):
|
|
75
|
+
return False
|
|
76
|
+
|
|
77
|
+
def get_tensor_shape(tensor_name):
|
|
78
|
+
"""Get shape for given tensor name."""
|
|
79
|
+
tensor_type = self.model.get_tensor_type(tensor_name)
|
|
80
|
+
if not tensor_type:
|
|
81
|
+
return None
|
|
82
|
+
|
|
83
|
+
tensor_shape = self.tensor_shape_to_list(tensor_type)
|
|
84
|
+
if not tensor_shape:
|
|
85
|
+
return None
|
|
86
|
+
|
|
87
|
+
return tensor_shape
|
|
88
|
+
|
|
89
|
+
if (
|
|
90
|
+
(input_shape := get_tensor_shape(reshape_node1.input[0])) is None
|
|
91
|
+
or (reshape_shape1 := get_tensor_shape(reshape_node1.output[0])) is None
|
|
92
|
+
or (reshape_shape2 := get_tensor_shape(reshape_node2.output[0])) is None
|
|
93
|
+
or (reshape_shape3 := get_tensor_shape(reshape_node3.output[0])) is None
|
|
94
|
+
or (reshape_shape4 := get_tensor_shape(reshape_node4.output[0])) is None
|
|
95
|
+
):
|
|
96
|
+
return False
|
|
97
|
+
|
|
98
|
+
transpose_perm1 = self.get_node_attribute(transpose_node1, "perm")
|
|
99
|
+
transpose_perm2 = self.get_node_attribute(transpose_node2, "perm")
|
|
100
|
+
transpose_perm3 = self.get_node_attribute(transpose_node3, "perm")
|
|
101
|
+
|
|
102
|
+
# Check rank.
|
|
103
|
+
if (
|
|
104
|
+
len(input_shape) != 4
|
|
105
|
+
or len(reshape_shape1) != 6
|
|
106
|
+
or len(reshape_shape2) != 4
|
|
107
|
+
or len(reshape_shape3) != 5
|
|
108
|
+
or len(reshape_shape4) != 4
|
|
109
|
+
):
|
|
110
|
+
return False
|
|
111
|
+
|
|
112
|
+
# Check shape and perm.
|
|
113
|
+
batch, channel, height, width = input_shape
|
|
114
|
+
blocksize = reshape_shape1[3]
|
|
115
|
+
if (
|
|
116
|
+
reshape_shape1 != [batch, channel, height // blocksize, blocksize, width // blocksize, blocksize]
|
|
117
|
+
or transpose_perm1 != [0, 1, 2, 4, 3, 5]
|
|
118
|
+
or reshape_shape2 != [batch, channel, (height // blocksize) * (width // blocksize), blocksize**2]
|
|
119
|
+
or transpose_perm2 != [0, 1, 3, 2]
|
|
120
|
+
or reshape_shape3 != [batch, channel, blocksize**2, height // blocksize, width // blocksize]
|
|
121
|
+
or transpose_perm3 != [0, 2, 1, 3, 4]
|
|
122
|
+
or reshape_shape4 != [batch, blocksize**2 * channel, height // blocksize, width // blocksize]
|
|
123
|
+
):
|
|
124
|
+
return False
|
|
125
|
+
|
|
126
|
+
self.nodes_to_remove.extend(
|
|
127
|
+
[
|
|
128
|
+
reshape_node1,
|
|
129
|
+
transpose_node1,
|
|
130
|
+
reshape_node2,
|
|
131
|
+
transpose_node2,
|
|
132
|
+
reshape_node3,
|
|
133
|
+
transpose_node3,
|
|
134
|
+
reshape_node4,
|
|
135
|
+
]
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
s2d_node = onnx.helper.make_node(
|
|
139
|
+
self.fused_op_type,
|
|
140
|
+
name=self.create_unique_node_name(),
|
|
141
|
+
inputs=[reshape_node1.input[0]],
|
|
142
|
+
outputs=[reshape_node4.output[0]],
|
|
143
|
+
blocksize=blocksize,
|
|
144
|
+
)
|
|
145
|
+
self.nodes_to_add.append(s2d_node)
|
|
146
|
+
|
|
147
|
+
return True
|
|
148
|
+
|
|
149
|
+
def fuse(
|
|
150
|
+
self,
|
|
151
|
+
node: onnx.NodeProto,
|
|
152
|
+
input_name_to_nodes: dict[str, list[onnx.NodeProto]],
|
|
153
|
+
output_name_to_node: dict[str, onnx.NodeProto],
|
|
154
|
+
):
|
|
155
|
+
"""Fuse a sequence of Reshape and Transpose nodes into a single SpaceToDepth node.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
node: An onnx.NodeProto matching the specified search type (i.e., Reshape).
|
|
159
|
+
input_name_to_nodes: A dict mapping tensor name to consumed nodes.
|
|
160
|
+
output_name_to_node: A dict mapping tensor name to produced node.
|
|
161
|
+
"""
|
|
162
|
+
self._fuse_yolo(node, input_name_to_nodes, output_name_to_node)
|