onnxruntime-directml 1.20.0__cp313-cp313-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 +6508 -0
- onnxruntime/__init__.py +78 -0
- onnxruntime/backend/__init__.py +6 -0
- onnxruntime/backend/backend.py +174 -0
- onnxruntime/backend/backend_rep.py +53 -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/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 +1108 -0
- onnxruntime/capi/onnxruntime_providers_shared.dll +0 -0
- onnxruntime/capi/onnxruntime_pybind11_state.pyd +0 -0
- onnxruntime/capi/onnxruntime_validation.py +150 -0
- onnxruntime/capi/version_info.py +2 -0
- onnxruntime/datasets/__init__.py +17 -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 +16 -0
- onnxruntime/quantization/base_quantizer.py +532 -0
- onnxruntime/quantization/calibrate.py +1245 -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/mixed_precision_overrides_utils.py +413 -0
- onnxruntime/quantization/execution_providers/qnn/preprocess.py +307 -0
- onnxruntime/quantization/execution_providers/qnn/quant_config.py +387 -0
- onnxruntime/quantization/fusions/__init__.py +3 -0
- onnxruntime/quantization/fusions/fusion.py +311 -0
- onnxruntime/quantization/fusions/fusion_gelu.py +272 -0
- onnxruntime/quantization/fusions/fusion_layernorm.py +135 -0
- onnxruntime/quantization/matmul_4bits_quantizer.py +1480 -0
- onnxruntime/quantization/matmul_bnb4_quantizer.py +240 -0
- onnxruntime/quantization/onnx_model.py +580 -0
- onnxruntime/quantization/onnx_quantizer.py +1008 -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 +258 -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 +166 -0
- onnxruntime/quantization/operators/lstm.py +117 -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 +100 -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 +1187 -0
- onnxruntime/quantization/quant_utils.py +891 -0
- onnxruntime/quantization/quantize.py +748 -0
- onnxruntime/quantization/registry.py +106 -0
- onnxruntime/quantization/shape_inference.py +187 -0
- onnxruntime/quantization/tensor_quant_overrides.py +516 -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 +377 -0
- onnxruntime/tools/file_utils.py +46 -0
- onnxruntime/tools/logger.py +11 -0
- onnxruntime/tools/make_dynamic_shape_fixed.py +72 -0
- onnxruntime/tools/mobile_helpers/__init__.py +0 -0
- onnxruntime/tools/mobile_helpers/coreml_supported_mlprogram_ops.md +33 -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 +739 -0
- onnxruntime/tools/offline_tuning.py +169 -0
- onnxruntime/tools/onnx_model_utils.py +413 -0
- onnxruntime/tools/onnx_randomizer.py +85 -0
- onnxruntime/tools/onnxruntime_test.py +164 -0
- onnxruntime/tools/optimize_onnx_model.py +55 -0
- onnxruntime/tools/ort_format_model/__init__.py +25 -0
- onnxruntime/tools/ort_format_model/operator_type_usage_processors.py +663 -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 +84 -0
- onnxruntime/tools/ort_format_model/utils.py +62 -0
- onnxruntime/tools/pytorch_export_contrib_ops.py +108 -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/reduced_build_config_parser.py +202 -0
- onnxruntime/tools/symbolic_shape_infer.py +3016 -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 +944 -0
- onnxruntime/transformers/benchmark_helper.py +646 -0
- onnxruntime/transformers/bert_perf_test.py +634 -0
- onnxruntime/transformers/bert_test_data.py +642 -0
- onnxruntime/transformers/compare_bert_results.py +246 -0
- onnxruntime/transformers/constants.py +47 -0
- onnxruntime/transformers/convert_generation.py +3124 -0
- onnxruntime/transformers/convert_tf_models_to_pytorch.py +205 -0
- onnxruntime/transformers/convert_to_packing_mode.py +387 -0
- onnxruntime/transformers/dynamo_onnx_helper.py +104 -0
- onnxruntime/transformers/float16.py +501 -0
- onnxruntime/transformers/fusion_attention.py +1235 -0
- onnxruntime/transformers/fusion_attention_clip.py +257 -0
- onnxruntime/transformers/fusion_attention_sam2.py +534 -0
- onnxruntime/transformers/fusion_attention_unet.py +1304 -0
- onnxruntime/transformers/fusion_attention_vae.py +301 -0
- onnxruntime/transformers/fusion_bart_attention.py +640 -0
- onnxruntime/transformers/fusion_base.py +137 -0
- onnxruntime/transformers/fusion_bias_add.py +58 -0
- onnxruntime/transformers/fusion_biasgelu.py +66 -0
- onnxruntime/transformers/fusion_biassplitgelu.py +111 -0
- onnxruntime/transformers/fusion_conformer_attention.py +143 -0
- onnxruntime/transformers/fusion_embedlayer.py +811 -0
- onnxruntime/transformers/fusion_fastgelu.py +360 -0
- onnxruntime/transformers/fusion_gelu.py +259 -0
- onnxruntime/transformers/fusion_gelu_approximation.py +25 -0
- onnxruntime/transformers/fusion_gemmfastgelu.py +122 -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 +179 -0
- onnxruntime/transformers/fusion_layernorm.py +465 -0
- onnxruntime/transformers/fusion_nhwc_conv.py +100 -0
- onnxruntime/transformers/fusion_options.py +340 -0
- onnxruntime/transformers/fusion_qordered_attention.py +421 -0
- onnxruntime/transformers/fusion_qordered_gelu.py +119 -0
- onnxruntime/transformers/fusion_qordered_layernorm.py +123 -0
- onnxruntime/transformers/fusion_qordered_matmul.py +217 -0
- onnxruntime/transformers/fusion_quickgelu.py +74 -0
- onnxruntime/transformers/fusion_reshape.py +173 -0
- onnxruntime/transformers/fusion_rotary_attention.py +1592 -0
- onnxruntime/transformers/fusion_shape.py +110 -0
- onnxruntime/transformers/fusion_simplified_layernorm.py +159 -0
- onnxruntime/transformers/fusion_skip_group_norm.py +255 -0
- onnxruntime/transformers/fusion_skiplayernorm.py +209 -0
- onnxruntime/transformers/fusion_transpose.py +168 -0
- onnxruntime/transformers/fusion_utils.py +307 -0
- onnxruntime/transformers/huggingface_models.py +167 -0
- onnxruntime/transformers/import_utils.py +20 -0
- onnxruntime/transformers/io_binding_helper.py +442 -0
- onnxruntime/transformers/large_model_exporter.py +395 -0
- onnxruntime/transformers/machine_info.py +221 -0
- onnxruntime/transformers/metrics.py +164 -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 +561 -0
- onnxruntime/transformers/models/gpt2/gpt2_helper.py +1032 -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 +703 -0
- onnxruntime/transformers/models/llama/benchmark_all.py +488 -0
- onnxruntime/transformers/models/llama/benchmark_e2e.py +606 -0
- onnxruntime/transformers/models/llama/convert_to_onnx.py +1027 -0
- onnxruntime/transformers/models/llama/dist_settings.py +57 -0
- onnxruntime/transformers/models/llama/llama_inputs.py +503 -0
- onnxruntime/transformers/models/llama/llama_parity.py +309 -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 +77 -0
- onnxruntime/transformers/models/phi2/__init__.py +12 -0
- onnxruntime/transformers/models/phi2/convert_to_onnx.py +576 -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 +625 -0
- onnxruntime/transformers/models/sam2/convert_to_onnx.py +260 -0
- onnxruntime/transformers/models/sam2/image_decoder.py +273 -0
- onnxruntime/transformers/models/sam2/image_encoder.py +186 -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 +322 -0
- onnxruntime/transformers/models/sam2/sam2_image_onnx_predictor.py +280 -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 +1429 -0
- onnxruntime/transformers/models/stable_diffusion/benchmark_controlnet.py +426 -0
- onnxruntime/transformers/models/stable_diffusion/demo_txt2img.py +102 -0
- onnxruntime/transformers/models/stable_diffusion/demo_txt2img_xl.py +268 -0
- onnxruntime/transformers/models/stable_diffusion/demo_utils.py +778 -0
- onnxruntime/transformers/models/stable_diffusion/diffusion_models.py +1319 -0
- onnxruntime/transformers/models/stable_diffusion/diffusion_schedulers.py +1181 -0
- onnxruntime/transformers/models/stable_diffusion/engine_builder.py +296 -0
- onnxruntime/transformers/models/stable_diffusion/engine_builder_ort_cuda.py +388 -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 +350 -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 +278 -0
- onnxruntime/transformers/models/t5/past_helper.py +150 -0
- onnxruntime/transformers/models/t5/t5_decoder.py +438 -0
- onnxruntime/transformers/models/t5/t5_encoder.py +171 -0
- onnxruntime/transformers/models/t5/t5_encoder_decoder_init.py +299 -0
- onnxruntime/transformers/models/t5/t5_helper.py +272 -0
- onnxruntime/transformers/models/whisper/__init__.py +12 -0
- onnxruntime/transformers/models/whisper/benchmark.py +610 -0
- onnxruntime/transformers/models/whisper/benchmark_all.py +528 -0
- onnxruntime/transformers/models/whisper/convert_to_onnx.py +536 -0
- onnxruntime/transformers/models/whisper/whisper_chain.py +329 -0
- onnxruntime/transformers/models/whisper/whisper_decoder.py +402 -0
- onnxruntime/transformers/models/whisper/whisper_encoder.py +164 -0
- onnxruntime/transformers/models/whisper/whisper_encoder_decoder_init.py +306 -0
- onnxruntime/transformers/models/whisper/whisper_helper.py +524 -0
- onnxruntime/transformers/models/whisper/whisper_openai_helper.py +84 -0
- onnxruntime/transformers/onnx_exporter.py +717 -0
- onnxruntime/transformers/onnx_model.py +1569 -0
- onnxruntime/transformers/onnx_model_bart.py +142 -0
- onnxruntime/transformers/onnx_model_bert.py +481 -0
- onnxruntime/transformers/onnx_model_bert_keras.py +475 -0
- onnxruntime/transformers/onnx_model_bert_tf.py +589 -0
- onnxruntime/transformers/onnx_model_clip.py +40 -0
- onnxruntime/transformers/onnx_model_conformer.py +33 -0
- onnxruntime/transformers/onnx_model_gpt2.py +101 -0
- onnxruntime/transformers/onnx_model_phi.py +930 -0
- onnxruntime/transformers/onnx_model_sam2.py +138 -0
- onnxruntime/transformers/onnx_model_t5.py +791 -0
- onnxruntime/transformers/onnx_model_tnlr.py +227 -0
- onnxruntime/transformers/onnx_model_unet.py +259 -0
- onnxruntime/transformers/onnx_model_vae.py +43 -0
- onnxruntime/transformers/onnx_utils.py +55 -0
- onnxruntime/transformers/optimizer.py +612 -0
- onnxruntime/transformers/profiler.py +725 -0
- onnxruntime/transformers/quantize_helper.py +76 -0
- onnxruntime/transformers/shape_infer_helper.py +122 -0
- onnxruntime/transformers/shape_optimizer.py +401 -0
- onnxruntime/transformers/torch_onnx_export_helper.py +74 -0
- onnxruntime_directml-1.20.0.dist-info/METADATA +187 -0
- onnxruntime_directml-1.20.0.dist-info/RECORD +305 -0
- onnxruntime_directml-1.20.0.dist-info/WHEEL +5 -0
- onnxruntime_directml-1.20.0.dist-info/entry_points.txt +2 -0
- onnxruntime_directml-1.20.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License.
|
|
4
|
+
# --------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
# It is a tool to compare the inference results of the original model and optimized model.
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import statistics
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
import psutil
|
|
14
|
+
from bert_perf_test import create_session, onnxruntime_inference
|
|
15
|
+
from bert_test_data import generate_test_data, get_bert_inputs, output_test_data
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def run_model(model_path, all_inputs, use_gpu, disable_optimization):
|
|
19
|
+
import onnxruntime
|
|
20
|
+
|
|
21
|
+
graph_optimization_level = None
|
|
22
|
+
if disable_optimization:
|
|
23
|
+
graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_DISABLE_ALL
|
|
24
|
+
|
|
25
|
+
intra_op_num_threads = psutil.cpu_count(logical=False)
|
|
26
|
+
|
|
27
|
+
session = create_session(
|
|
28
|
+
model_path, use_gpu, "cuda" if use_gpu else "cpu", intra_op_num_threads, graph_optimization_level
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
output_names = [output.name for output in session.get_outputs()]
|
|
32
|
+
results, latency_list = onnxruntime_inference(session, all_inputs, output_names)
|
|
33
|
+
return results, latency_list, output_names
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def compare(baseline_results, treatment_results, verbose, rtol=1e-1, atol=1e-3):
|
|
37
|
+
# Validate the output of baseline and treatment, to make sure the results are similar.
|
|
38
|
+
diff_count = 0
|
|
39
|
+
max_abs_diff = 0
|
|
40
|
+
for test_case_id, results in enumerate(baseline_results):
|
|
41
|
+
case_passed = True
|
|
42
|
+
for i in range(len(results)):
|
|
43
|
+
treatment_output = treatment_results[test_case_id][i]
|
|
44
|
+
abs_diff = np.amax(np.abs(treatment_output - results[i]))
|
|
45
|
+
if verbose and abs_diff > atol:
|
|
46
|
+
print("abs_diff", abs_diff)
|
|
47
|
+
print("treatment", treatment_output)
|
|
48
|
+
print("baseline", results[i])
|
|
49
|
+
|
|
50
|
+
max_abs_diff = max(max_abs_diff, abs_diff)
|
|
51
|
+
if not np.allclose(results[i].tolist(), treatment_output.tolist(), rtol=rtol, atol=atol):
|
|
52
|
+
if case_passed:
|
|
53
|
+
case_passed = False
|
|
54
|
+
diff_count += 1
|
|
55
|
+
|
|
56
|
+
if verbose:
|
|
57
|
+
print(f"case {test_case_id} output {i}")
|
|
58
|
+
print(f"baseline={results[i].tolist()}\ntreatment={treatment_output}")
|
|
59
|
+
print(f"abs_diff={abs_diff}")
|
|
60
|
+
|
|
61
|
+
if diff_count == 0:
|
|
62
|
+
print(f"100% passed for {len(baseline_results)} random inputs given thresholds (rtol={rtol}, atol={atol}).")
|
|
63
|
+
else:
|
|
64
|
+
print(
|
|
65
|
+
f"WARNING: {diff_count} out of {len(baseline_results)} results NOT passed for thresholds (rtol={rtol}, atol={atol})."
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
print(f"maximum absolute difference={max_abs_diff}")
|
|
69
|
+
return max_abs_diff, case_passed
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def run_test(
|
|
73
|
+
baseline_model,
|
|
74
|
+
optimized_model,
|
|
75
|
+
output_dir,
|
|
76
|
+
batch_size,
|
|
77
|
+
sequence_length,
|
|
78
|
+
use_gpu,
|
|
79
|
+
test_cases,
|
|
80
|
+
seed,
|
|
81
|
+
verbose,
|
|
82
|
+
rtol,
|
|
83
|
+
atol,
|
|
84
|
+
input_ids_name,
|
|
85
|
+
segment_ids_name,
|
|
86
|
+
input_mask_name,
|
|
87
|
+
mask_type,
|
|
88
|
+
):
|
|
89
|
+
# Try deduce input names from optimized model.
|
|
90
|
+
input_ids, segment_ids, input_mask = get_bert_inputs(
|
|
91
|
+
optimized_model, input_ids_name, segment_ids_name, input_mask_name
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# Use random mask length for accuracy test. It might introduce slight inflation in latency reported in this script.
|
|
95
|
+
average_sequence_length = int(sequence_length / 2) if sequence_length >= 2 else sequence_length
|
|
96
|
+
all_inputs = generate_test_data(
|
|
97
|
+
batch_size,
|
|
98
|
+
sequence_length,
|
|
99
|
+
test_cases,
|
|
100
|
+
seed,
|
|
101
|
+
verbose,
|
|
102
|
+
input_ids,
|
|
103
|
+
segment_ids,
|
|
104
|
+
input_mask,
|
|
105
|
+
average_sequence_length,
|
|
106
|
+
True, # random sequence length
|
|
107
|
+
mask_type,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
baseline_results, baseline_latency, output_names = run_model(
|
|
111
|
+
baseline_model, all_inputs, use_gpu, disable_optimization=True
|
|
112
|
+
)
|
|
113
|
+
if verbose:
|
|
114
|
+
print(f"baseline average latency (all optimizations disabled): {statistics.mean(baseline_latency) * 1000} ms")
|
|
115
|
+
|
|
116
|
+
if output_dir is not None:
|
|
117
|
+
for i, inputs in enumerate(all_inputs):
|
|
118
|
+
output_test_data(output_dir, i, inputs)
|
|
119
|
+
|
|
120
|
+
treatment_results, treatment_latency, treatment_output_names = run_model(
|
|
121
|
+
optimized_model, all_inputs, use_gpu, disable_optimization=False
|
|
122
|
+
)
|
|
123
|
+
if verbose:
|
|
124
|
+
print(f"treatment average latency: {statistics.mean(treatment_latency) * 1000} ms")
|
|
125
|
+
|
|
126
|
+
# Validate the output of baseline and treatment, to make sure the results are similar.
|
|
127
|
+
return compare(baseline_results, treatment_results, verbose, rtol, atol)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def parse_arguments():
|
|
131
|
+
parser = argparse.ArgumentParser()
|
|
132
|
+
parser.add_argument("--baseline_model", required=True, type=str, help="baseline onnx model path.")
|
|
133
|
+
|
|
134
|
+
parser.add_argument(
|
|
135
|
+
"--optimized_model",
|
|
136
|
+
required=True,
|
|
137
|
+
type=str,
|
|
138
|
+
default=None,
|
|
139
|
+
help="path of the optimized model. It shall have same inputs as the baseline model.",
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
parser.add_argument(
|
|
143
|
+
"--output_dir",
|
|
144
|
+
required=False,
|
|
145
|
+
type=str,
|
|
146
|
+
default=None,
|
|
147
|
+
help="output test data path. If not specified, test data will not be saved.",
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
parser.add_argument("--batch_size", required=True, type=int, help="batch size of input")
|
|
151
|
+
|
|
152
|
+
parser.add_argument(
|
|
153
|
+
"--sequence_length",
|
|
154
|
+
required=True,
|
|
155
|
+
type=int,
|
|
156
|
+
help="maximum sequence length of input",
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
parser.add_argument("--rtol", required=False, type=float, default=1e-3, help="relative tolerance")
|
|
160
|
+
|
|
161
|
+
parser.add_argument("--atol", required=False, type=float, default=1e-4, help="absolute tolerance")
|
|
162
|
+
|
|
163
|
+
parser.add_argument(
|
|
164
|
+
"--samples",
|
|
165
|
+
required=False,
|
|
166
|
+
type=int,
|
|
167
|
+
default=100,
|
|
168
|
+
help="number of test cases to be generated",
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
parser.add_argument("--seed", required=False, type=int, default=3, help="random seed")
|
|
172
|
+
|
|
173
|
+
parser.add_argument("--use_gpu", required=False, action="store_true", help="use GPU")
|
|
174
|
+
parser.set_defaults(use_gpu=False)
|
|
175
|
+
|
|
176
|
+
parser.add_argument(
|
|
177
|
+
"--verbose",
|
|
178
|
+
required=False,
|
|
179
|
+
action="store_true",
|
|
180
|
+
help="print verbose information",
|
|
181
|
+
)
|
|
182
|
+
parser.set_defaults(verbose=False)
|
|
183
|
+
|
|
184
|
+
parser.add_argument(
|
|
185
|
+
"--input_ids",
|
|
186
|
+
required=False,
|
|
187
|
+
type=str,
|
|
188
|
+
default=None,
|
|
189
|
+
help="input name for input ids",
|
|
190
|
+
)
|
|
191
|
+
parser.add_argument(
|
|
192
|
+
"--segment_ids",
|
|
193
|
+
required=False,
|
|
194
|
+
type=str,
|
|
195
|
+
default=None,
|
|
196
|
+
help="input name for segment ids",
|
|
197
|
+
)
|
|
198
|
+
parser.add_argument(
|
|
199
|
+
"--input_mask",
|
|
200
|
+
required=False,
|
|
201
|
+
type=str,
|
|
202
|
+
default=None,
|
|
203
|
+
help="input name for attention mask",
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
parser.add_argument(
|
|
207
|
+
"--mask_type",
|
|
208
|
+
required=False,
|
|
209
|
+
type=int,
|
|
210
|
+
default=2,
|
|
211
|
+
help="mask type: (1: mask index or sequence length, 2: raw 2D mask, 3: key len, cumulated lengths of query and key)",
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
args = parser.parse_args()
|
|
215
|
+
return args
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def main():
|
|
219
|
+
args = parse_arguments()
|
|
220
|
+
|
|
221
|
+
if args.output_dir is not None:
|
|
222
|
+
# create the output directory if not existed
|
|
223
|
+
path = Path(args.output_dir)
|
|
224
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
225
|
+
|
|
226
|
+
run_test(
|
|
227
|
+
args.baseline_model,
|
|
228
|
+
args.optimized_model,
|
|
229
|
+
args.output_dir,
|
|
230
|
+
args.batch_size,
|
|
231
|
+
args.sequence_length,
|
|
232
|
+
args.use_gpu,
|
|
233
|
+
args.samples,
|
|
234
|
+
args.seed,
|
|
235
|
+
args.verbose,
|
|
236
|
+
args.rtol,
|
|
237
|
+
args.atol,
|
|
238
|
+
args.input_ids,
|
|
239
|
+
args.segment_ids,
|
|
240
|
+
args.input_mask,
|
|
241
|
+
args.mask_type,
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
if __name__ == "__main__":
|
|
246
|
+
main()
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License.
|
|
4
|
+
# --------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Operators:
|
|
8
|
+
ATTENTION = "Attention"
|
|
9
|
+
LAYERNORM = "LayerNormalization"
|
|
10
|
+
MULTI_HEAD_ATTENTION = "MultiHeadAttention"
|
|
11
|
+
PACKEDATTENTION = "PackedAttention"
|
|
12
|
+
PACKED_MULTI_HEAD_ATTENTION = "PackedMultiHeadAttention"
|
|
13
|
+
REMOVEPADDING = "RemovePadding"
|
|
14
|
+
RESTOREPADDING = "RestorePadding"
|
|
15
|
+
SKIPLAYERNORM = "SkipLayerNormalization"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AttentionInputIDs:
|
|
19
|
+
INPUT = 0
|
|
20
|
+
WEIGHTS = 1
|
|
21
|
+
BIAS = 2
|
|
22
|
+
MASK_INDEX = 3
|
|
23
|
+
PAST = 4
|
|
24
|
+
ATTENTION_BIAS = 5
|
|
25
|
+
PAST_SEQUENCE_LENGTH = 6
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class AttentionOutputIDs:
|
|
29
|
+
OUTPUT = 0
|
|
30
|
+
PRESENT = 1
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class MultiHeadAttentionInputIDs:
|
|
34
|
+
QUERY = 0
|
|
35
|
+
KEY = 1
|
|
36
|
+
VALUE = 2
|
|
37
|
+
BIAS = 3
|
|
38
|
+
KEY_PADDING_MASK = 4
|
|
39
|
+
ATTENTION_BIAS = 5
|
|
40
|
+
PAST_KEY = 6
|
|
41
|
+
PAST_VALUE = 7
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class MultiHeadAttentionOutputIDs:
|
|
45
|
+
OUTPUT = 0
|
|
46
|
+
PRESENT_KEY = 1
|
|
47
|
+
PRESENT_VALUE = 2
|