2021-08-09 17:37:05 +00:00
|
|
|
# ------------------------------------------------------------------------
|
2018-11-20 00:48:22 +00:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
# Licensed under the MIT License.
|
2021-08-09 17:37:05 +00:00
|
|
|
# ------------------------------------------------------------------------
|
2023-01-09 10:48:01 +00:00
|
|
|
# pylint: disable=C0103
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2022-04-26 16:35:16 +00:00
|
|
|
import datetime
|
2023-01-09 10:48:01 +00:00
|
|
|
import logging
|
2022-04-26 16:35:16 +00:00
|
|
|
import platform
|
2023-09-08 19:25:16 +00:00
|
|
|
import shlex
|
2022-04-26 16:35:16 +00:00
|
|
|
import subprocess
|
|
|
|
|
import sys
|
2021-08-28 18:05:21 +00:00
|
|
|
from glob import glob, iglob
|
2022-06-17 21:49:04 +00:00
|
|
|
from os import environ, getcwd, path, popen, remove
|
2022-04-26 16:35:16 +00:00
|
|
|
from pathlib import Path
|
2021-10-20 17:20:35 +00:00
|
|
|
from shutil import copyfile
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2022-09-24 15:32:44 +00:00
|
|
|
from packaging.tags import sys_tags
|
2022-04-26 16:35:16 +00:00
|
|
|
from setuptools import Extension, setup
|
2023-01-09 10:48:01 +00:00
|
|
|
from setuptools.command.build_ext import build_ext as _build_ext
|
2022-06-17 21:49:04 +00:00
|
|
|
from setuptools.command.install import install as InstallCommandBase
|
2022-04-26 16:35:16 +00:00
|
|
|
|
2019-04-12 05:06:18 +00:00
|
|
|
nightly_build = False
|
2022-04-26 16:35:16 +00:00
|
|
|
package_name = "onnxruntime"
|
2020-04-14 16:00:13 +00:00
|
|
|
wheel_name_suffix = None
|
2023-01-09 10:48:01 +00:00
|
|
|
logger = logging.getLogger()
|
2019-06-18 15:58:53 +00:00
|
|
|
|
2021-06-03 06:36:49 +00:00
|
|
|
|
2021-04-13 23:19:42 +00:00
|
|
|
def parse_arg_remove_boolean(argv, arg_name):
|
|
|
|
|
arg_value = False
|
|
|
|
|
if arg_name in sys.argv:
|
|
|
|
|
arg_value = True
|
|
|
|
|
argv.remove(arg_name)
|
|
|
|
|
|
|
|
|
|
return arg_value
|
|
|
|
|
|
2021-06-03 06:36:49 +00:00
|
|
|
|
2021-04-13 23:19:42 +00:00
|
|
|
def parse_arg_remove_string(argv, arg_name_equal):
|
|
|
|
|
arg_value = None
|
|
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
|
if arg.startswith(arg_name_equal):
|
2022-04-26 16:35:16 +00:00
|
|
|
arg_value = arg[len(arg_name_equal) :]
|
2021-04-13 23:19:42 +00:00
|
|
|
sys.argv.remove(arg)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
return arg_value
|
|
|
|
|
|
2021-06-03 06:36:49 +00:00
|
|
|
|
2020-04-29 16:47:51 +00:00
|
|
|
# Any combination of the following arguments can be applied
|
|
|
|
|
|
2022-04-26 16:35:16 +00:00
|
|
|
if parse_arg_remove_boolean(sys.argv, "--nightly_build"):
|
|
|
|
|
package_name = "ort-nightly"
|
2020-04-29 16:47:51 +00:00
|
|
|
nightly_build = True
|
|
|
|
|
|
2022-04-26 16:35:16 +00:00
|
|
|
wheel_name_suffix = parse_arg_remove_string(sys.argv, "--wheel_name_suffix=")
|
2020-04-29 16:47:51 +00:00
|
|
|
|
2021-04-13 23:19:42 +00:00
|
|
|
cuda_version = None
|
2021-04-24 00:22:31 +00:00
|
|
|
rocm_version = None
|
2021-11-02 02:12:09 +00:00
|
|
|
is_rocm = False
|
2022-06-17 21:49:04 +00:00
|
|
|
is_openvino = False
|
2020-04-29 16:47:51 +00:00
|
|
|
# The following arguments are mutually exclusive
|
2022-04-26 16:35:16 +00:00
|
|
|
if wheel_name_suffix == "gpu":
|
2021-08-09 17:37:05 +00:00
|
|
|
# TODO: how to support multiple CUDA versions?
|
2022-04-26 16:35:16 +00:00
|
|
|
cuda_version = parse_arg_remove_string(sys.argv, "--cuda_version=")
|
|
|
|
|
elif parse_arg_remove_boolean(sys.argv, "--use_rocm"):
|
2021-11-02 02:12:09 +00:00
|
|
|
is_rocm = True
|
2024-06-21 08:01:07 +00:00
|
|
|
package_name = "onnxruntime-rocm" if not nightly_build else "ort-rocm-nightly"
|
2022-04-26 16:35:16 +00:00
|
|
|
rocm_version = parse_arg_remove_string(sys.argv, "--rocm_version=")
|
|
|
|
|
elif parse_arg_remove_boolean(sys.argv, "--use_openvino"):
|
2022-06-17 21:49:04 +00:00
|
|
|
is_openvino = True
|
2022-04-26 16:35:16 +00:00
|
|
|
package_name = "onnxruntime-openvino"
|
|
|
|
|
elif parse_arg_remove_boolean(sys.argv, "--use_dnnl"):
|
|
|
|
|
package_name = "onnxruntime-dnnl"
|
|
|
|
|
elif parse_arg_remove_boolean(sys.argv, "--use_tvm"):
|
|
|
|
|
package_name = "onnxruntime-tvm"
|
|
|
|
|
elif parse_arg_remove_boolean(sys.argv, "--use_vitisai"):
|
|
|
|
|
package_name = "onnxruntime-vitisai"
|
|
|
|
|
elif parse_arg_remove_boolean(sys.argv, "--use_acl"):
|
|
|
|
|
package_name = "onnxruntime-acl"
|
|
|
|
|
elif parse_arg_remove_boolean(sys.argv, "--use_armnn"):
|
|
|
|
|
package_name = "onnxruntime-armnn"
|
2022-09-22 21:53:40 +00:00
|
|
|
elif parse_arg_remove_boolean(sys.argv, "--use_cann"):
|
|
|
|
|
package_name = "onnxruntime-cann"
|
2023-01-11 20:25:04 +00:00
|
|
|
elif parse_arg_remove_boolean(sys.argv, "--use_azure"):
|
2023-06-21 16:38:52 +00:00
|
|
|
# keep the same name since AzureEP will release with CpuEP by default.
|
2023-08-18 16:53:36 +00:00
|
|
|
pass
|
2023-03-03 15:26:53 +00:00
|
|
|
elif parse_arg_remove_boolean(sys.argv, "--use_qnn"):
|
|
|
|
|
package_name = "onnxruntime-qnn"
|
2021-06-16 23:59:12 +00:00
|
|
|
|
2020-05-11 17:26:16 +00:00
|
|
|
# PEP 513 defined manylinux1_x86_64 and manylinux1_i686
|
|
|
|
|
# PEP 571 defined manylinux2010_x86_64 and manylinux2010_i686
|
|
|
|
|
# PEP 599 defines the following platform tags:
|
|
|
|
|
# manylinux2014_x86_64
|
|
|
|
|
# manylinux2014_i686
|
|
|
|
|
# manylinux2014_aarch64
|
|
|
|
|
# manylinux2014_armv7l
|
|
|
|
|
# manylinux2014_ppc64
|
|
|
|
|
# manylinux2014_ppc64le
|
|
|
|
|
# manylinux2014_s390x
|
|
|
|
|
manylinux_tags = [
|
2022-04-26 16:35:16 +00:00
|
|
|
"manylinux1_x86_64",
|
|
|
|
|
"manylinux1_i686",
|
|
|
|
|
"manylinux2010_x86_64",
|
|
|
|
|
"manylinux2010_i686",
|
|
|
|
|
"manylinux2014_x86_64",
|
|
|
|
|
"manylinux2014_i686",
|
|
|
|
|
"manylinux2014_aarch64",
|
|
|
|
|
"manylinux2014_armv7l",
|
|
|
|
|
"manylinux2014_ppc64",
|
|
|
|
|
"manylinux2014_ppc64le",
|
|
|
|
|
"manylinux2014_s390x",
|
2023-08-30 04:05:36 +00:00
|
|
|
"manylinux_2_28_x86_64",
|
|
|
|
|
"manylinux_2_28_aarch64",
|
2020-05-11 17:26:16 +00:00
|
|
|
]
|
2022-04-26 16:35:16 +00:00
|
|
|
is_manylinux = environ.get("AUDITWHEEL_PLAT", None) in manylinux_tags
|
2019-06-27 22:45:06 +00:00
|
|
|
|
2021-08-09 17:37:05 +00:00
|
|
|
|
2023-03-24 22:29:03 +00:00
|
|
|
class build_ext(_build_ext): # noqa: N801
|
2019-06-27 22:45:06 +00:00
|
|
|
def build_extension(self, ext):
|
|
|
|
|
dest_file = self.get_ext_fullpath(ext.name)
|
2022-04-26 16:35:16 +00:00
|
|
|
logger.info("copying %s -> %s", ext.sources[0], dest_file)
|
2019-06-27 22:45:06 +00:00
|
|
|
copyfile(ext.sources[0], dest_file)
|
|
|
|
|
|
|
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
try:
|
|
|
|
|
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
|
2021-06-03 06:36:49 +00:00
|
|
|
|
2023-03-24 22:29:03 +00:00
|
|
|
class bdist_wheel(_bdist_wheel): # noqa: N801
|
2022-06-17 21:49:04 +00:00
|
|
|
"""Helper functions to create wheel package"""
|
|
|
|
|
|
|
|
|
|
if is_openvino and is_manylinux:
|
|
|
|
|
|
|
|
|
|
def get_tag(self):
|
|
|
|
|
_, _, plat = _bdist_wheel.get_tag(self)
|
|
|
|
|
if platform.system() == "Linux":
|
|
|
|
|
# Get the right platform tag by querying the linker version
|
|
|
|
|
glibc_major, glibc_minor = popen("ldd --version | head -1").read().split()[-1].split(".")
|
|
|
|
|
"""# See https://github.com/mayeut/pep600_compliance/blob/master/
|
|
|
|
|
pep600_compliance/tools/manylinux-policy.json"""
|
|
|
|
|
if glibc_major == "2" and glibc_minor == "17":
|
|
|
|
|
plat = "manylinux_2_17_x86_64.manylinux2014_x86_64"
|
|
|
|
|
else: # For manylinux2014 and above, no alias is required
|
2023-03-24 22:29:03 +00:00
|
|
|
plat = f"manylinux_{glibc_major}_{glibc_minor}_x86_64"
|
2022-06-17 21:49:04 +00:00
|
|
|
tags = next(sys_tags())
|
|
|
|
|
return (tags.interpreter, tags.abi, plat)
|
|
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
def finalize_options(self):
|
|
|
|
|
_bdist_wheel.finalize_options(self)
|
2020-05-18 16:41:00 +00:00
|
|
|
if not is_manylinux:
|
2019-06-27 22:45:06 +00:00
|
|
|
self.root_is_pure = False
|
|
|
|
|
|
|
|
|
|
def _rewrite_ld_preload(self, to_preload):
|
2022-04-26 16:35:16 +00:00
|
|
|
with open("onnxruntime/capi/_ld_preload.py", "a") as f:
|
2019-06-27 22:45:06 +00:00
|
|
|
if len(to_preload) > 0:
|
2022-04-26 16:35:16 +00:00
|
|
|
f.write("from ctypes import CDLL, RTLD_GLOBAL\n")
|
2019-06-27 22:45:06 +00:00
|
|
|
for library in to_preload:
|
2022-04-26 16:35:16 +00:00
|
|
|
f.write('_{} = CDLL("{}", mode=RTLD_GLOBAL)\n'.format(library.split(".")[0], library))
|
2019-06-27 22:45:06 +00:00
|
|
|
|
2021-09-07 18:09:25 +00:00
|
|
|
def _rewrite_ld_preload_cuda(self, to_preload):
|
2022-04-26 16:35:16 +00:00
|
|
|
with open("onnxruntime/capi/_ld_preload.py", "a") as f:
|
2021-09-07 18:09:25 +00:00
|
|
|
if len(to_preload) > 0:
|
2022-04-26 16:35:16 +00:00
|
|
|
f.write("from ctypes import CDLL, RTLD_GLOBAL\n")
|
|
|
|
|
f.write("try:\n")
|
2021-09-07 18:09:25 +00:00
|
|
|
for library in to_preload:
|
2022-04-26 16:35:16 +00:00
|
|
|
f.write(' _{} = CDLL("{}", mode=RTLD_GLOBAL)\n'.format(library.split(".")[0], library))
|
|
|
|
|
f.write("except OSError:\n")
|
|
|
|
|
f.write(" import os\n")
|
2021-09-07 18:09:25 +00:00
|
|
|
f.write(' os.environ["ORT_CUDA_UNAVAILABLE"] = "1"\n')
|
|
|
|
|
|
2021-11-18 21:26:51 +00:00
|
|
|
def _rewrite_ld_preload_tensorrt(self, to_preload):
|
2023-01-09 10:48:01 +00:00
|
|
|
with open("onnxruntime/capi/_ld_preload.py", "a", encoding="ascii") as f:
|
2021-11-18 21:26:51 +00:00
|
|
|
if len(to_preload) > 0:
|
2022-04-26 16:35:16 +00:00
|
|
|
f.write("from ctypes import CDLL, RTLD_GLOBAL\n")
|
|
|
|
|
f.write("try:\n")
|
2021-11-18 21:26:51 +00:00
|
|
|
for library in to_preload:
|
2022-04-26 16:35:16 +00:00
|
|
|
f.write(' _{} = CDLL("{}", mode=RTLD_GLOBAL)\n'.format(library.split(".")[0], library))
|
|
|
|
|
f.write("except OSError:\n")
|
|
|
|
|
f.write(" import os\n")
|
2021-11-18 21:26:51 +00:00
|
|
|
f.write(' os.environ["ORT_TENSORRT_UNAVAILABLE"] = "1"\n')
|
|
|
|
|
|
2019-06-27 22:45:06 +00:00
|
|
|
def run(self):
|
2020-05-18 16:41:00 +00:00
|
|
|
if is_manylinux:
|
2022-04-26 16:35:16 +00:00
|
|
|
source = "onnxruntime/capi/onnxruntime_pybind11_state.so"
|
|
|
|
|
dest = "onnxruntime/capi/onnxruntime_pybind11_state_manylinux1.so"
|
|
|
|
|
logger.info("copying %s -> %s", source, dest)
|
2019-06-27 22:45:06 +00:00
|
|
|
copyfile(source, dest)
|
2023-09-08 19:25:16 +00:00
|
|
|
|
2019-06-27 22:45:06 +00:00
|
|
|
to_preload = []
|
2021-09-07 18:09:25 +00:00
|
|
|
to_preload_cuda = []
|
2021-11-18 21:26:51 +00:00
|
|
|
to_preload_tensorrt = []
|
2022-12-16 14:57:40 +00:00
|
|
|
to_preload_cann = []
|
2023-09-08 19:25:16 +00:00
|
|
|
|
|
|
|
|
cuda_dependencies = [
|
|
|
|
|
"libcublas.so.11",
|
2023-10-24 22:17:36 +00:00
|
|
|
"libcublas.so.12",
|
2023-09-08 19:25:16 +00:00
|
|
|
"libcublasLt.so.11",
|
2023-10-24 22:17:36 +00:00
|
|
|
"libcublasLt.so.12",
|
2023-09-08 19:25:16 +00:00
|
|
|
"libcudart.so.11.0",
|
2023-11-20 06:06:32 +00:00
|
|
|
"libcudart.so.12",
|
2023-10-24 22:17:36 +00:00
|
|
|
"libcudnn.so.8",
|
2024-06-11 16:37:16 +00:00
|
|
|
"libcudnn.so.9",
|
2023-09-08 19:25:16 +00:00
|
|
|
"libcufft.so.10",
|
2023-10-24 22:17:36 +00:00
|
|
|
"libcufft.so.11",
|
|
|
|
|
"libcurand.so.10",
|
2023-09-08 19:25:16 +00:00
|
|
|
]
|
|
|
|
|
rocm_dependencies = [
|
|
|
|
|
"libamd_comgr.so.2",
|
2023-10-31 00:41:01 +00:00
|
|
|
"libamdhip64.so.5",
|
2024-02-22 05:34:55 +00:00
|
|
|
"libamdhip64.so.6",
|
2023-09-08 19:25:16 +00:00
|
|
|
"libdrm.so.2",
|
|
|
|
|
"libdrm_amdgpu.so.1",
|
|
|
|
|
"libelf.so.1",
|
2023-10-31 00:41:01 +00:00
|
|
|
"libhipfft.so.0",
|
|
|
|
|
"libhiprtc.so.5",
|
2024-02-22 05:34:55 +00:00
|
|
|
"libhiprtc.so.6",
|
2023-09-08 19:25:16 +00:00
|
|
|
"libhsa-runtime64.so.1",
|
2023-10-31 00:41:01 +00:00
|
|
|
"libMIOpen.so.1",
|
|
|
|
|
"libnuma.so.1",
|
|
|
|
|
"librccl.so.1",
|
|
|
|
|
"librocblas.so.3",
|
2024-02-22 05:34:55 +00:00
|
|
|
"librocblas.so.4",
|
2023-10-31 00:41:01 +00:00
|
|
|
"librocfft.so.0",
|
2024-02-22 05:34:55 +00:00
|
|
|
"libroctx64.so.4",
|
2023-10-31 00:41:01 +00:00
|
|
|
"librocm_smi64.so.5",
|
2024-02-22 05:34:55 +00:00
|
|
|
"librocm_smi64.so.6",
|
2023-10-31 00:41:01 +00:00
|
|
|
"libroctracer64.so.4",
|
|
|
|
|
"libtinfo.so.6",
|
2023-11-14 03:54:22 +00:00
|
|
|
"libmigraphx_c.so.3",
|
|
|
|
|
"libmigraphx.so.2",
|
|
|
|
|
"libmigraphx_onnx.so.2",
|
|
|
|
|
"libmigraphx_tf.so.2",
|
2023-09-08 19:25:16 +00:00
|
|
|
]
|
|
|
|
|
|
2024-05-04 05:39:20 +00:00
|
|
|
tensorrt_dependencies = ["libnvinfer.so.10", "libnvinfer_plugin.so.10", "libnvonnxparser.so.10"]
|
2022-12-16 14:57:40 +00:00
|
|
|
|
2024-03-16 03:28:43 +00:00
|
|
|
cann_dependencies = ["libascendcl.so", "libacl_op_compiler.so", "libfmk_onnx_parser.so"]
|
|
|
|
|
|
2022-06-17 21:49:04 +00:00
|
|
|
dest = "onnxruntime/capi/libonnxruntime_providers_openvino.so"
|
|
|
|
|
if path.isfile(dest):
|
|
|
|
|
subprocess.run(
|
|
|
|
|
["patchelf", "--set-rpath", "$ORIGIN", dest, "--force-rpath"],
|
|
|
|
|
check=True,
|
|
|
|
|
stdout=subprocess.PIPE,
|
2023-03-24 22:29:03 +00:00
|
|
|
text=True,
|
2022-06-17 21:49:04 +00:00
|
|
|
)
|
|
|
|
|
|
2021-07-03 00:15:28 +00:00
|
|
|
self._rewrite_ld_preload(to_preload)
|
2021-09-07 18:09:25 +00:00
|
|
|
self._rewrite_ld_preload_cuda(to_preload_cuda)
|
2021-11-18 21:26:51 +00:00
|
|
|
self._rewrite_ld_preload_tensorrt(to_preload_tensorrt)
|
2022-12-16 14:57:40 +00:00
|
|
|
self._rewrite_ld_preload(to_preload_cann)
|
CloudEP (#13855)
Implement CloudEP for hybrid inferencing.
The PR introduces zero new API, customers could configure session and
run options to do inferencing with Azure [triton
endpoint.](https://learn.microsoft.com/en-us/azure/machine-learning/how-to-deploy-with-triton?tabs=azure-cli%2Cendpoint)
Sample configuration in python be like:
```
sess_opt.add_session_config_entry('cloud.endpoint_type', 'triton');
sess_opt.add_session_config_entry('cloud.uri', 'https://cloud.com');
sess_opt.add_session_config_entry('cloud.model_name', 'detection2');
sess_opt.add_session_config_entry('cloud.model_version', '7'); // optional, default 1
sess_opt.add_session_config_entry('cloud.verbose', '1'); // optional, default '0', meaning no verbose
...
run_opt.add_run_config_entry('use_cloud', '1') # 0 for local inferencing, 1 for cloud endpoint.
run_opt.add_run_config_entry('cloud.auth_key', '...')
...
sess.run(None, {'input':input_}, run_opt)
```
Co-authored-by: Randy Shuai <rashuai@microsoft.com>
2023-01-03 18:03:15 +00:00
|
|
|
|
|
|
|
|
else:
|
2023-05-22 23:38:47 +00:00
|
|
|
pass
|
CloudEP (#13855)
Implement CloudEP for hybrid inferencing.
The PR introduces zero new API, customers could configure session and
run options to do inferencing with Azure [triton
endpoint.](https://learn.microsoft.com/en-us/azure/machine-learning/how-to-deploy-with-triton?tabs=azure-cli%2Cendpoint)
Sample configuration in python be like:
```
sess_opt.add_session_config_entry('cloud.endpoint_type', 'triton');
sess_opt.add_session_config_entry('cloud.uri', 'https://cloud.com');
sess_opt.add_session_config_entry('cloud.model_name', 'detection2');
sess_opt.add_session_config_entry('cloud.model_version', '7'); // optional, default 1
sess_opt.add_session_config_entry('cloud.verbose', '1'); // optional, default '0', meaning no verbose
...
run_opt.add_run_config_entry('use_cloud', '1') # 0 for local inferencing, 1 for cloud endpoint.
run_opt.add_run_config_entry('cloud.auth_key', '...')
...
sess.run(None, {'input':input_}, run_opt)
```
Co-authored-by: Randy Shuai <rashuai@microsoft.com>
2023-01-03 18:03:15 +00:00
|
|
|
|
2019-06-27 22:45:06 +00:00
|
|
|
_bdist_wheel.run(self)
|
2022-06-17 21:49:04 +00:00
|
|
|
if is_manylinux and not disable_auditwheel_repair and not is_openvino:
|
|
|
|
|
assert self.dist_dir is not None
|
2022-04-26 16:35:16 +00:00
|
|
|
file = glob(path.join(self.dist_dir, "*linux*.whl"))[0]
|
|
|
|
|
logger.info("repairing %s for manylinux1", file)
|
2023-09-08 19:25:16 +00:00
|
|
|
auditwheel_cmd = ["auditwheel", "-v", "repair", "-w", self.dist_dir, file]
|
2024-03-16 03:28:43 +00:00
|
|
|
for i in cuda_dependencies + rocm_dependencies + tensorrt_dependencies + cann_dependencies:
|
2023-09-08 19:25:16 +00:00
|
|
|
auditwheel_cmd += ["--exclude", i]
|
2024-03-13 17:00:32 +00:00
|
|
|
logger.info("Running %s", " ".join([shlex.quote(arg) for arg in auditwheel_cmd]))
|
2019-06-27 22:45:06 +00:00
|
|
|
try:
|
2023-09-08 19:25:16 +00:00
|
|
|
subprocess.run(auditwheel_cmd, check=True, stdout=subprocess.PIPE)
|
2019-06-27 22:45:06 +00:00
|
|
|
finally:
|
2022-04-26 16:35:16 +00:00
|
|
|
logger.info("removing %s", file)
|
2019-06-27 22:45:06 +00:00
|
|
|
remove(file)
|
|
|
|
|
|
2019-11-27 21:03:23 +00:00
|
|
|
except ImportError as error:
|
|
|
|
|
print("Error importing dependencies:")
|
|
|
|
|
print(error)
|
2018-11-20 00:48:22 +00:00
|
|
|
bdist_wheel = None
|
|
|
|
|
|
2022-06-17 21:49:04 +00:00
|
|
|
|
|
|
|
|
class InstallCommand(InstallCommandBase):
|
|
|
|
|
def finalize_options(self):
|
|
|
|
|
ret = InstallCommandBase.finalize_options(self)
|
|
|
|
|
self.install_lib = self.install_platlib
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
2024-06-21 08:01:07 +00:00
|
|
|
providers_cuda_or_rocm = "libonnxruntime_providers_" + ("rocm.so" if is_rocm else "cuda.so")
|
|
|
|
|
providers_tensorrt_or_migraphx = "libonnxruntime_providers_" + ("migraphx.so" if is_rocm else "tensorrt.so")
|
|
|
|
|
providers_openvino = "libonnxruntime_providers_openvino.so"
|
|
|
|
|
providers_cann = "libonnxruntime_providers_cann.so"
|
2022-06-17 21:49:04 +00:00
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
# Additional binaries
|
2022-06-17 21:49:04 +00:00
|
|
|
dl_libs = []
|
|
|
|
|
libs = []
|
|
|
|
|
|
2022-04-26 16:35:16 +00:00
|
|
|
if platform.system() == "Linux":
|
|
|
|
|
libs = [
|
|
|
|
|
"onnxruntime_pybind11_state.so",
|
|
|
|
|
"libdnnl.so.2",
|
|
|
|
|
"libmklml_intel.so",
|
|
|
|
|
"libmklml_gnu.so",
|
|
|
|
|
"libiomp5.so",
|
|
|
|
|
"mimalloc.so",
|
|
|
|
|
]
|
2024-06-21 08:01:07 +00:00
|
|
|
dl_libs = ["libonnxruntime_providers_shared.so"]
|
|
|
|
|
dl_libs.append(providers_cuda_or_rocm)
|
|
|
|
|
dl_libs.append(providers_tensorrt_or_migraphx)
|
|
|
|
|
dl_libs.append(providers_cann)
|
|
|
|
|
# DNNL, TensorRT & OpenVINO EPs are built as shared libs
|
|
|
|
|
libs.extend(["libonnxruntime_providers_shared.so"])
|
|
|
|
|
libs.extend(["libonnxruntime_providers_dnnl.so"])
|
|
|
|
|
libs.extend(["libonnxruntime_providers_openvino.so"])
|
|
|
|
|
libs.extend(["libonnxruntime_providers_vitisai.so"])
|
|
|
|
|
libs.append(providers_cuda_or_rocm)
|
|
|
|
|
libs.append(providers_tensorrt_or_migraphx)
|
|
|
|
|
libs.append(providers_cann)
|
2021-08-09 17:37:05 +00:00
|
|
|
if nightly_build:
|
2022-04-26 16:35:16 +00:00
|
|
|
libs.extend(["libonnxruntime_pywrapper.so"])
|
2018-11-29 04:01:21 +00:00
|
|
|
elif platform.system() == "Darwin":
|
2022-04-26 16:35:16 +00:00
|
|
|
libs = ["onnxruntime_pybind11_state.so", "libdnnl.2.dylib", "mimalloc.so"] # TODO add libmklml and libiomp5 later.
|
2021-08-09 17:37:05 +00:00
|
|
|
# DNNL & TensorRT EPs are built as shared libs
|
2022-04-26 16:35:16 +00:00
|
|
|
libs.extend(["libonnxruntime_providers_shared.dylib"])
|
|
|
|
|
libs.extend(["libonnxruntime_providers_dnnl.dylib"])
|
|
|
|
|
libs.extend(["libonnxruntime_providers_tensorrt.dylib"])
|
|
|
|
|
libs.extend(["libonnxruntime_providers_cuda.dylib"])
|
2024-02-01 05:08:26 +00:00
|
|
|
libs.extend(["libonnxruntime_providers_vitisai.dylib"])
|
2021-08-09 17:37:05 +00:00
|
|
|
if nightly_build:
|
2022-04-26 16:35:16 +00:00
|
|
|
libs.extend(["libonnxruntime_pywrapper.dylib"])
|
2018-11-20 00:48:22 +00:00
|
|
|
else:
|
2024-06-21 08:01:07 +00:00
|
|
|
libs = ["onnxruntime_pybind11_state.pyd", "dnnl.dll", "mklml.dll", "libiomp5md.dll"]
|
2021-08-09 17:37:05 +00:00
|
|
|
# DNNL, TensorRT & OpenVINO EPs are built as shared libs
|
2022-04-26 16:35:16 +00:00
|
|
|
libs.extend(["onnxruntime_providers_shared.dll"])
|
|
|
|
|
libs.extend(["onnxruntime_providers_dnnl.dll"])
|
|
|
|
|
libs.extend(["onnxruntime_providers_tensorrt.dll"])
|
|
|
|
|
libs.extend(["onnxruntime_providers_openvino.dll"])
|
|
|
|
|
libs.extend(["onnxruntime_providers_cuda.dll"])
|
2024-02-01 05:08:26 +00:00
|
|
|
libs.extend(["onnxruntime_providers_vitisai.dll"])
|
2021-08-09 17:37:05 +00:00
|
|
|
# DirectML Libs
|
2022-04-26 16:35:16 +00:00
|
|
|
libs.extend(["DirectML.dll"])
|
2024-04-29 16:44:54 +00:00
|
|
|
# QNN V68/V73 dependencies
|
|
|
|
|
qnn_deps = [
|
|
|
|
|
"QnnCpu.dll",
|
|
|
|
|
"QnnHtp.dll",
|
|
|
|
|
"QnnSaver.dll",
|
|
|
|
|
"QnnSystem.dll",
|
|
|
|
|
"QnnHtpPrepare.dll",
|
|
|
|
|
"QnnHtpV73Stub.dll",
|
|
|
|
|
"libQnnHtpV73Skel.so",
|
|
|
|
|
"libqnnhtpv73.cat",
|
|
|
|
|
"QnnHtpV68Stub.dll",
|
|
|
|
|
"libQnnHtpV68Skel.so",
|
|
|
|
|
]
|
|
|
|
|
libs.extend(qnn_deps)
|
2021-08-09 17:37:05 +00:00
|
|
|
if nightly_build:
|
2022-04-26 16:35:16 +00:00
|
|
|
libs.extend(["onnxruntime_pywrapper.dll"])
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2020-05-18 16:41:00 +00:00
|
|
|
if is_manylinux:
|
2022-06-17 21:49:04 +00:00
|
|
|
if is_openvino:
|
|
|
|
|
ov_libs = [
|
|
|
|
|
"libopenvino_intel_cpu_plugin.so",
|
|
|
|
|
"libopenvino_intel_gpu_plugin.so",
|
|
|
|
|
"libopenvino_auto_plugin.so",
|
|
|
|
|
"libopenvino_hetero_plugin.so",
|
|
|
|
|
"libtbb.so.2",
|
|
|
|
|
"libtbbmalloc.so.2",
|
|
|
|
|
"libopenvino.so",
|
|
|
|
|
"libopenvino_c.so",
|
|
|
|
|
"libopenvino_onnx_frontend.so",
|
|
|
|
|
]
|
|
|
|
|
for x in ov_libs:
|
|
|
|
|
y = "onnxruntime/capi/" + x
|
|
|
|
|
subprocess.run(
|
|
|
|
|
["patchelf", "--set-rpath", "$ORIGIN", y, "--force-rpath"],
|
|
|
|
|
check=True,
|
|
|
|
|
stdout=subprocess.PIPE,
|
2023-03-24 22:29:03 +00:00
|
|
|
text=True,
|
2022-06-17 21:49:04 +00:00
|
|
|
)
|
|
|
|
|
dl_libs.append(x)
|
|
|
|
|
dl_libs.append(providers_openvino)
|
|
|
|
|
dl_libs.append("plugins.xml")
|
|
|
|
|
dl_libs.append("usb-ma2x8x.mvcmd")
|
2022-04-26 16:35:16 +00:00
|
|
|
data = ["capi/libonnxruntime_pywrapper.so"] if nightly_build else []
|
|
|
|
|
data += [path.join("capi", x) for x in dl_libs if path.isfile(path.join("onnxruntime", "capi", x))]
|
2019-06-27 22:45:06 +00:00
|
|
|
ext_modules = [
|
|
|
|
|
Extension(
|
2022-04-26 16:35:16 +00:00
|
|
|
"onnxruntime.capi.onnxruntime_pybind11_state",
|
|
|
|
|
["onnxruntime/capi/onnxruntime_pybind11_state_manylinux1.so"],
|
2019-06-27 22:45:06 +00:00
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
else:
|
2022-04-26 16:35:16 +00:00
|
|
|
data = [path.join("capi", x) for x in libs if path.isfile(path.join("onnxruntime", "capi", x))]
|
2019-06-27 22:45:06 +00:00
|
|
|
ext_modules = []
|
|
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
# Additional examples
|
2019-07-04 03:10:29 +00:00
|
|
|
examples_names = ["mul_1.onnx", "logreg_iris.onnx", "sigmoid.onnx"]
|
2022-04-26 16:35:16 +00:00
|
|
|
examples = [path.join("datasets", x) for x in examples_names]
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2024-04-29 16:44:54 +00:00
|
|
|
# Extra files such as EULA and ThirdPartyNotices (and Qualcomm License, only for QNN release packages)
|
|
|
|
|
extra = ["LICENSE", "ThirdPartyNotices.txt", "Privacy.md", "Qualcomm AI Hub Proprietary License.pdf"]
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
# Description
|
2022-06-17 21:49:04 +00:00
|
|
|
readme_file = "docs/python/ReadMeOV.rst" if is_openvino else "docs/python/README.rst"
|
|
|
|
|
README = path.join(getcwd(), readme_file)
|
2018-11-20 00:48:22 +00:00
|
|
|
if not path.exists(README):
|
|
|
|
|
this = path.dirname(__file__)
|
2022-06-17 21:49:04 +00:00
|
|
|
README = path.join(this, readme_file)
|
|
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
if not path.exists(README):
|
|
|
|
|
raise FileNotFoundError("Unable to find 'README.rst'")
|
2023-03-24 22:29:03 +00:00
|
|
|
with open(README, encoding="utf-8") as fdesc:
|
2023-01-09 10:48:01 +00:00
|
|
|
long_description = fdesc.read()
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2021-08-28 18:05:21 +00:00
|
|
|
# Include files in onnxruntime/external if --enable_external_custom_op_schemas build.sh command
|
|
|
|
|
# line option is specified.
|
|
|
|
|
# If the options is not specified this following condition fails as onnxruntime/external folder is not created in the
|
|
|
|
|
# build flow under the build binary directory.
|
2022-04-26 16:35:16 +00:00
|
|
|
if path.isdir(path.join("onnxruntime", "external")):
|
2021-08-28 18:05:21 +00:00
|
|
|
# Gather all files under onnxruntime/external directory.
|
2022-04-26 16:35:16 +00:00
|
|
|
extra.extend(
|
|
|
|
|
list(
|
|
|
|
|
str(Path(*Path(x).parts[1:]))
|
|
|
|
|
for x in list(iglob(path.join(path.join("onnxruntime", "external"), "**/*.*"), recursive=True))
|
|
|
|
|
)
|
|
|
|
|
)
|
2021-08-28 18:05:21 +00:00
|
|
|
|
2020-04-23 20:27:22 +00:00
|
|
|
packages = [
|
2022-04-26 16:35:16 +00:00
|
|
|
"onnxruntime",
|
|
|
|
|
"onnxruntime.backend",
|
|
|
|
|
"onnxruntime.capi",
|
|
|
|
|
"onnxruntime.datasets",
|
|
|
|
|
"onnxruntime.tools",
|
|
|
|
|
"onnxruntime.tools.mobile_helpers",
|
|
|
|
|
"onnxruntime.tools.ort_format_model",
|
|
|
|
|
"onnxruntime.tools.ort_format_model.ort_flatbuffers_py",
|
|
|
|
|
"onnxruntime.tools.ort_format_model.ort_flatbuffers_py.fbs",
|
|
|
|
|
"onnxruntime.tools.qdq_helpers",
|
|
|
|
|
"onnxruntime.quantization",
|
|
|
|
|
"onnxruntime.quantization.operators",
|
|
|
|
|
"onnxruntime.quantization.CalTableFlatBuffers",
|
2023-12-12 16:43:04 +00:00
|
|
|
"onnxruntime.quantization.fusions",
|
[Quantization] Tensor quant overrides and QNN EP quantization configuration (#18465)
### Description
#### 1. Adds `TensorQuantOverrides` extra option
Allows specifying a dictionary of tensor-level quantization overrides:
```
TensorQuantOverrides = dictionary :
Default is {}. Set tensor quantization overrides. The key is a tensor name and the value is a
list of dictionaries. For per-tensor quantization, the list contains a single dictionary. For
per-channel quantization, the list contains a dictionary for each channel in the tensor.
Each dictionary contains optional overrides with the following keys and values.
'quant_type' = QuantType : The tensor's quantization data type.
'scale' = Float : The scale value to use. Must also specify `zero_point` if set.
'zero_point' = Int : The zero-point value to use. Must also specify `scale` is set.
'symmetric' = Bool : If the tensor should use symmetric quantization. Invalid if also
set `scale` or `zero_point`.
'reduce_range' = Bool : If the quantization range should be reduced. Invalid if also
set `scale` or `zero_point`.
'rmax' = Float : Override the maximum real tensor value in calibration data.
Invalid if also set `scale` or `zero_point`.
'rmin' = Float : Override the minimum real tensor value in calibration data.
Invalid if also set `scale` or `zero_point`.
```
- All of the options are optional.
- Some combinations are invalid.
- Ex: `rmax` and `rmin` are unnecessary if the `zero_point` and `scale`
are also specified.
Example for per-tensor quantization overrides:
```Python3
extra_options = {
"TensorQuantOverrides": {
"SIG_OUT": [{"scale": 1.0, "zero_point": 127}],
"WGT": [{"quant_type": quantization.QuantType.QInt8, "symmetric": True, "reduce_range": True}],
"BIAS": [{"quant_type": quantization.QuantType.QInt8, "symmetric": True, "reduce_range": True}],
},
}
```
Example for per-channel quantization overrides (Conv weight and bias):
```Python3
extra_options = {
"TensorQuantOverrides": {
"WGT": [
{
"quant_type": quantization.QuantType.QUInt8,
"rmin": 0.0,
"rmax": 2.5,
"reduce_range": True,
},
{
"quant_type": quantization.QuantType.QUInt8,
"rmin": 0.2,
"rmax": 2.55,
"reduce_range": False,
},
],
"BIAS": [
{"zero_point": 0, "scale": 0.000621},
{"zero_point": 0, "scale": 0.23},
],
},
}
```
#### 2. Adds utilities to get the default QDQ configs for QNN EP
Added a `quantization.execution_providers.qnn.get_qnn_qdq_config` method
that inspects the model and returns suitable quantization
configurations.
Example usage:
```python3
from quantization import quantize, QuantType
from quantization.execution_providers.qnn import get_qnn_qdq_config
qnn_config = get_qnn_qdq_config(input_model_path,
data_reader,
activation_type=QuantType.QUInt16,
weight_type=QuantType.QUInt8)
quantize(input_model_path,
output_model_path,
qnn_config)
```
### Motivation and Context
Make it possible to create more QDQ models that run on QNN EP.
---------
Signed-off-by: adrianlizarraga <adlizarraga@microsoft.com>
2023-12-05 01:54:58 +00:00
|
|
|
"onnxruntime.quantization.execution_providers.qnn",
|
2022-04-26 16:35:16 +00:00
|
|
|
"onnxruntime.transformers",
|
2023-02-07 15:49:15 +00:00
|
|
|
"onnxruntime.transformers.models.bart",
|
|
|
|
|
"onnxruntime.transformers.models.bert",
|
2022-04-26 16:35:16 +00:00
|
|
|
"onnxruntime.transformers.models.gpt2",
|
2023-08-23 01:05:11 +00:00
|
|
|
"onnxruntime.transformers.models.llama",
|
2022-04-26 16:35:16 +00:00
|
|
|
"onnxruntime.transformers.models.longformer",
|
2024-02-05 18:15:16 +00:00
|
|
|
"onnxruntime.transformers.models.phi2",
|
2022-04-26 16:35:16 +00:00
|
|
|
"onnxruntime.transformers.models.t5",
|
2023-02-07 15:49:15 +00:00
|
|
|
"onnxruntime.transformers.models.stable_diffusion",
|
2023-04-28 23:03:55 +00:00
|
|
|
"onnxruntime.transformers.models.whisper",
|
2020-04-23 20:27:22 +00:00
|
|
|
]
|
|
|
|
|
|
2022-04-28 06:13:26 +00:00
|
|
|
package_data = {"onnxruntime.tools.mobile_helpers": ["*.md", "*.config"]}
|
|
|
|
|
data_files = []
|
|
|
|
|
|
2021-03-24 01:43:19 +00:00
|
|
|
requirements_file = "requirements.txt"
|
|
|
|
|
|
2021-04-13 23:19:42 +00:00
|
|
|
local_version = None
|
2022-04-26 16:35:16 +00:00
|
|
|
enable_training = parse_arg_remove_boolean(sys.argv, "--enable_training")
|
2023-01-03 21:28:16 +00:00
|
|
|
enable_training_apis = parse_arg_remove_boolean(sys.argv, "--enable_training_apis")
|
2022-10-17 02:11:20 +00:00
|
|
|
enable_rocm_profiling = parse_arg_remove_boolean(sys.argv, "--enable_rocm_profiling")
|
2022-04-26 16:35:16 +00:00
|
|
|
disable_auditwheel_repair = parse_arg_remove_boolean(sys.argv, "--disable_auditwheel_repair")
|
|
|
|
|
default_training_package_device = parse_arg_remove_boolean(sys.argv, "--default_training_package_device")
|
2021-05-27 05:44:20 +00:00
|
|
|
|
2021-08-20 15:53:25 +00:00
|
|
|
classifiers = [
|
2022-04-26 16:35:16 +00:00
|
|
|
"Development Status :: 5 - Production/Stable",
|
|
|
|
|
"Intended Audience :: Developers",
|
|
|
|
|
"License :: OSI Approved :: MIT License",
|
|
|
|
|
"Operating System :: POSIX :: Linux",
|
|
|
|
|
"Topic :: Scientific/Engineering",
|
|
|
|
|
"Topic :: Scientific/Engineering :: Mathematics",
|
|
|
|
|
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
|
|
|
"Topic :: Software Development",
|
|
|
|
|
"Topic :: Software Development :: Libraries",
|
|
|
|
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
|
|
|
"Programming Language :: Python",
|
|
|
|
|
"Programming Language :: Python :: 3 :: Only",
|
|
|
|
|
"Programming Language :: Python :: 3.7",
|
|
|
|
|
"Programming Language :: Python :: 3.8",
|
|
|
|
|
"Programming Language :: Python :: 3.9",
|
2022-07-12 22:28:30 +00:00
|
|
|
"Programming Language :: Python :: 3.10",
|
2023-07-28 20:04:50 +00:00
|
|
|
"Programming Language :: Python :: 3.11",
|
2024-01-11 16:34:28 +00:00
|
|
|
"Programming Language :: Python :: 3.12",
|
2023-08-08 03:32:55 +00:00
|
|
|
"Operating System :: Microsoft :: Windows",
|
|
|
|
|
"Operating System :: MacOS",
|
2022-04-26 16:35:16 +00:00
|
|
|
]
|
2021-08-20 15:53:25 +00:00
|
|
|
|
2023-02-01 01:17:26 +00:00
|
|
|
if enable_training or enable_training_apis:
|
|
|
|
|
packages.append("onnxruntime.training")
|
|
|
|
|
if enable_training:
|
|
|
|
|
packages.extend(
|
|
|
|
|
[
|
|
|
|
|
"onnxruntime.training.amp",
|
|
|
|
|
"onnxruntime.training.experimental",
|
|
|
|
|
"onnxruntime.training.experimental.gradient_graph",
|
|
|
|
|
"onnxruntime.training.optim",
|
|
|
|
|
"onnxruntime.training.ortmodule",
|
|
|
|
|
"onnxruntime.training.ortmodule.experimental",
|
|
|
|
|
"onnxruntime.training.ortmodule.experimental.json_config",
|
|
|
|
|
"onnxruntime.training.ortmodule.experimental.hierarchical_ortmodule",
|
|
|
|
|
"onnxruntime.training.ortmodule.torch_cpp_extensions",
|
|
|
|
|
"onnxruntime.training.ortmodule.torch_cpp_extensions.cpu.aten_op_executor",
|
|
|
|
|
"onnxruntime.training.ortmodule.torch_cpp_extensions.cpu.torch_interop_utils",
|
|
|
|
|
"onnxruntime.training.ortmodule.torch_cpp_extensions.cuda.torch_gpu_allocator",
|
|
|
|
|
"onnxruntime.training.ortmodule.torch_cpp_extensions.cuda.fused_ops",
|
2023-10-27 02:29:27 +00:00
|
|
|
"onnxruntime.training.ortmodule.graph_optimizers",
|
2024-04-18 18:30:15 +00:00
|
|
|
"onnxruntime.training.ortmodule.experimental.pipe",
|
2023-07-13 10:17:58 +00:00
|
|
|
"onnxruntime.training.ort_triton",
|
|
|
|
|
"onnxruntime.training.ort_triton.kernel",
|
2023-08-04 05:58:21 +00:00
|
|
|
"onnxruntime.training.utils",
|
2023-02-01 01:17:26 +00:00
|
|
|
"onnxruntime.training.utils.data",
|
Statistics tool for ORTModule convergence parity (#15020)
### Statistics tool for ORTModule convergence parity
As ORTModule get more and more validated, it is pretty fast to
intergrade PyTorch based model with ORT.
The same time, we need make sure once there is convergence issue, we
don't spend months of time to investigate. As part of this efforts, this
PR is introducing a tool to dump activation statistics without much
involvement from users. The dumping results contains only some statistic
numbers plus sampled data, which is not big, compared with dumping all
the tensors, it is much faster and space efficient.
For us to use it, two single lines are needed before wrapping ORTModule.
For baseline run, need also apply the same trick.
```
+ from onnxruntime.training.utils.hooks import SubscriberManager, StatisticsSubscriber
+ SubscriberManager.subscribe(model, [StatisticsSubscriber("pt_out", override_output_dir=True)])
```
Once you run the steps, following command can be used to merge result
into per-step-summary respectively for ORT and baseline runs.
```bash
python -m onnxruntime.training.utils.hooks.merge_activation_summary --pt_dir pt_out --ort_dir ort_out --output_dir /tmp/output
```
Docs is added here as part of this PR [convergence investigation
notes](https://github.com/microsoft/onnxruntime/blob/pengwa/conv_tool/docs/ORTModule_Convergence_Notes.md)
Based on the generated merged files, we can compare them with tools.

### Design and Implementation
This PR introduced a common mechanism registering custom logic for
nn.Module's post forward hooks. And statistics for activation
(StatisticsSubscriber) is one of the implementations. If there is other
needs, we can define another XXSubscriber to do the customized things.
2023-03-23 12:34:24 +00:00
|
|
|
"onnxruntime.training.utils.hooks",
|
2023-08-08 03:32:55 +00:00
|
|
|
"onnxruntime.training.api",
|
|
|
|
|
"onnxruntime.training.onnxblock",
|
|
|
|
|
"onnxruntime.training.onnxblock.loss",
|
|
|
|
|
"onnxruntime.training.onnxblock.optim",
|
2023-02-01 01:17:26 +00:00
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
package_data["onnxruntime.training.ortmodule.torch_cpp_extensions.cpu.aten_op_executor"] = ["*.cc"]
|
2023-12-15 05:32:19 +00:00
|
|
|
package_data["onnxruntime.training.ortmodule.torch_cpp_extensions.cpu.torch_interop_utils"] = ["*.cc", "*.h"]
|
2023-02-01 01:17:26 +00:00
|
|
|
package_data["onnxruntime.training.ortmodule.torch_cpp_extensions.cuda.torch_gpu_allocator"] = ["*.cc"]
|
|
|
|
|
package_data["onnxruntime.training.ortmodule.torch_cpp_extensions.cuda.fused_ops"] = [
|
|
|
|
|
"*.cpp",
|
|
|
|
|
"*.cu",
|
|
|
|
|
"*.cuh",
|
|
|
|
|
"*.h",
|
|
|
|
|
]
|
|
|
|
|
|
2021-03-24 01:43:19 +00:00
|
|
|
requirements_file = "requirements-training.txt"
|
2021-04-13 23:19:42 +00:00
|
|
|
# with training, we want to follow this naming convention:
|
|
|
|
|
# stable:
|
|
|
|
|
# onnxruntime-training-1.7.0+cu111-cp36-cp36m-linux_x86_64.whl
|
|
|
|
|
# nightly:
|
|
|
|
|
# onnxruntime-training-1.7.0.dev20210408+cu111-cp36-cp36m-linux_x86_64.whl
|
|
|
|
|
# this is needed immediately by pytorch/ort so that the user is able to
|
|
|
|
|
# install an onnxruntime training package with matching torch cuda version.
|
2022-06-17 21:49:04 +00:00
|
|
|
if not is_openvino:
|
|
|
|
|
# To support the package consisting of both openvino and training modules part of it
|
|
|
|
|
package_name = "onnxruntime-training"
|
2021-05-27 05:44:20 +00:00
|
|
|
|
2023-01-12 00:31:26 +00:00
|
|
|
disable_local_version = environ.get("ORT_DISABLE_PYTHON_PACKAGE_LOCAL_VERSION", "0")
|
|
|
|
|
disable_local_version = (
|
|
|
|
|
disable_local_version == "1"
|
|
|
|
|
or disable_local_version.lower() == "true"
|
|
|
|
|
or disable_local_version.lower() == "yes"
|
|
|
|
|
)
|
|
|
|
|
# local version should be disabled for internal feeds.
|
|
|
|
|
if not disable_local_version:
|
|
|
|
|
# we want put default training packages to pypi. pypi does not accept package with a local version.
|
|
|
|
|
if not default_training_package_device or nightly_build:
|
|
|
|
|
if cuda_version:
|
|
|
|
|
# removing '.' to make Cuda version number in the same form as Pytorch.
|
|
|
|
|
local_version = "+cu" + cuda_version.replace(".", "")
|
|
|
|
|
elif rocm_version:
|
|
|
|
|
# removing '.' to make Rocm version number in the same form as Pytorch.
|
|
|
|
|
local_version = "+rocm" + rocm_version.replace(".", "")
|
|
|
|
|
else:
|
|
|
|
|
# cpu version for documentation
|
|
|
|
|
local_version = "+cpu"
|
2023-08-14 18:32:35 +00:00
|
|
|
else:
|
|
|
|
|
if not (cuda_version or rocm_version):
|
|
|
|
|
# Training CPU package for ADO feeds is called onnxruntime-training-cpu
|
|
|
|
|
package_name = "onnxruntime-training-cpu"
|
2021-04-24 00:22:31 +00:00
|
|
|
|
2023-10-07 02:45:35 +00:00
|
|
|
if rocm_version:
|
|
|
|
|
# Training ROCM package for ADO feeds is called onnxruntime-training-rocm
|
|
|
|
|
package_name = "onnxruntime-training-rocm"
|
|
|
|
|
|
2022-04-26 16:35:16 +00:00
|
|
|
if package_name == "onnxruntime-tvm":
|
|
|
|
|
packages += ["onnxruntime.providers.tvm"]
|
2021-12-16 00:59:20 +00:00
|
|
|
|
2020-04-23 20:27:22 +00:00
|
|
|
package_data["onnxruntime"] = data + examples + extra
|
2019-04-12 05:06:18 +00:00
|
|
|
|
2022-04-26 16:35:16 +00:00
|
|
|
version_number = ""
|
|
|
|
|
with open("VERSION_NUMBER") as f:
|
2019-03-21 20:44:13 +00:00
|
|
|
version_number = f.readline().strip()
|
2019-04-12 05:06:18 +00:00
|
|
|
if nightly_build:
|
2021-04-13 23:19:42 +00:00
|
|
|
# https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables
|
2022-04-26 16:35:16 +00:00
|
|
|
build_suffix = environ.get("BUILD_BUILDNUMBER")
|
2020-04-14 16:00:13 +00:00
|
|
|
if build_suffix is None:
|
2021-04-13 23:19:42 +00:00
|
|
|
# The following line is only for local testing
|
|
|
|
|
build_suffix = str(datetime.datetime.now().date().strftime("%Y%m%d"))
|
2020-01-02 23:43:40 +00:00
|
|
|
else:
|
2022-04-26 16:35:16 +00:00
|
|
|
build_suffix = build_suffix.replace(".", "")
|
2021-04-13 23:19:42 +00:00
|
|
|
|
2021-08-06 23:44:51 +00:00
|
|
|
if len(build_suffix) > 8 and len(build_suffix) < 12:
|
|
|
|
|
# we want to format the build_suffix to avoid (the 12th run on 20210630 vs the first run on 20210701):
|
|
|
|
|
# 2021063012 > 202107011
|
|
|
|
|
# in above 2021063012 is treated as the latest which is incorrect.
|
|
|
|
|
# we want to convert the format to:
|
|
|
|
|
# 20210630012 < 20210701001
|
|
|
|
|
# where the first 8 digits are date. the last 3 digits are run count.
|
|
|
|
|
# as long as there are less than 1000 runs per day, we will not have the problem.
|
|
|
|
|
# to test this code locally, run:
|
|
|
|
|
# NIGHTLY_BUILD=1 BUILD_BUILDNUMBER=202107011 python tools/ci_build/build.py --config RelWithDebInfo \
|
|
|
|
|
# --enable_training --use_cuda --cuda_home /usr/local/cuda --cudnn_home /usr/lib/x86_64-linux-gnu/ \
|
|
|
|
|
# --nccl_home /usr/lib/x86_64-linux-gnu/ --build_dir build/Linux --build --build_wheel --skip_tests \
|
|
|
|
|
# --cuda_version 11.1
|
|
|
|
|
def check_date_format(date_str):
|
|
|
|
|
try:
|
2022-04-26 16:35:16 +00:00
|
|
|
datetime.datetime.strptime(date_str, "%Y%m%d")
|
2021-08-06 23:44:51 +00:00
|
|
|
return True
|
2023-03-24 22:29:03 +00:00
|
|
|
except Exception:
|
2021-08-06 23:44:51 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def reformat_run_count(count_str):
|
|
|
|
|
try:
|
|
|
|
|
count = int(count_str)
|
|
|
|
|
if count >= 0 and count < 1000:
|
2023-03-24 22:29:03 +00:00
|
|
|
return f"{count:03}"
|
2021-08-06 23:44:51 +00:00
|
|
|
elif count >= 1000:
|
2022-04-26 16:35:16 +00:00
|
|
|
raise RuntimeError(f"Too many builds for the same day: {count}")
|
2021-08-06 23:44:51 +00:00
|
|
|
return ""
|
2023-03-24 22:29:03 +00:00
|
|
|
except Exception:
|
2021-08-06 23:44:51 +00:00
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
build_suffix_is_date_format = check_date_format(build_suffix[:8])
|
|
|
|
|
build_suffix_run_count = reformat_run_count(build_suffix[8:])
|
|
|
|
|
if build_suffix_is_date_format and build_suffix_run_count:
|
|
|
|
|
build_suffix = build_suffix[:8] + build_suffix_run_count
|
|
|
|
|
elif len(build_suffix) >= 12:
|
2021-08-09 17:37:05 +00:00
|
|
|
raise RuntimeError(f'Incorrect build suffix: "{build_suffix}"')
|
2021-08-06 23:44:51 +00:00
|
|
|
|
2021-04-13 23:19:42 +00:00
|
|
|
if enable_training:
|
|
|
|
|
from packaging import version
|
|
|
|
|
from packaging.version import Version
|
2022-04-26 16:35:16 +00:00
|
|
|
|
2021-04-13 23:19:42 +00:00
|
|
|
# with training package, we need to bump up version minor number so that
|
|
|
|
|
# nightly releases take precedence over the latest release when --pre is used during pip install.
|
|
|
|
|
# eventually this shall be the behavior of all onnxruntime releases.
|
|
|
|
|
# alternatively we may bump up version number right after every release.
|
|
|
|
|
ort_version = version.parse(version_number)
|
|
|
|
|
if isinstance(ort_version, Version):
|
2021-06-25 21:55:49 +00:00
|
|
|
# TODO: this is the last time we have to do this!!!
|
|
|
|
|
# We shall bump up release number right after release cut.
|
|
|
|
|
if ort_version.major == 1 and ort_version.minor == 8 and ort_version.micro == 0:
|
2024-03-13 17:00:32 +00:00
|
|
|
version_number = f"{ort_version.major}.{ort_version.minor + 1}.{ort_version.micro}"
|
2020-04-14 16:00:13 +00:00
|
|
|
|
|
|
|
|
version_number = version_number + ".dev" + build_suffix
|
|
|
|
|
|
2021-04-13 23:19:42 +00:00
|
|
|
if local_version:
|
|
|
|
|
version_number = version_number + local_version
|
2022-10-17 02:11:20 +00:00
|
|
|
if is_rocm and enable_rocm_profiling:
|
|
|
|
|
version_number = version_number + ".profiling"
|
2021-04-13 23:19:42 +00:00
|
|
|
|
2020-04-14 16:00:13 +00:00
|
|
|
if wheel_name_suffix:
|
2022-04-26 16:35:16 +00:00
|
|
|
if not (enable_training and wheel_name_suffix == "gpu"):
|
2021-06-25 21:55:49 +00:00
|
|
|
# for training packages, local version is used to indicate device types
|
2023-03-24 22:29:03 +00:00
|
|
|
package_name = f"{package_name}-{wheel_name_suffix}"
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2019-11-27 21:03:23 +00:00
|
|
|
cmd_classes = {}
|
2021-04-13 23:19:42 +00:00
|
|
|
if bdist_wheel is not None:
|
2022-04-26 16:35:16 +00:00
|
|
|
cmd_classes["bdist_wheel"] = bdist_wheel
|
2022-06-17 21:49:04 +00:00
|
|
|
cmd_classes["install"] = InstallCommand
|
2022-04-26 16:35:16 +00:00
|
|
|
cmd_classes["build_ext"] = build_ext
|
2019-11-27 21:03:23 +00:00
|
|
|
|
2021-03-24 01:43:19 +00:00
|
|
|
requirements_path = path.join(getcwd(), requirements_file)
|
2020-04-13 22:45:27 +00:00
|
|
|
if not path.exists(requirements_path):
|
|
|
|
|
this = path.dirname(__file__)
|
2021-03-24 01:43:19 +00:00
|
|
|
requirements_path = path.join(this, requirements_file)
|
2020-04-13 22:45:27 +00:00
|
|
|
if not path.exists(requirements_path):
|
2021-03-24 01:43:19 +00:00
|
|
|
raise FileNotFoundError("Unable to find " + requirements_file)
|
2020-04-13 22:45:27 +00:00
|
|
|
with open(requirements_path) as f:
|
2020-04-13 01:44:21 +00:00
|
|
|
install_requires = f.read().splitlines()
|
|
|
|
|
|
2021-06-03 06:36:49 +00:00
|
|
|
|
2021-05-14 16:54:19 +00:00
|
|
|
if enable_training:
|
2022-04-26 16:35:16 +00:00
|
|
|
|
2021-06-30 20:52:22 +00:00
|
|
|
def save_build_and_package_info(package_name, version_number, cuda_version, rocm_version):
|
2022-04-26 16:35:16 +00:00
|
|
|
sys.path.append(path.join(path.dirname(__file__), "onnxruntime", "python"))
|
2021-05-14 16:54:19 +00:00
|
|
|
from onnxruntime_collect_build_info import find_cudart_versions
|
|
|
|
|
|
2022-04-26 16:35:16 +00:00
|
|
|
version_path = path.join("onnxruntime", "capi", "build_and_package_info.py")
|
|
|
|
|
with open(version_path, "w") as f:
|
2023-03-24 22:29:03 +00:00
|
|
|
f.write(f"package_name = '{package_name}'\n")
|
|
|
|
|
f.write(f"__version__ = '{version_number}'\n")
|
2021-05-14 16:54:19 +00:00
|
|
|
|
|
|
|
|
if cuda_version:
|
2023-03-24 22:29:03 +00:00
|
|
|
f.write(f"cuda_version = '{cuda_version}'\n")
|
2021-05-14 16:54:19 +00:00
|
|
|
|
|
|
|
|
# cudart_versions are integers
|
|
|
|
|
cudart_versions = find_cudart_versions(build_env=True)
|
2021-05-22 23:53:15 +00:00
|
|
|
if cudart_versions and len(cudart_versions) == 1:
|
2023-03-24 22:29:03 +00:00
|
|
|
f.write(f"cudart_version = {cudart_versions[0]}\n")
|
2021-05-14 16:54:19 +00:00
|
|
|
else:
|
|
|
|
|
print(
|
|
|
|
|
"Error getting cudart version. ",
|
2024-03-13 17:00:32 +00:00
|
|
|
(
|
|
|
|
|
"did not find any cudart library"
|
|
|
|
|
if not cudart_versions or len(cudart_versions) == 0
|
|
|
|
|
else "found multiple cudart libraries"
|
|
|
|
|
),
|
2022-04-26 16:35:16 +00:00
|
|
|
)
|
2021-06-30 20:52:22 +00:00
|
|
|
elif rocm_version:
|
2023-03-24 22:29:03 +00:00
|
|
|
f.write(f"rocm_version = '{rocm_version}'\n")
|
2021-05-14 16:54:19 +00:00
|
|
|
|
2021-06-30 20:52:22 +00:00
|
|
|
save_build_and_package_info(package_name, version_number, cuda_version, rocm_version)
|
2021-05-14 16:54:19 +00:00
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
# Setup
|
|
|
|
|
setup(
|
|
|
|
|
name=package_name,
|
2019-03-21 20:44:13 +00:00
|
|
|
version=version_number,
|
2022-04-26 16:35:16 +00:00
|
|
|
description="ONNX Runtime is a runtime accelerator for Machine Learning models",
|
2018-11-20 00:48:22 +00:00
|
|
|
long_description=long_description,
|
2022-04-26 16:35:16 +00:00
|
|
|
author="Microsoft Corporation",
|
|
|
|
|
author_email="onnxruntime@microsoft.com",
|
2019-11-27 21:03:23 +00:00
|
|
|
cmdclass=cmd_classes,
|
2018-11-20 00:48:22 +00:00
|
|
|
license="MIT License",
|
2020-04-23 20:27:22 +00:00
|
|
|
packages=packages,
|
2019-06-27 22:45:06 +00:00
|
|
|
ext_modules=ext_modules,
|
2020-04-23 20:27:22 +00:00
|
|
|
package_data=package_data,
|
2021-01-28 03:27:37 +00:00
|
|
|
url="https://onnxruntime.ai",
|
2022-04-26 16:35:16 +00:00
|
|
|
download_url="https://github.com/microsoft/onnxruntime/tags",
|
2020-04-23 20:27:22 +00:00
|
|
|
data_files=data_files,
|
2020-04-13 01:44:21 +00:00
|
|
|
install_requires=install_requires,
|
2022-04-26 16:35:16 +00:00
|
|
|
keywords="onnx machine learning",
|
2021-08-09 17:37:05 +00:00
|
|
|
entry_points={
|
2022-04-26 16:35:16 +00:00
|
|
|
"console_scripts": [
|
|
|
|
|
"onnxruntime_test = onnxruntime.tools.onnxruntime_test:main",
|
2018-11-20 00:48:22 +00:00
|
|
|
]
|
|
|
|
|
},
|
2021-08-20 15:53:25 +00:00
|
|
|
classifiers=classifiers,
|
2022-04-26 16:35:16 +00:00
|
|
|
)
|