I am done

This commit is contained in:
2024-10-30 22:14:35 +01:00
parent 720dc28c09
commit 40e2a747cf
36901 changed files with 5011519 additions and 0 deletions

View File

@ -0,0 +1,4 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------

View File

@ -0,0 +1,7 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
# This file can be modified by setup.py when building a manylinux2010 wheel
# When modified, it will preload some libraries needed for the python C extension

View File

@ -0,0 +1,33 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
"""
Ensure that dependencies are available and then load the extension module.
"""
import os
import platform
import warnings
from . import _ld_preload # noqa: F401
if platform.system() == "Windows":
from . import version_info
# If on Windows, check if this import error is caused by the user not installing the 2019 VC Runtime
# The VC Redist installer usually puts the VC Runtime dlls in the System32 folder, but it may also be found
# in some other locations.
# TODO, we may want to try to load the VC Runtime dlls instead of checking if the hardcoded file path
# is valid, and raise ImportError if the load fails
if version_info.vs2019 and platform.architecture()[0] == "64bit":
system_root = os.getenv("SystemRoot") or "C:\\Windows"
if not os.path.isfile(os.path.join(system_root, "System32", "vcruntime140_1.dll")):
warnings.warn("Please install the 2019 Visual C++ runtime and then try again. "
"If you've installed the runtime in a non-standard location "
"(other than %SystemRoot%\\System32), "
"make sure it can be found by setting the correct path.")
from .onnxruntime_pybind11_state import * # noqa

Binary file not shown.

View File

