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,576 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License.
|
|
4
|
+
# --------------------------------------------------------------------------
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import logging
|
|
9
|
+
import os
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
import onnx
|
|
13
|
+
import torch
|
|
14
|
+
from benchmark_helper import Precision
|
|
15
|
+
from fusion_options import AttentionOpType
|
|
16
|
+
from onnx_model import OnnxModel
|
|
17
|
+
from transformers import AutoConfig, AutoModelForCausalLM
|
|
18
|
+
|
|
19
|
+
from onnxruntime.quantization.matmul_4bits_quantizer import MatMul4BitsQuantizer
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ConvertPhi2ToONNX:
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
device: torch.device,
|
|
26
|
+
model_class: str = "microsoft/phi-2",
|
|
27
|
+
cache_dir: str = "./cache",
|
|
28
|
+
):
|
|
29
|
+
self.model_class = model_class
|
|
30
|
+
self.device = device
|
|
31
|
+
self.cache_dir = cache_dir
|
|
32
|
+
self.phi_config = AutoConfig.from_pretrained(self.model_class, trust_remote_code=True, cache_dir=self.cache_dir)
|
|
33
|
+
self.phi_model = None
|
|
34
|
+
self.batch_size = 2
|
|
35
|
+
self.sequence_length = 8
|
|
36
|
+
self.attn_op_type = None
|
|
37
|
+
self.precision = None
|
|
38
|
+
self.block_size = 16
|
|
39
|
+
self.accuracy_level = None
|
|
40
|
+
|
|
41
|
+
def set_quantization_params(self, block_size: int, accuracy_level: int | None):
|
|
42
|
+
self.block_size = block_size
|
|
43
|
+
self.accuracy_level = accuracy_level
|
|
44
|
+
|
|
45
|
+
def init_attn_type_and_precision(self, attn_op_type: AttentionOpType, precision: Precision):
|
|
46
|
+
self.attn_op_type = attn_op_type
|
|
47
|
+
self.precision = precision
|
|
48
|
+
|
|
49
|
+
def erase_onnx_model(self, onnx_path: str) -> None:
|
|
50
|
+
assert onnx_path.endswith(".onnx")
|
|
51
|
+
if not os.path.exists(onnx_path):
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
model = onnx.load_model(onnx_path, load_external_data=False)
|
|
55
|
+
onnx_data_path = None
|
|
56
|
+
for initializer in model.graph.initializer:
|
|
57
|
+
if initializer.data_location == 1 and initializer.external_data[0].key == "location":
|
|
58
|
+
onnx_data_path = "./" + initializer.external_data[0].value
|
|
59
|
+
break
|
|
60
|
+
logging.info(f"Erasing {onnx_path}...")
|
|
61
|
+
os.remove(onnx_path)
|
|
62
|
+
if onnx_data_path is not None:
|
|
63
|
+
onnx_data_path = os.path.join(Path(onnx_path).parent, onnx_data_path)
|
|
64
|
+
logging.info(f"Erasing {onnx_data_path}...")
|
|
65
|
+
os.remove(onnx_data_path)
|
|
66
|
+
|
|
67
|
+
def get_phi2_torch_model(self):
|
|
68
|
+
logging.info("Loading phi2 torch model...")
|
|
69
|
+
if self.phi_model is not None:
|
|
70
|
+
return
|
|
71
|
+
self.phi_model = AutoModelForCausalLM.from_pretrained(
|
|
72
|
+
self.model_class, trust_remote_code=True, cache_dir=self.cache_dir
|
|
73
|
+
)
|
|
74
|
+
self.phi_model.eval()
|
|
75
|
+
self.phi_model.to(self.device)
|
|
76
|
+
|
|
77
|
+
def get_phi2_torch_inputs(self, batch_size: int, sequence_length: int):
|
|
78
|
+
input_ids = torch.randint(
|
|
79
|
+
low=0,
|
|
80
|
+
high=self.phi_config.vocab_size,
|
|
81
|
+
size=(batch_size, sequence_length),
|
|
82
|
+
dtype=torch.int64,
|
|
83
|
+
device=self.device,
|
|
84
|
+
)
|
|
85
|
+
self.get_phi2_torch_model()
|
|
86
|
+
torch_inputs = self.phi_model.prepare_inputs_for_generation(
|
|
87
|
+
input_ids, past_key_values=self.phi_model(input_ids, use_cache=True)["past_key_values"]
|
|
88
|
+
)
|
|
89
|
+
return torch_inputs["input_ids"], torch_inputs["attention_mask"], torch_inputs["past_key_values"]
|
|
90
|
+
|
|
91
|
+
def dynamo_export(self, onnx_path: str):
|
|
92
|
+
input_ids, attention_mask, past_key_values = self.get_phi2_torch_inputs(self.batch_size, self.sequence_length)
|
|
93
|
+
self.phi_model(input_ids, attention_mask=attention_mask, past_key_values=past_key_values)
|
|
94
|
+
|
|
95
|
+
from torch._dynamo import config
|
|
96
|
+
|
|
97
|
+
config.capture_scalar_outputs = True
|
|
98
|
+
|
|
99
|
+
logging.info("Exporting Phi2 torch model to ONNX...")
|
|
100
|
+
torch.onnx.dynamo_export(
|
|
101
|
+
self.phi_model,
|
|
102
|
+
input_ids,
|
|
103
|
+
attention_mask=attention_mask,
|
|
104
|
+
past_key_values=past_key_values,
|
|
105
|
+
export_options=torch.onnx.ExportOptions(dynamic_shapes=True),
|
|
106
|
+
).save(onnx_path)
|
|
107
|
+
onnx.checker.check_model(onnx_path)
|
|
108
|
+
onnx.shape_inference.infer_shapes_path(onnx_path)
|
|
109
|
+
|
|
110
|
+
def optimize_phi2_onnx(self, onnx_path: str, onnx_path_opt: str):
|
|
111
|
+
from fusion_options import FusionOptions
|
|
112
|
+
from optimizer import optimize_model
|
|
113
|
+
|
|
114
|
+
optimization_options = FusionOptions("phi")
|
|
115
|
+
optimization_options.set_attention_op_type(self.attn_op_type)
|
|
116
|
+
optimizer = optimize_model(
|
|
117
|
+
onnx_path,
|
|
118
|
+
model_type="phi",
|
|
119
|
+
num_heads=self.phi_config.num_attention_heads,
|
|
120
|
+
hidden_size=self.phi_config.hidden_size,
|
|
121
|
+
opt_level=0,
|
|
122
|
+
optimization_options=optimization_options,
|
|
123
|
+
only_onnxruntime=False,
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
fused_op_count = optimizer.get_fused_operator_statistics()
|
|
127
|
+
if optimizer.is_fully_optimized(fused_op_count):
|
|
128
|
+
logging.info("Model is fully optimized.")
|
|
129
|
+
else:
|
|
130
|
+
logging.info("Model is not fully optimized.")
|
|
131
|
+
|
|
132
|
+
if self.precision == Precision.FLOAT32:
|
|
133
|
+
optimizer.save_model_to_file(onnx_path_opt, use_external_data_format=True)
|
|
134
|
+
return
|
|
135
|
+
|
|
136
|
+
if (
|
|
137
|
+
self.precision == Precision.FLOAT16 or self.precision == Precision.INT4
|
|
138
|
+
) and self.attn_op_type != AttentionOpType.MultiHeadAttention:
|
|
139
|
+
# We keep last three layers of Attention as float32 or bfloat16 to avoid overflow.
|
|
140
|
+
node_block_list = (
|
|
141
|
+
[
|
|
142
|
+
"Attention_29",
|
|
143
|
+
"Attention_30",
|
|
144
|
+
"Attention_31",
|
|
145
|
+
]
|
|
146
|
+
if self.attn_op_type != AttentionOpType.PagedAttention
|
|
147
|
+
else []
|
|
148
|
+
) # TODO: temp setting for paged attention
|
|
149
|
+
logging.info("Converting onnx model to float16/bfloat16...")
|
|
150
|
+
optimizer.convert_float_to_float16(
|
|
151
|
+
keep_io_types=False,
|
|
152
|
+
node_block_list=node_block_list,
|
|
153
|
+
use_symbolic_shape_infer=True,
|
|
154
|
+
use_bfloat16_as_blocked_nodes_dtype=self.attn_op_type == AttentionOpType.GroupQueryAttention,
|
|
155
|
+
)
|
|
156
|
+
logging.info("Converting onnx model to float16/bfloat16 done.")
|
|
157
|
+
|
|
158
|
+
if self.precision == Precision.FLOAT16:
|
|
159
|
+
optimizer.save_model_to_file(onnx_path_opt, use_external_data_format=True)
|
|
160
|
+
return
|
|
161
|
+
else:
|
|
162
|
+
assert self.precision == Precision.INT4
|
|
163
|
+
quant = MatMul4BitsQuantizer(
|
|
164
|
+
model=optimizer.model,
|
|
165
|
+
block_size=self.block_size,
|
|
166
|
+
is_symmetric=True,
|
|
167
|
+
accuracy_level=self.accuracy_level,
|
|
168
|
+
)
|
|
169
|
+
quant.process()
|
|
170
|
+
quant.model.save_model_to_file(onnx_path_opt, use_external_data_format=True)
|
|
171
|
+
|
|
172
|
+
# This function currently only works for phi2 model
|
|
173
|
+
def convert_to_use_cuda_graph(self, in_onnx_path: str, out_onnx_path: str):
|
|
174
|
+
onnx_model = OnnxModel(onnx.load(in_onnx_path, load_external_data=True))
|
|
175
|
+
|
|
176
|
+
from onnx import TensorProto, helper
|
|
177
|
+
|
|
178
|
+
graph = onnx_model.graph()
|
|
179
|
+
new_inputs = []
|
|
180
|
+
for vi in graph.input:
|
|
181
|
+
if "attention_mask" in vi.name:
|
|
182
|
+
vi_seqlen_k = helper.make_tensor_value_info(
|
|
183
|
+
"seqlens_k",
|
|
184
|
+
elem_type=TensorProto.INT32,
|
|
185
|
+
shape=["batch_size"],
|
|
186
|
+
)
|
|
187
|
+
vi_total_seq_len = helper.make_tensor_value_info(
|
|
188
|
+
"total_sequence_length",
|
|
189
|
+
elem_type=TensorProto.INT32,
|
|
190
|
+
shape=[1],
|
|
191
|
+
)
|
|
192
|
+
new_inputs.extend([vi_seqlen_k, vi_total_seq_len])
|
|
193
|
+
else:
|
|
194
|
+
new_inputs.append(vi)
|
|
195
|
+
|
|
196
|
+
graph.ClearField("input")
|
|
197
|
+
graph.input.extend(new_inputs)
|
|
198
|
+
|
|
199
|
+
gqas = onnx_model.get_nodes_by_op_type("GroupQueryAttention")
|
|
200
|
+
gqa = gqas[0]
|
|
201
|
+
seqlens_path = onnx_model.match_parent_path(
|
|
202
|
+
gqa,
|
|
203
|
+
["Cast", "Sub", "ReduceSum", "Cast"],
|
|
204
|
+
[5, 0, 0, 0],
|
|
205
|
+
)
|
|
206
|
+
if seqlens_path is None:
|
|
207
|
+
raise RuntimeError("Failed to find seqlens path for GroupQueryAttention node.")
|
|
208
|
+
total_seq_len_path = onnx_model.match_parent_path(
|
|
209
|
+
gqa,
|
|
210
|
+
["Cast", "Gather", "Shape"],
|
|
211
|
+
[6, 0, 0],
|
|
212
|
+
)
|
|
213
|
+
if total_seq_len_path is None:
|
|
214
|
+
raise RuntimeError("Failed to find total_seq_len path for GroupQueryAttention node.")
|
|
215
|
+
onnx_model.remove_nodes(seqlens_path)
|
|
216
|
+
onnx_model.remove_nodes(total_seq_len_path)
|
|
217
|
+
|
|
218
|
+
for gqa in gqas:
|
|
219
|
+
gqa.input[5] = "seqlens_k"
|
|
220
|
+
gqa.input[6] = "total_sequence_length"
|
|
221
|
+
|
|
222
|
+
onnx_model.save(onnx_model.model, out_onnx_path, save_as_external_data=True)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def parse_arguments():
|
|
226
|
+
parser = argparse.ArgumentParser()
|
|
227
|
+
|
|
228
|
+
parser.add_argument(
|
|
229
|
+
"--fp32_cpu",
|
|
230
|
+
required=False,
|
|
231
|
+
action="store_true",
|
|
232
|
+
help="Generate fp32 ONNX model for CPU",
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
parser.add_argument(
|
|
236
|
+
"--int4_cpu",
|
|
237
|
+
required=False,
|
|
238
|
+
action="store_true",
|
|
239
|
+
help="Generate int4 ONNX model for CPU",
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
parser.add_argument(
|
|
243
|
+
"--fp32_gpu",
|
|
244
|
+
required=False,
|
|
245
|
+
action="store_true",
|
|
246
|
+
help="Generate fp32 ONNX model for Nvidia GPUs",
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
parser.add_argument(
|
|
250
|
+
"--fp16_gpu",
|
|
251
|
+
required=False,
|
|
252
|
+
action="store_true",
|
|
253
|
+
help="Generate fp16 ONNX model for Nvidia GPUs",
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
parser.add_argument(
|
|
257
|
+
"--int4_gpu",
|
|
258
|
+
required=False,
|
|
259
|
+
action="store_true",
|
|
260
|
+
help="Generate int4 ONNX model for Nvidia GPUs",
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
parser.add_argument(
|
|
264
|
+
"--fp16_gpu_sm8x",
|
|
265
|
+
required=False,
|
|
266
|
+
action="store_true",
|
|
267
|
+
help="Generate fp16 ONNX model for Nvidia GPUs with CUDA architecture SM=80~89",
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
parser.add_argument(
|
|
271
|
+
"--int4_gpu_sm8x",
|
|
272
|
+
required=False,
|
|
273
|
+
action="store_true",
|
|
274
|
+
help="Generate int4 ONNX model for Nvidia GPUs with CUDA architecture SM=80~89",
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
parser.add_argument(
|
|
278
|
+
"--fp16_vllm",
|
|
279
|
+
required=False,
|
|
280
|
+
action="store_true",
|
|
281
|
+
help="Generate fp16 ONNX model for ORT VLLM",
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
parser.add_argument(
|
|
285
|
+
"--int4_vllm",
|
|
286
|
+
required=False,
|
|
287
|
+
action="store_true",
|
|
288
|
+
help="Generate int4 ONNX model for ORT VLLM",
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
parser.add_argument(
|
|
292
|
+
"--use_cuda_graph",
|
|
293
|
+
required=False,
|
|
294
|
+
action="store_true",
|
|
295
|
+
help="Use CUDA Graph in decoding process",
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
parser.add_argument(
|
|
299
|
+
"--overwrite",
|
|
300
|
+
required=False,
|
|
301
|
+
action="store_true",
|
|
302
|
+
help="Overwrite existing ONNX models",
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
parser.add_argument(
|
|
306
|
+
"--cache_dir",
|
|
307
|
+
required=False,
|
|
308
|
+
type=str,
|
|
309
|
+
default="./cache",
|
|
310
|
+
help="The cache directory for the pytorch model",
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
parser.add_argument(
|
|
314
|
+
"--device_id",
|
|
315
|
+
required=False,
|
|
316
|
+
type=int,
|
|
317
|
+
default=0,
|
|
318
|
+
help="The device id for the pytorch model",
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
parser.add_argument(
|
|
322
|
+
"--run_example",
|
|
323
|
+
required=False,
|
|
324
|
+
action="store_true",
|
|
325
|
+
help="Run ORT inference example",
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
parser.add_argument(
|
|
329
|
+
"--run_benchmark",
|
|
330
|
+
required=False,
|
|
331
|
+
action="store_true",
|
|
332
|
+
help="Run ORT benchmark",
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
parser.add_argument(
|
|
336
|
+
"--skip_export",
|
|
337
|
+
required=False,
|
|
338
|
+
action="store_true",
|
|
339
|
+
help="Skip exporting ONNX model",
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
parser.add_argument(
|
|
343
|
+
"--output_dir",
|
|
344
|
+
type=str,
|
|
345
|
+
help="The output directory for the ONNX models",
|
|
346
|
+
default="phi2_onnx_models",
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
parser.add_argument(
|
|
350
|
+
"--block_size",
|
|
351
|
+
required=False,
|
|
352
|
+
default=16,
|
|
353
|
+
type=int,
|
|
354
|
+
help="Block size to quantize with. See https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/python/tools/quantization/matmul_4bits_quantizer.py for details.",
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
parser.add_argument(
|
|
358
|
+
"--int4_accuracy_level",
|
|
359
|
+
required=False,
|
|
360
|
+
type=int,
|
|
361
|
+
help="Accuracy level of the 4-bit quantized MatMul computation. "
|
|
362
|
+
"Refer to the MatMulNBits contrib op's 'accuracy_level' attribute for details "
|
|
363
|
+
"(https://github.com/microsoft/onnxruntime/blob/main/docs/ContribOperators.md#commicrosoftmatmulnbits).",
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
args = parser.parse_args()
|
|
367
|
+
return args
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def main():
|
|
371
|
+
args = parse_arguments()
|
|
372
|
+
|
|
373
|
+
device = torch.device("cuda", args.device_id) if torch.cuda.is_available() else torch.device("cpu")
|
|
374
|
+
|
|
375
|
+
converter = ConvertPhi2ToONNX(device, cache_dir=args.cache_dir)
|
|
376
|
+
converter.set_quantization_params(args.block_size, args.int4_accuracy_level)
|
|
377
|
+
|
|
378
|
+
output_dir = args.output_dir
|
|
379
|
+
|
|
380
|
+
if not os.path.exists(output_dir):
|
|
381
|
+
os.makedirs(output_dir)
|
|
382
|
+
|
|
383
|
+
original_onnx_path = os.path.join(output_dir, "phi2_original.onnx")
|
|
384
|
+
|
|
385
|
+
if not args.skip_export:
|
|
386
|
+
if not os.path.exists(original_onnx_path) or args.overwrite:
|
|
387
|
+
converter.dynamo_export(original_onnx_path)
|
|
388
|
+
|
|
389
|
+
model_type_to_args = {
|
|
390
|
+
"fp32_cpu": (
|
|
391
|
+
AttentionOpType.MultiHeadAttention,
|
|
392
|
+
Precision.FLOAT32,
|
|
393
|
+
os.path.join(output_dir, "phi2_decoder_fp32_cpu.onnx"),
|
|
394
|
+
),
|
|
395
|
+
"int4_cpu": (
|
|
396
|
+
AttentionOpType.MultiHeadAttention,
|
|
397
|
+
Precision.INT4,
|
|
398
|
+
os.path.join(output_dir, "phi2_decoder_int4_cpu.onnx"),
|
|
399
|
+
),
|
|
400
|
+
"fp32_gpu": (
|
|
401
|
+
AttentionOpType.Attention,
|
|
402
|
+
Precision.FLOAT32,
|
|
403
|
+
os.path.join(output_dir, "phi2_decoder_fp32_gpu.onnx"),
|
|
404
|
+
),
|
|
405
|
+
"fp16_gpu": (
|
|
406
|
+
AttentionOpType.Attention,
|
|
407
|
+
Precision.FLOAT16,
|
|
408
|
+
os.path.join(output_dir, "phi2_decoder_fp16_gpu.onnx"),
|
|
409
|
+
),
|
|
410
|
+
"int4_gpu": (AttentionOpType.Attention, Precision.INT4, os.path.join(output_dir, "phi2_decoder_int4_gpu.onnx")),
|
|
411
|
+
"fp16_gpu_sm8x": (
|
|
412
|
+
AttentionOpType.GroupQueryAttention,
|
|
413
|
+
Precision.FLOAT16,
|
|
414
|
+
os.path.join(output_dir, "phi2_decoder_fp16_gpu_sm8x.onnx"),
|
|
415
|
+
),
|
|
416
|
+
"int4_gpu_sm8x": (
|
|
417
|
+
AttentionOpType.GroupQueryAttention,
|
|
418
|
+
Precision.INT4,
|
|
419
|
+
os.path.join(output_dir, "phi2_decoder_int4_gpu_sm8x.onnx"),
|
|
420
|
+
),
|
|
421
|
+
"fp16_vllm": (
|
|
422
|
+
AttentionOpType.PagedAttention,
|
|
423
|
+
Precision.FLOAT16,
|
|
424
|
+
os.path.join(output_dir, "phi2_decoder_fp16_vllm.onnx"),
|
|
425
|
+
),
|
|
426
|
+
"int4_vllm": (
|
|
427
|
+
AttentionOpType.PagedAttention,
|
|
428
|
+
Precision.INT4,
|
|
429
|
+
os.path.join(output_dir, "phi2_decoder_int4_vllm.onnx"),
|
|
430
|
+
),
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if not args.skip_export:
|
|
434
|
+
from multiprocessing import Process
|
|
435
|
+
|
|
436
|
+
def run_optimize_phi2_onnx(
|
|
437
|
+
converter: ConvertPhi2ToONNX,
|
|
438
|
+
original_onnx_path: str,
|
|
439
|
+
attention_type: AttentionOpType,
|
|
440
|
+
precision: Precision,
|
|
441
|
+
optimized_onnx_path: str,
|
|
442
|
+
):
|
|
443
|
+
converter.init_attn_type_and_precision(attention_type, precision)
|
|
444
|
+
converter.optimize_phi2_onnx(original_onnx_path, optimized_onnx_path)
|
|
445
|
+
if args.use_cuda_graph:
|
|
446
|
+
assert args.fp16_gpu_sm8x or args.int4_gpu_sm8x
|
|
447
|
+
converter.convert_to_use_cuda_graph(optimized_onnx_path, optimized_onnx_path)
|
|
448
|
+
|
|
449
|
+
processes = []
|
|
450
|
+
if args.fp32_cpu:
|
|
451
|
+
processes.append(
|
|
452
|
+
Process(
|
|
453
|
+
target=run_optimize_phi2_onnx, args=(converter, original_onnx_path, *model_type_to_args["fp32_cpu"])
|
|
454
|
+
)
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
if args.int4_cpu:
|
|
458
|
+
processes.append(
|
|
459
|
+
Process(
|
|
460
|
+
target=run_optimize_phi2_onnx, args=(converter, original_onnx_path, *model_type_to_args["int4_cpu"])
|
|
461
|
+
)
|
|
462
|
+
)
|
|
463
|
+
|
|
464
|
+
if args.fp32_gpu:
|
|
465
|
+
processes.append(
|
|
466
|
+
Process(
|
|
467
|
+
target=run_optimize_phi2_onnx, args=(converter, original_onnx_path, *model_type_to_args["fp32_gpu"])
|
|
468
|
+
)
|
|
469
|
+
)
|
|
470
|
+
|
|
471
|
+
if args.fp16_gpu:
|
|
472
|
+
processes.append(
|
|
473
|
+
Process(
|
|
474
|
+
target=run_optimize_phi2_onnx, args=(converter, original_onnx_path, *model_type_to_args["fp16_gpu"])
|
|
475
|
+
)
|
|
476
|
+
)
|
|
477
|
+
|
|
478
|
+
if args.int4_gpu:
|
|
479
|
+
processes.append(
|
|
480
|
+
Process(
|
|
481
|
+
target=run_optimize_phi2_onnx, args=(converter, original_onnx_path, *model_type_to_args["int4_gpu"])
|
|
482
|
+
)
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
if args.fp16_gpu_sm8x:
|
|
486
|
+
processes.append(
|
|
487
|
+
Process(
|
|
488
|
+
target=run_optimize_phi2_onnx,
|
|
489
|
+
args=(converter, original_onnx_path, *model_type_to_args["fp16_gpu_sm8x"]),
|
|
490
|
+
)
|
|
491
|
+
)
|
|
492
|
+
|
|
493
|
+
if args.int4_gpu_sm8x:
|
|
494
|
+
processes.append(
|
|
495
|
+
Process(
|
|
496
|
+
target=run_optimize_phi2_onnx,
|
|
497
|
+
args=(converter, original_onnx_path, *model_type_to_args["int4_gpu_sm8x"]),
|
|
498
|
+
)
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
if args.fp16_vllm:
|
|
502
|
+
processes.append(
|
|
503
|
+
Process(
|
|
504
|
+
target=run_optimize_phi2_onnx,
|
|
505
|
+
args=(converter, original_onnx_path, *model_type_to_args["fp16_vllm"]),
|
|
506
|
+
)
|
|
507
|
+
)
|
|
508
|
+
|
|
509
|
+
if args.int4_vllm:
|
|
510
|
+
processes.append(
|
|
511
|
+
Process(
|
|
512
|
+
target=run_optimize_phi2_onnx,
|
|
513
|
+
args=(converter, original_onnx_path, *model_type_to_args["int4_vllm"]),
|
|
514
|
+
)
|
|
515
|
+
)
|
|
516
|
+
|
|
517
|
+
[p.start() for p in processes]
|
|
518
|
+
[p.join() for p in processes]
|
|
519
|
+
|
|
520
|
+
if args.run_example or args.run_benchmark:
|
|
521
|
+
from inference_example import run_phi2
|
|
522
|
+
|
|
523
|
+
if args.fp16_gpu_sm8x:
|
|
524
|
+
logging.info("Running fp16_gpu_sm8x example...")
|
|
525
|
+
run_phi2(
|
|
526
|
+
onnx_model_path=model_type_to_args["fp16_gpu_sm8x"][2],
|
|
527
|
+
use_buffer_share=True,
|
|
528
|
+
device_id=args.device_id,
|
|
529
|
+
use_step=True,
|
|
530
|
+
use_cuda_graph=args.use_cuda_graph,
|
|
531
|
+
run_benchmark=args.run_benchmark,
|
|
532
|
+
)
|
|
533
|
+
if args.int4_gpu_sm8x:
|
|
534
|
+
logging.info("Running int4_gpu_sm8x example...")
|
|
535
|
+
run_phi2(
|
|
536
|
+
onnx_model_path=model_type_to_args["int4_gpu_sm8x"][2],
|
|
537
|
+
use_buffer_share=True,
|
|
538
|
+
device_id=args.device_id,
|
|
539
|
+
use_step=True,
|
|
540
|
+
use_cuda_graph=args.use_cuda_graph,
|
|
541
|
+
run_benchmark=args.run_benchmark,
|
|
542
|
+
)
|
|
543
|
+
if args.fp32_gpu:
|
|
544
|
+
logging.info("Running fp32_gpu example...")
|
|
545
|
+
run_phi2(
|
|
546
|
+
onnx_model_path=model_type_to_args["fp32_gpu"][2],
|
|
547
|
+
use_buffer_share=False,
|
|
548
|
+
device_id=args.device_id,
|
|
549
|
+
packed_kv=True,
|
|
550
|
+
use_fp16=False,
|
|
551
|
+
run_benchmark=args.run_benchmark,
|
|
552
|
+
)
|
|
553
|
+
if args.fp16_gpu:
|
|
554
|
+
logging.info("Running fp16_gpu example...")
|
|
555
|
+
run_phi2(
|
|
556
|
+
onnx_model_path=model_type_to_args["fp16_gpu"][2],
|
|
557
|
+
use_buffer_share=False,
|
|
558
|
+
device_id=args.device_id,
|
|
559
|
+
packed_kv=True,
|
|
560
|
+
run_benchmark=args.run_benchmark,
|
|
561
|
+
)
|
|
562
|
+
if args.int4_gpu:
|
|
563
|
+
logging.info("Running int4_gpu example...")
|
|
564
|
+
run_phi2(
|
|
565
|
+
onnx_model_path=model_type_to_args["int4_gpu"][2],
|
|
566
|
+
use_buffer_share=False,
|
|
567
|
+
device_id=args.device_id,
|
|
568
|
+
packed_kv=True,
|
|
569
|
+
run_benchmark=args.run_benchmark,
|
|
570
|
+
)
|
|
571
|
+
if args.fp32_cpu or args.int4_cpu or args.fp16_vllm or args.int4_vllm:
|
|
572
|
+
raise NotImplementedError("CPU/vllm inference example is not implemented yet.")
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
if __name__ == "__main__":
|
|
576
|
+
main()
|