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,638 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License.
|
|
4
|
+
# --------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
Benchmark performance of SAM2 encoder with ORT or PyTorch. See benchmark_sam2.sh for usage.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import csv
|
|
12
|
+
import statistics
|
|
13
|
+
import time
|
|
14
|
+
from collections.abc import Mapping
|
|
15
|
+
from datetime import datetime
|
|
16
|
+
|
|
17
|
+
import torch
|
|
18
|
+
from image_decoder import SAM2ImageDecoder
|
|
19
|
+
from image_encoder import SAM2ImageEncoder
|
|
20
|
+
from sam2_utils import decoder_shape_dict, encoder_shape_dict, load_sam2_model
|
|
21
|
+
|
|
22
|
+
from onnxruntime import InferenceSession, SessionOptions, get_available_providers
|
|
23
|
+
from onnxruntime.transformers.io_binding_helper import CudaSession
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class TestConfig:
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
model_type: str,
|
|
30
|
+
onnx_path: str,
|
|
31
|
+
sam2_dir: str,
|
|
32
|
+
device: torch.device,
|
|
33
|
+
component: str = "image_encoder",
|
|
34
|
+
provider="CPUExecutionProvider",
|
|
35
|
+
torch_compile_mode="max-autotune",
|
|
36
|
+
batch_size: int = 1,
|
|
37
|
+
height: int = 1024,
|
|
38
|
+
width: int = 1024,
|
|
39
|
+
num_labels: int = 1,
|
|
40
|
+
num_points: int = 1,
|
|
41
|
+
num_masks: int = 1,
|
|
42
|
+
multi_mask_output: bool = False,
|
|
43
|
+
use_tf32: bool = True,
|
|
44
|
+
enable_cuda_graph: bool = False,
|
|
45
|
+
dtype=torch.float32,
|
|
46
|
+
prefer_nhwc: bool = False,
|
|
47
|
+
warm_up: int = 5,
|
|
48
|
+
enable_nvtx_profile: bool = False,
|
|
49
|
+
enable_ort_profile: bool = False,
|
|
50
|
+
enable_torch_profile: bool = False,
|
|
51
|
+
repeats: int = 1000,
|
|
52
|
+
verbose: bool = False,
|
|
53
|
+
):
|
|
54
|
+
assert model_type in ["sam2_hiera_tiny", "sam2_hiera_small", "sam2_hiera_large", "sam2_hiera_base_plus"]
|
|
55
|
+
assert height >= 160 and height <= 4096
|
|
56
|
+
assert width >= 160 and width <= 4096
|
|
57
|
+
|
|
58
|
+
self.model_type = model_type
|
|
59
|
+
self.onnx_path = onnx_path
|
|
60
|
+
self.sam2_dir = sam2_dir
|
|
61
|
+
self.component = component
|
|
62
|
+
self.provider = provider
|
|
63
|
+
self.torch_compile_mode = torch_compile_mode
|
|
64
|
+
self.batch_size = batch_size
|
|
65
|
+
self.height = height
|
|
66
|
+
self.width = width
|
|
67
|
+
self.num_labels = num_labels
|
|
68
|
+
self.num_points = num_points
|
|
69
|
+
self.num_masks = num_masks
|
|
70
|
+
self.multi_mask_output = multi_mask_output
|
|
71
|
+
self.device = device
|
|
72
|
+
self.use_tf32 = use_tf32
|
|
73
|
+
self.enable_cuda_graph = enable_cuda_graph
|
|
74
|
+
self.dtype = dtype
|
|
75
|
+
self.prefer_nhwc = prefer_nhwc
|
|
76
|
+
self.warm_up = warm_up
|
|
77
|
+
self.enable_nvtx_profile = enable_nvtx_profile
|
|
78
|
+
self.enable_ort_profile = enable_ort_profile
|
|
79
|
+
self.enable_torch_profile = enable_torch_profile
|
|
80
|
+
self.repeats = repeats
|
|
81
|
+
self.verbose = verbose
|
|
82
|
+
|
|
83
|
+
if self.component == "image_encoder":
|
|
84
|
+
assert self.height == 1024 and self.width == 1024, "Only image size 1024x1024 is allowed for image encoder."
|
|
85
|
+
|
|
86
|
+
def __repr__(self):
|
|
87
|
+
return f"{vars(self)}"
|
|
88
|
+
|
|
89
|
+
def shape_dict(self) -> Mapping[str, list[int]]:
|
|
90
|
+
if self.component == "image_encoder":
|
|
91
|
+
return encoder_shape_dict(self.batch_size, self.height, self.width)
|
|
92
|
+
else:
|
|
93
|
+
return decoder_shape_dict(self.height, self.width, self.num_labels, self.num_points, self.num_masks)
|
|
94
|
+
|
|
95
|
+
def random_inputs(self) -> Mapping[str, torch.Tensor]:
|
|
96
|
+
dtype = self.dtype
|
|
97
|
+
if self.component == "image_encoder":
|
|
98
|
+
return {"image": torch.randn(self.batch_size, 3, self.height, self.width, dtype=dtype, device=self.device)}
|
|
99
|
+
else:
|
|
100
|
+
return {
|
|
101
|
+
"image_features_0": torch.rand(1, 32, 256, 256, dtype=dtype, device=self.device),
|
|
102
|
+
"image_features_1": torch.rand(1, 64, 128, 128, dtype=dtype, device=self.device),
|
|
103
|
+
"image_embeddings": torch.rand(1, 256, 64, 64, dtype=dtype, device=self.device),
|
|
104
|
+
"point_coords": torch.randint(
|
|
105
|
+
0, 1024, (self.num_labels, self.num_points, 2), dtype=dtype, device=self.device
|
|
106
|
+
),
|
|
107
|
+
"point_labels": torch.randint(
|
|
108
|
+
0, 1, (self.num_labels, self.num_points), dtype=torch.int32, device=self.device
|
|
109
|
+
),
|
|
110
|
+
"input_masks": torch.zeros(self.num_labels, 1, 256, 256, dtype=dtype, device=self.device),
|
|
111
|
+
"has_input_masks": torch.ones(self.num_labels, dtype=dtype, device=self.device),
|
|
112
|
+
"original_image_size": torch.tensor([self.height, self.width], dtype=torch.int32, device=self.device),
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def create_ort_session(config: TestConfig, session_options=None) -> InferenceSession:
|
|
117
|
+
if config.verbose:
|
|
118
|
+
print(f"create session for {vars(config)}")
|
|
119
|
+
|
|
120
|
+
if config.provider == "CUDAExecutionProvider":
|
|
121
|
+
device_id = torch.cuda.current_device() if isinstance(config.device, str) else config.device.index
|
|
122
|
+
provider_options = CudaSession.get_cuda_provider_options(device_id, config.enable_cuda_graph)
|
|
123
|
+
provider_options["use_tf32"] = int(config.use_tf32)
|
|
124
|
+
if config.prefer_nhwc:
|
|
125
|
+
provider_options["prefer_nhwc"] = 1
|
|
126
|
+
providers = [(config.provider, provider_options), "CPUExecutionProvider"]
|
|
127
|
+
else:
|
|
128
|
+
providers = ["CPUExecutionProvider"]
|
|
129
|
+
|
|
130
|
+
ort_session = InferenceSession(config.onnx_path, session_options, providers=providers)
|
|
131
|
+
return ort_session
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def create_session(config: TestConfig, session_options=None) -> CudaSession:
|
|
135
|
+
ort_session = create_ort_session(config, session_options)
|
|
136
|
+
cuda_session = CudaSession(ort_session, config.device, config.enable_cuda_graph)
|
|
137
|
+
cuda_session.allocate_buffers(config.shape_dict())
|
|
138
|
+
return cuda_session
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class OrtTestSession:
|
|
142
|
+
"""A wrapper of ORT session to test relevance and performance."""
|
|
143
|
+
|
|
144
|
+
def __init__(self, config: TestConfig, session_options=None):
|
|
145
|
+
self.ort_session = create_session(config, session_options)
|
|
146
|
+
self.feed_dict = config.random_inputs()
|
|
147
|
+
|
|
148
|
+
def infer(self):
|
|
149
|
+
return self.ort_session.infer(self.feed_dict)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def measure_latency(cuda_session: CudaSession, input_dict):
|
|
153
|
+
start = time.time()
|
|
154
|
+
_ = cuda_session.infer(input_dict)
|
|
155
|
+
end = time.time()
|
|
156
|
+
return end - start
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def run_torch(config: TestConfig):
|
|
160
|
+
device_type = config.device.type
|
|
161
|
+
is_cuda = device_type == "cuda"
|
|
162
|
+
|
|
163
|
+
# Turn on TF32 for Ampere GPUs which could help when data type is float32.
|
|
164
|
+
if is_cuda and torch.cuda.get_device_properties(0).major >= 8 and config.use_tf32:
|
|
165
|
+
torch.backends.cuda.matmul.allow_tf32 = True
|
|
166
|
+
torch.backends.cudnn.allow_tf32 = True
|
|
167
|
+
|
|
168
|
+
enabled_auto_cast = is_cuda and config.dtype != torch.float32
|
|
169
|
+
ort_inputs = config.random_inputs()
|
|
170
|
+
|
|
171
|
+
with torch.inference_mode(), torch.autocast(device_type=device_type, dtype=config.dtype, enabled=enabled_auto_cast):
|
|
172
|
+
sam2_model = load_sam2_model(config.sam2_dir, config.model_type, device=config.device)
|
|
173
|
+
if config.component == "image_encoder":
|
|
174
|
+
if is_cuda and config.torch_compile_mode != "none":
|
|
175
|
+
sam2_model.image_encoder.forward = torch.compile(
|
|
176
|
+
sam2_model.image_encoder.forward,
|
|
177
|
+
mode=config.torch_compile_mode, # "reduce-overhead" if you want to reduce latency of first run.
|
|
178
|
+
fullgraph=True,
|
|
179
|
+
dynamic=False,
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
image_shape = config.shape_dict()["image"]
|
|
183
|
+
img = torch.randn(image_shape).to(device=config.device, dtype=config.dtype)
|
|
184
|
+
sam2_encoder = SAM2ImageEncoder(sam2_model)
|
|
185
|
+
|
|
186
|
+
if is_cuda and config.torch_compile_mode != "none":
|
|
187
|
+
print(f"Running warm up. It will take a while since torch compile mode is {config.torch_compile_mode}.")
|
|
188
|
+
|
|
189
|
+
for _ in range(config.warm_up):
|
|
190
|
+
_image_features_0, _image_features_1, _image_embeddings = sam2_encoder(img)
|
|
191
|
+
|
|
192
|
+
if is_cuda and config.enable_nvtx_profile:
|
|
193
|
+
import nvtx # noqa: PLC0415
|
|
194
|
+
from cuda import cudart # noqa: PLC0415
|
|
195
|
+
|
|
196
|
+
cudart.cudaProfilerStart()
|
|
197
|
+
print("Start nvtx profiling on encoder ...")
|
|
198
|
+
with nvtx.annotate("one_run"):
|
|
199
|
+
sam2_encoder(img, enable_nvtx_profile=True)
|
|
200
|
+
cudart.cudaProfilerStop()
|
|
201
|
+
|
|
202
|
+
if is_cuda and config.enable_torch_profile:
|
|
203
|
+
with torch.profiler.profile(
|
|
204
|
+
activities=[torch.profiler.ProfilerActivity.CPU, torch.profiler.ProfilerActivity.CUDA],
|
|
205
|
+
record_shapes=True,
|
|
206
|
+
) as prof:
|
|
207
|
+
print("Start torch profiling on encoder ...")
|
|
208
|
+
with torch.profiler.record_function("encoder"):
|
|
209
|
+
sam2_encoder(img)
|
|
210
|
+
print(prof.key_averages().table(sort_by="cuda_time_total", row_limit=10))
|
|
211
|
+
prof.export_chrome_trace("torch_image_encoder.json")
|
|
212
|
+
|
|
213
|
+
if config.repeats == 0:
|
|
214
|
+
return
|
|
215
|
+
|
|
216
|
+
print(f"Start {config.repeats} runs of performance tests...")
|
|
217
|
+
start = time.time()
|
|
218
|
+
for _ in range(config.repeats):
|
|
219
|
+
_image_features_0, _image_features_1, _image_embeddings = sam2_encoder(img)
|
|
220
|
+
if is_cuda:
|
|
221
|
+
torch.cuda.synchronize()
|
|
222
|
+
else:
|
|
223
|
+
torch_inputs = (
|
|
224
|
+
ort_inputs["image_features_0"],
|
|
225
|
+
ort_inputs["image_features_1"],
|
|
226
|
+
ort_inputs["image_embeddings"],
|
|
227
|
+
ort_inputs["point_coords"],
|
|
228
|
+
ort_inputs["point_labels"],
|
|
229
|
+
ort_inputs["input_masks"],
|
|
230
|
+
ort_inputs["has_input_masks"],
|
|
231
|
+
ort_inputs["original_image_size"],
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
sam2_decoder = SAM2ImageDecoder(
|
|
235
|
+
sam2_model,
|
|
236
|
+
multimask_output=config.multi_mask_output,
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
if is_cuda and config.torch_compile_mode != "none":
|
|
240
|
+
sam2_decoder.forward = torch.compile(
|
|
241
|
+
sam2_decoder.forward,
|
|
242
|
+
mode=config.torch_compile_mode,
|
|
243
|
+
fullgraph=True,
|
|
244
|
+
dynamic=False,
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
# warm up
|
|
248
|
+
for _ in range(config.warm_up):
|
|
249
|
+
_masks, _iou_predictions, _low_res_masks = sam2_decoder(*torch_inputs)
|
|
250
|
+
|
|
251
|
+
if is_cuda and config.enable_nvtx_profile:
|
|
252
|
+
import nvtx # noqa: PLC0415
|
|
253
|
+
from cuda import cudart # noqa: PLC0415
|
|
254
|
+
|
|
255
|
+
cudart.cudaProfilerStart()
|
|
256
|
+
print("Start nvtx profiling on decoder...")
|
|
257
|
+
with nvtx.annotate("one_run"):
|
|
258
|
+
sam2_decoder(*torch_inputs, enable_nvtx_profile=True)
|
|
259
|
+
cudart.cudaProfilerStop()
|
|
260
|
+
|
|
261
|
+
if is_cuda and config.enable_torch_profile:
|
|
262
|
+
with torch.profiler.profile(
|
|
263
|
+
activities=[torch.profiler.ProfilerActivity.CPU, torch.profiler.ProfilerActivity.CUDA],
|
|
264
|
+
record_shapes=True,
|
|
265
|
+
) as prof:
|
|
266
|
+
print("Start torch profiling on decoder ...")
|
|
267
|
+
with torch.profiler.record_function("decoder"):
|
|
268
|
+
sam2_decoder(*torch_inputs)
|
|
269
|
+
print(prof.key_averages().table(sort_by="cuda_time_total", row_limit=10))
|
|
270
|
+
prof.export_chrome_trace("torch_image_decoder.json")
|
|
271
|
+
|
|
272
|
+
if config.repeats == 0:
|
|
273
|
+
return
|
|
274
|
+
|
|
275
|
+
print(f"Start {config.repeats} runs of performance tests...")
|
|
276
|
+
start = time.time()
|
|
277
|
+
for _ in range(config.repeats):
|
|
278
|
+
_masks, _iou_predictions, _low_res_masks = sam2_decoder(*torch_inputs)
|
|
279
|
+
if is_cuda:
|
|
280
|
+
torch.cuda.synchronize()
|
|
281
|
+
|
|
282
|
+
end = time.time()
|
|
283
|
+
return (end - start) / config.repeats
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def run_test(
|
|
287
|
+
args: argparse.Namespace,
|
|
288
|
+
csv_writer: csv.DictWriter | None = None,
|
|
289
|
+
):
|
|
290
|
+
use_gpu: bool = args.use_gpu
|
|
291
|
+
enable_cuda_graph: bool = args.use_cuda_graph
|
|
292
|
+
repeats: int = args.repeats
|
|
293
|
+
|
|
294
|
+
if use_gpu:
|
|
295
|
+
device_id = torch.cuda.current_device()
|
|
296
|
+
device = torch.device("cuda", device_id)
|
|
297
|
+
provider = "CUDAExecutionProvider"
|
|
298
|
+
else:
|
|
299
|
+
device_id = 0
|
|
300
|
+
device = torch.device("cpu")
|
|
301
|
+
enable_cuda_graph = False
|
|
302
|
+
provider = "CPUExecutionProvider"
|
|
303
|
+
|
|
304
|
+
dtypes = {"fp32": torch.float32, "fp16": torch.float16, "bf16": torch.bfloat16}
|
|
305
|
+
config = TestConfig(
|
|
306
|
+
model_type=args.model_type,
|
|
307
|
+
onnx_path=args.onnx_path,
|
|
308
|
+
sam2_dir=args.sam2_dir,
|
|
309
|
+
component=args.component,
|
|
310
|
+
provider=provider,
|
|
311
|
+
batch_size=args.batch_size,
|
|
312
|
+
height=args.height,
|
|
313
|
+
width=args.width,
|
|
314
|
+
device=device,
|
|
315
|
+
use_tf32=True,
|
|
316
|
+
enable_cuda_graph=enable_cuda_graph,
|
|
317
|
+
dtype=dtypes[args.dtype],
|
|
318
|
+
prefer_nhwc=args.prefer_nhwc,
|
|
319
|
+
repeats=args.repeats,
|
|
320
|
+
warm_up=args.warm_up,
|
|
321
|
+
enable_nvtx_profile=args.enable_nvtx_profile,
|
|
322
|
+
enable_ort_profile=args.enable_ort_profile,
|
|
323
|
+
enable_torch_profile=args.enable_torch_profile,
|
|
324
|
+
torch_compile_mode=args.torch_compile_mode,
|
|
325
|
+
verbose=False,
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
if args.engine == "ort":
|
|
329
|
+
sess_options = SessionOptions()
|
|
330
|
+
sess_options.intra_op_num_threads = args.intra_op_num_threads
|
|
331
|
+
if config.enable_ort_profile:
|
|
332
|
+
sess_options.enable_profiling = True
|
|
333
|
+
sess_options.log_severity_level = 4
|
|
334
|
+
sess_options.log_verbosity_level = 0
|
|
335
|
+
|
|
336
|
+
session = create_session(config, sess_options)
|
|
337
|
+
input_dict = config.random_inputs()
|
|
338
|
+
|
|
339
|
+
# warm up session
|
|
340
|
+
try:
|
|
341
|
+
for _ in range(config.warm_up):
|
|
342
|
+
_ = measure_latency(session, input_dict)
|
|
343
|
+
except Exception as e:
|
|
344
|
+
print(f"Failed to run {config=}. Exception: {e}")
|
|
345
|
+
return
|
|
346
|
+
|
|
347
|
+
if config.enable_nvtx_profile:
|
|
348
|
+
import nvtx # noqa: PLC0415
|
|
349
|
+
from cuda import cudart # noqa: PLC0415
|
|
350
|
+
|
|
351
|
+
cudart.cudaProfilerStart()
|
|
352
|
+
with nvtx.annotate("one_run"):
|
|
353
|
+
_ = session.infer(input_dict)
|
|
354
|
+
cudart.cudaProfilerStop()
|
|
355
|
+
|
|
356
|
+
if config.enable_ort_profile:
|
|
357
|
+
session.ort_session.end_profiling()
|
|
358
|
+
|
|
359
|
+
if repeats == 0:
|
|
360
|
+
return
|
|
361
|
+
|
|
362
|
+
latency_list = []
|
|
363
|
+
for _ in range(repeats):
|
|
364
|
+
latency = measure_latency(session, input_dict)
|
|
365
|
+
latency_list.append(latency)
|
|
366
|
+
average_latency = statistics.mean(latency_list)
|
|
367
|
+
|
|
368
|
+
del session
|
|
369
|
+
else: # torch
|
|
370
|
+
with torch.no_grad():
|
|
371
|
+
try:
|
|
372
|
+
average_latency = run_torch(config)
|
|
373
|
+
except Exception as e:
|
|
374
|
+
print(f"Failed to run {config=}. Exception: {e}")
|
|
375
|
+
return
|
|
376
|
+
|
|
377
|
+
if repeats == 0:
|
|
378
|
+
return
|
|
379
|
+
|
|
380
|
+
engine = args.engine + ":" + ("cuda" if use_gpu else "cpu")
|
|
381
|
+
row = {
|
|
382
|
+
"model_type": args.model_type,
|
|
383
|
+
"component": args.component,
|
|
384
|
+
"dtype": args.dtype,
|
|
385
|
+
"use_gpu": use_gpu,
|
|
386
|
+
"enable_cuda_graph": enable_cuda_graph,
|
|
387
|
+
"prefer_nhwc": config.prefer_nhwc,
|
|
388
|
+
"use_tf32": config.use_tf32,
|
|
389
|
+
"batch_size": args.batch_size,
|
|
390
|
+
"height": args.height,
|
|
391
|
+
"width": args.width,
|
|
392
|
+
"multi_mask_output": args.multimask_output,
|
|
393
|
+
"num_labels": config.num_labels,
|
|
394
|
+
"num_points": config.num_points,
|
|
395
|
+
"num_masks": config.num_masks,
|
|
396
|
+
"intra_op_num_threads": args.intra_op_num_threads,
|
|
397
|
+
"warm_up": config.warm_up,
|
|
398
|
+
"repeats": repeats,
|
|
399
|
+
"enable_nvtx_profile": args.enable_nvtx_profile,
|
|
400
|
+
"torch_compile_mode": args.torch_compile_mode,
|
|
401
|
+
"engine": engine,
|
|
402
|
+
"average_latency": average_latency,
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if csv_writer is not None:
|
|
406
|
+
csv_writer.writerow(row)
|
|
407
|
+
|
|
408
|
+
print(f"{vars(config)}")
|
|
409
|
+
print(f"{row}")
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def run_perf_test(args):
|
|
413
|
+
features = "gpu" if args.use_gpu else "cpu"
|
|
414
|
+
csv_filename = "benchmark_sam_{}_{}_{}.csv".format(
|
|
415
|
+
features,
|
|
416
|
+
args.engine,
|
|
417
|
+
datetime.now().strftime("%Y%m%d-%H%M%S"),
|
|
418
|
+
)
|
|
419
|
+
with open(csv_filename, mode="a", newline="") as csv_file:
|
|
420
|
+
column_names = [
|
|
421
|
+
"model_type",
|
|
422
|
+
"component",
|
|
423
|
+
"dtype",
|
|
424
|
+
"use_gpu",
|
|
425
|
+
"enable_cuda_graph",
|
|
426
|
+
"prefer_nhwc",
|
|
427
|
+
"use_tf32",
|
|
428
|
+
"batch_size",
|
|
429
|
+
"height",
|
|
430
|
+
"width",
|
|
431
|
+
"multi_mask_output",
|
|
432
|
+
"num_labels",
|
|
433
|
+
"num_points",
|
|
434
|
+
"num_masks",
|
|
435
|
+
"intra_op_num_threads",
|
|
436
|
+
"warm_up",
|
|
437
|
+
"repeats",
|
|
438
|
+
"enable_nvtx_profile",
|
|
439
|
+
"torch_compile_mode",
|
|
440
|
+
"engine",
|
|
441
|
+
"average_latency",
|
|
442
|
+
]
|
|
443
|
+
csv_writer = csv.DictWriter(csv_file, fieldnames=column_names)
|
|
444
|
+
csv_writer.writeheader()
|
|
445
|
+
|
|
446
|
+
run_test(args, csv_writer)
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def _parse_arguments():
|
|
450
|
+
parser = argparse.ArgumentParser(description="Benchmark SMA2 for ONNX Runtime and PyTorch.")
|
|
451
|
+
|
|
452
|
+
parser.add_argument(
|
|
453
|
+
"--component",
|
|
454
|
+
required=False,
|
|
455
|
+
choices=["image_encoder", "image_decoder"],
|
|
456
|
+
default="image_encoder",
|
|
457
|
+
help="component to benchmark. Choices are image_encoder and image_decoder.",
|
|
458
|
+
)
|
|
459
|
+
|
|
460
|
+
parser.add_argument(
|
|
461
|
+
"--dtype", required=False, choices=["fp32", "fp16", "bf16"], default="fp32", help="Data type for inference."
|
|
462
|
+
)
|
|
463
|
+
|
|
464
|
+
parser.add_argument(
|
|
465
|
+
"--use_gpu",
|
|
466
|
+
required=False,
|
|
467
|
+
action="store_true",
|
|
468
|
+
help="Use GPU for inference.",
|
|
469
|
+
)
|
|
470
|
+
parser.set_defaults(use_gpu=False)
|
|
471
|
+
|
|
472
|
+
parser.add_argument(
|
|
473
|
+
"--use_cuda_graph",
|
|
474
|
+
required=False,
|
|
475
|
+
action="store_true",
|
|
476
|
+
help="Use cuda graph in onnxruntime.",
|
|
477
|
+
)
|
|
478
|
+
parser.set_defaults(use_cuda_graph=False)
|
|
479
|
+
|
|
480
|
+
parser.add_argument(
|
|
481
|
+
"--intra_op_num_threads",
|
|
482
|
+
required=False,
|
|
483
|
+
type=int,
|
|
484
|
+
choices=[0, 1, 2, 4, 8, 16],
|
|
485
|
+
default=0,
|
|
486
|
+
help="intra_op_num_threads for onnxruntime. ",
|
|
487
|
+
)
|
|
488
|
+
|
|
489
|
+
parser.add_argument(
|
|
490
|
+
"--batch_size",
|
|
491
|
+
required=False,
|
|
492
|
+
type=int,
|
|
493
|
+
default=1,
|
|
494
|
+
help="batch size",
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
parser.add_argument(
|
|
498
|
+
"--height",
|
|
499
|
+
required=False,
|
|
500
|
+
type=int,
|
|
501
|
+
default=1024,
|
|
502
|
+
help="image height",
|
|
503
|
+
)
|
|
504
|
+
|
|
505
|
+
parser.add_argument(
|
|
506
|
+
"--width",
|
|
507
|
+
required=False,
|
|
508
|
+
type=int,
|
|
509
|
+
default=1024,
|
|
510
|
+
help="image width",
|
|
511
|
+
)
|
|
512
|
+
|
|
513
|
+
parser.add_argument(
|
|
514
|
+
"--repeats",
|
|
515
|
+
required=False,
|
|
516
|
+
type=int,
|
|
517
|
+
default=1000,
|
|
518
|
+
help="number of repeats for performance test. Default is 1000.",
|
|
519
|
+
)
|
|
520
|
+
|
|
521
|
+
parser.add_argument(
|
|
522
|
+
"--warm_up",
|
|
523
|
+
required=False,
|
|
524
|
+
type=int,
|
|
525
|
+
default=5,
|
|
526
|
+
help="number of runs for warm up. Default is 5.",
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
parser.add_argument(
|
|
530
|
+
"--engine",
|
|
531
|
+
required=False,
|
|
532
|
+
type=str,
|
|
533
|
+
default="ort",
|
|
534
|
+
choices=["ort", "torch"],
|
|
535
|
+
help="engine for inference",
|
|
536
|
+
)
|
|
537
|
+
|
|
538
|
+
parser.add_argument(
|
|
539
|
+
"--multimask_output",
|
|
540
|
+
required=False,
|
|
541
|
+
default=False,
|
|
542
|
+
action="store_true",
|
|
543
|
+
help="Export mask_decoder or image_decoder with multimask_output",
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
parser.add_argument(
|
|
547
|
+
"--prefer_nhwc",
|
|
548
|
+
required=False,
|
|
549
|
+
default=False,
|
|
550
|
+
action="store_true",
|
|
551
|
+
help="Use prefer_nhwc=1 provider option for CUDAExecutionProvider",
|
|
552
|
+
)
|
|
553
|
+
|
|
554
|
+
parser.add_argument(
|
|
555
|
+
"--enable_nvtx_profile",
|
|
556
|
+
required=False,
|
|
557
|
+
default=False,
|
|
558
|
+
action="store_true",
|
|
559
|
+
help="Enable nvtx profiling. It will add an extra run for profiling before performance test.",
|
|
560
|
+
)
|
|
561
|
+
|
|
562
|
+
parser.add_argument(
|
|
563
|
+
"--enable_ort_profile",
|
|
564
|
+
required=False,
|
|
565
|
+
default=False,
|
|
566
|
+
action="store_true",
|
|
567
|
+
help="Enable ORT profiling.",
|
|
568
|
+
)
|
|
569
|
+
|
|
570
|
+
parser.add_argument(
|
|
571
|
+
"--enable_torch_profile",
|
|
572
|
+
required=False,
|
|
573
|
+
default=False,
|
|
574
|
+
action="store_true",
|
|
575
|
+
help="Enable PyTorch profiling. It will add an extra run for profiling before performance test.",
|
|
576
|
+
)
|
|
577
|
+
|
|
578
|
+
parser.add_argument(
|
|
579
|
+
"--model_type",
|
|
580
|
+
required=False,
|
|
581
|
+
type=str,
|
|
582
|
+
default="sam2_hiera_large",
|
|
583
|
+
choices=["sam2_hiera_tiny", "sam2_hiera_small", "sam2_hiera_large", "sam2_hiera_base_plus"],
|
|
584
|
+
help="sam2 model name",
|
|
585
|
+
)
|
|
586
|
+
|
|
587
|
+
parser.add_argument(
|
|
588
|
+
"--sam2_dir",
|
|
589
|
+
required=False,
|
|
590
|
+
type=str,
|
|
591
|
+
default="./segment-anything-2",
|
|
592
|
+
help="The directory of segment-anything-2 git root directory",
|
|
593
|
+
)
|
|
594
|
+
|
|
595
|
+
parser.add_argument(
|
|
596
|
+
"--onnx_path",
|
|
597
|
+
required=False,
|
|
598
|
+
type=str,
|
|
599
|
+
default="./sam2_onnx_models/sam2_hiera_large_image_encoder.onnx",
|
|
600
|
+
help="path of onnx model",
|
|
601
|
+
)
|
|
602
|
+
|
|
603
|
+
parser.add_argument(
|
|
604
|
+
"--torch_compile_mode",
|
|
605
|
+
required=False,
|
|
606
|
+
type=str,
|
|
607
|
+
default=None,
|
|
608
|
+
choices=["reduce-overhead", "max-autotune", "max-autotune-no-cudagraphs", "none"],
|
|
609
|
+
help="torch compile mode. none will disable torch compile.",
|
|
610
|
+
)
|
|
611
|
+
|
|
612
|
+
args = parser.parse_args()
|
|
613
|
+
|
|
614
|
+
return args
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
if __name__ == "__main__":
|
|
618
|
+
args = _parse_arguments()
|
|
619
|
+
print(f"arguments:{args}")
|
|
620
|
+
|
|
621
|
+
if args.torch_compile_mode is None:
|
|
622
|
+
# image decoder will fail with compile modes other than "none".
|
|
623
|
+
args.torch_compile_mode = "max-autotune" if args.component == "image_encoder" else "none"
|
|
624
|
+
|
|
625
|
+
if args.use_gpu:
|
|
626
|
+
assert torch.cuda.is_available()
|
|
627
|
+
if args.engine == "ort":
|
|
628
|
+
assert "CUDAExecutionProvider" in get_available_providers()
|
|
629
|
+
args.enable_torch_profile = False
|
|
630
|
+
else:
|
|
631
|
+
# Only support cuda profiling for now.
|
|
632
|
+
assert not args.enable_nvtx_profile
|
|
633
|
+
assert not args.enable_torch_profile
|
|
634
|
+
|
|
635
|
+
if args.enable_nvtx_profile or args.enable_torch_profile:
|
|
636
|
+
run_test(args)
|
|
637
|
+
else:
|
|
638
|
+
run_perf_test(args)
|