@ -0,0 +1,103 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import ctypes
import sys
import warnings
def find_cudart_versions(build_env=False, build_cuda_version=None):
# ctypes.CDLL and ctypes.util.find_library load the latest installed library.
# it may not the the library that would be loaded by onnxruntime.
# for example, in an environment with Cuda 11.1 and subsequently
# conda cudatoolkit 10.2.89 installed. ctypes will find cudart 10.2. however,
# onnxruntime built with Cuda 11.1 will find and load cudart for Cuda 11.1.
# for the above reason, we need find all versions in the environment and
# only give warnings if the expected cuda version is not found.
# in onnxruntime build environment, we expected only one Cuda version.
if not sys.platform.startswith("linux"):
warnings.warn("find_cudart_versions only works on Linux")
return None
cudart_possible_versions = {None, build_cuda_version}
def get_cudart_version(find_cudart_version=None):
cudart_lib_filename = "libcudart.so"
if find_cudart_version:
cudart_lib_filename = cudart_lib_filename + "." + find_cudart_version
try:
cudart = ctypes.CDLL(cudart_lib_filename)
cudart.cudaRuntimeGetVersion.restype = int
cudart.cudaRuntimeGetVersion.argtypes = [ctypes.POINTER(ctypes.c_int)]
version = ctypes.c_int()
status = cudart.cudaRuntimeGetVersion(ctypes.byref(version))
if status != 0:
return None
except Exception:
return None
return version.value
# use set to avoid duplications
cudart_found_versions = {get_cudart_version(cudart_version) for cudart_version in cudart_possible_versions}
# convert to list and remove None
return [ver for ver in cudart_found_versions if ver]
def find_cudnn_supported_cuda_versions(build_env=False):
# comments in get_cudart_version apply here
if not sys.platform.startswith("linux"):
warnings.warn("find_cudnn_versions only works on Linux")
cudnn_possible_versions = {None}
if not build_env:
# if not in a build environment, there may be more than one installed cudnn.
# https://developer.nvidia.com/rdp/cudnn-archive to include all that may support Cuda 10+.
cudnn_possible_versions.update(
{
"8.2",
"8.1.1",
"8.1.0",
"8.0.5",
"8.0.4",
"8.0.3",
"8.0.2",
"8.0.1",
"7.6.5",
"7.6.4",
"7.6.3",
"7.6.2",
"7.6.1",
"7.6.0",
"7.5.1",
"7.5.0",
"7.4.2",
"7.4.1",
"7.3.1",
"7.3.0",
}
)
def get_cudnn_supported_cuda_version(find_cudnn_version=None):
cudnn_lib_filename = "libcudnn.so"
if find_cudnn_version:
cudnn_lib_filename = cudnn_lib_filename + "." + find_cudnn_version
# in cudnn.h cudnn version are calculated as:
# #define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
try:
cudnn = ctypes.CDLL(cudnn_lib_filename)
# cudnn_ver = cudnn.cudnnGetVersion()
cuda_ver = cudnn.cudnnGetCudartVersion()
return cuda_ver
except Exception:
return None
# use set to avoid duplications
cuda_found_versions = {get_cudnn_supported_cuda_version(cudnn_version) for cudnn_version in cudnn_possible_versions}
# convert to list and remove None
return [ver for ver in cuda_found_versions if ver]

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,144 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
"""
Check OS requirements for ONNX Runtime Python Bindings.
"""
import linecache
import platform
import warnings
def check_distro_info():
__my_distro__ = ""
__my_distro_ver__ = ""
__my_system__ = platform.system().lower()
__OS_RELEASE_FILE__ = "/etc/os-release" # noqa: N806
__LSB_RELEASE_FILE__ = "/etc/lsb-release" # noqa: N806
if __my_system__ == "windows":
__my_distro__ = __my_system__
__my_distro_ver__ = platform.release().lower()
if __my_distro_ver__ not in ["10", "11"]:
warnings.warn(
f"Unsupported Windows version ({__my_distro_ver__}). ONNX Runtime supports Windows 10 and above, only."
)
elif __my_system__ == "linux":
"""Although the 'platform' python module for getting Distro information works well on standard OS images
running on real hardware, it is not accurate when running on Azure VMs, Git Bash, Cygwin, etc.
The returned values for release and version are unpredictable for virtualized or emulated environments.
/etc/os-release and /etc/lsb_release files, on the other hand, are guaranteed to exist and have standard values
in all OSes supported by onnxruntime. The former is the current standard file to check OS info and the latter
is its predecessor.
"""
# Newer systems have /etc/os-release with relevant distro info
__my_distro__ = linecache.getline(__OS_RELEASE_FILE__, 3)[3:-1]
__my_distro_ver__ = linecache.getline(__OS_RELEASE_FILE__, 6)[12:-2]
# Older systems may have /etc/os-release instead
if not __my_distro__:
__my_distro__ = linecache.getline(__LSB_RELEASE_FILE__, 1)[11:-1]
__my_distro_ver__ = linecache.getline(__LSB_RELEASE_FILE__, 2)[16:-1]
# Instead of trying to parse distro specific files,
# warn the user ONNX Runtime may not work out of the box
__my_distro__ = __my_distro__.lower()
__my_distro_ver__ = __my_distro_ver__.lower()
elif __my_system__ == "darwin":
__my_distro__ = __my_system__
__my_distro_ver__ = platform.release().lower()
if int(__my_distro_ver__.split(".")[0]) < 11:
warnings.warn(
f"Unsupported macOS version ({__my_distro_ver__}). ONNX Runtime supports macOS 11.0 or later."
)
else:
warnings.warn(
f"Unsupported platform ({__my_system__}). ONNX Runtime supports Linux, macOS and Windows platforms, only."
)
def validate_build_package_info():
import_ortmodule_exception = None
has_ortmodule = False
try:
from onnxruntime.training.ortmodule import ORTModule # noqa: F401
has_ortmodule = True
except ImportError:
# ORTModule not present
has_ortmodule = False
except Exception as e:
# this may happen if Cuda is not installed, we want to raise it after
# for any exception other than not having ortmodule, we want to continue
# device version validation and raise the exception after.
try:
from onnxruntime.training.ortmodule._fallback import ORTModuleInitException
if isinstance(e, ORTModuleInitException):
# ORTModule is present but not ready to run yet
has_ortmodule = True
except Exception:
# ORTModule not present
has_ortmodule = False
if not has_ortmodule:
import_ortmodule_exception = e
package_name = ""
version = ""
cuda_version = ""
if has_ortmodule:
try:
# collect onnxruntime package name, version, and cuda version
from .build_and_package_info import __version__ as version
from .build_and_package_info import package_name
try: # noqa: SIM105
from .build_and_package_info import cuda_version
except Exception:
pass
if cuda_version:
# collect cuda library build info. the library info may not be available
# when the build environment has none or multiple libraries installed
try:
from .build_and_package_info import cudart_version
except Exception:
warnings.warn("WARNING: failed to get cudart_version from onnxruntime build info.")
cudart_version = None
def print_build_package_info():
warnings.warn(f"onnxruntime training package info: package_name: {package_name}")
warnings.warn(f"onnxruntime training package info: __version__: {version}")
warnings.warn(f"onnxruntime training package info: cuda_version: {cuda_version}")
warnings.warn(f"onnxruntime build info: cudart_version: {cudart_version}")
# collection cuda library info from current environment.
from onnxruntime.capi.onnxruntime_collect_build_info import find_cudart_versions
local_cudart_versions = find_cudart_versions(build_env=False, build_cuda_version=cuda_version)
if cudart_version and local_cudart_versions and cudart_version not in local_cudart_versions:
print_build_package_info()
warnings.warn("WARNING: failed to find cudart version that matches onnxruntime build info")
warnings.warn(f"WARNING: found cudart versions: {local_cudart_versions}")
else:
# TODO: rcom
pass
except Exception as e:
warnings.warn("WARNING: failed to collect onnxruntime version and build info")
print(e)
if import_ortmodule_exception:
raise import_ortmodule_exception
return has_ortmodule, package_name, version, cuda_version
has_ortmodule, package_name, version, cuda_version = validate_build_package_info()

View File

@ -0,0 +1,2 @@
use_cuda = False
vs2019 = False