Skip to content

Commit

Permalink
Adding python3.12 support to ORT (#18814)
Browse files Browse the repository at this point in the history
### Description
Adding python3.12 support to ORT



### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
  • Loading branch information
jchen351 authored Jan 11, 2024
1 parent a89db01 commit 2eb3db6
Show file tree
Hide file tree
Showing 24 changed files with 103 additions and 10 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ def finalize_options(self):
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ stages:
PythonVersion: '3.10'
Python311:
PythonVersion: '3.11'
Python312:
PythonVersion: '3.12'

steps:
- checkout: self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ stages:
EP_NAME: gpu
CudaVersion: ${{ parameters.cuda_version }}

- template: ../templates/py-win-gpu.yml
parameters:
MACHINE_POOL: 'onnxruntime-Win2022-GPU-T4'
PYTHON_VERSION: '3.12'
EP_BUILD_FLAGS: --use_tensorrt --tensorrt_home=${{ variables.win_trt_home }} --cuda_home=${{ variables.win_cuda_home }} --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=52;60;61;70;75;80"
EP_NAME: gpu
CudaVersion: ${{ parameters.cuda_version }}


- ${{ if eq(parameters.enable_linux_gpu, true) }}:
- template: ../templates/py-linux-gpu.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
PythonVersion: '3.10'
Python311:
PythonVersion: '3.11'
Python312:
PythonVersion: '3.12'
steps:
- checkout: none

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ stages:
PythonVersion: '3.11'
MsbuildPlatform: x64
buildArch: x64
Python312_x64:
PythonVersion: '3.12'
MsbuildPlatform: x64
buildArch: x64
# Training build cannot support Win32 for now because one or more of its python
# dependencies does not support Win32. So, don't build a training package for Win32
${{ if not(contains(parameters.build_py_parameters, '--enable_training')) }}:
Expand All @@ -96,6 +100,10 @@ stages:
PythonVersion: '3.11'
MsbuildPlatform: Win32
buildArch: x86
Python312_x86:
PythonVersion: '3.12'
MsbuildPlatform: Win32
buildArch: x86
variables:
OnnxRuntimeBuildDirectory: '$(Build.BinariesDirectory)'
EnvSetupScript: setup_env.bat
Expand Down Expand Up @@ -295,6 +303,14 @@ stages:
ENV_SETUP_SCRIPT: setup_env_gpu.bat
EP_NAME: gpu

- template: py-win-gpu.yml
parameters:
MACHINE_POOL: 'onnxruntime-Win2022-GPU-T4'
PYTHON_VERSION: '3.12'
EP_BUILD_FLAGS: --use_tensorrt --tensorrt_home="C:\local\TensorRT-8.6.1.6.Windows10.x86_64.cuda-11.8" --cuda_home="$(Agent.TempDirectory)\v11.8" --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=52;60;61;70;75;80"
ENV_SETUP_SCRIPT: setup_env_gpu.bat
EP_NAME: gpu

- template: py-win-gpu.yml
parameters:
MACHINE_POOL: 'onnxruntime-Win2022-GPU-dml-A10'
Expand Down Expand Up @@ -327,6 +343,14 @@ stages:
ENV_SETUP_SCRIPT: setup_env.bat
EP_NAME: directml

- template: py-win-gpu.yml
parameters:
MACHINE_POOL: 'onnxruntime-Win2022-GPU-dml-A10'
PYTHON_VERSION: '3.12'
EP_BUILD_FLAGS: --use_dml --cmake_extra_defines CMAKE_SYSTEM_VERSION=10.0.18362.0 --enable_wcos
ENV_SETUP_SCRIPT: setup_env.bat
EP_NAME: directml

- ${{ if eq(parameters.enable_mac_cpu, true) }}:
- job: MacOS_py_Wheels
timeoutInMinutes: 180
Expand All @@ -346,6 +370,8 @@ stages:
PythonVersion: '3.10'
Python311:
PythonVersion: '3.11'
Python312:
PythonVersion: '3.12'
steps:
- checkout: self
clean: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ stages:
OpsetVersion: ${{ parameters.opset_version }}
CudaVersion: ${{ parameters.cuda_version }}
UploadWheel: ${{ parameters.upload_wheel }}
Python312:
PythonVersion: '3.12'
TorchVersion: ${{ parameters.torch_version }}
OpsetVersion: ${{ parameters.opset_version }}
CudaVersion: ${{ parameters.cuda_version }}
UploadWheel: ${{ parameters.upload_wheel }}

steps:
- task: CmdLine@2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ steps:
variables = {
"PythonManylinuxDir": "/opt/python/cp311-cp311"
}
elif version == "3.12":
variables = {
"PythonManylinuxDir": "/opt/python/cp312-cp312"
}
else:
raise ValueError("Unsupported Python version: '{}'".format(version))
Expand Down
2 changes: 1 addition & 1 deletion tools/ci_build/github/linux/build_linux_python_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ EXTRA_ARG=""

# Put 3.8 at the last because Ubuntu 20.04 use python 3.8 and we will upload the intermediate build files of this
# config to Azure DevOps Artifacts and download them to a Ubuntu 20.04 machine to run the tests.
PYTHON_EXES=("/opt/python/cp39-cp39/bin/python3.9" "/opt/python/cp310-cp310/bin/python3.10" "/opt/python/cp311-cp311/bin/python3.11" "/opt/python/cp38-cp38/bin/python3.8")
PYTHON_EXES=("/opt/python/cp39-cp39/bin/python3.9" "/opt/python/cp310-cp310/bin/python3.10" "/opt/python/cp311-cp311/bin/python3.11" "/opt/python/cp312-cp312/bin/python3.12" "/opt/python/cp38-cp38/bin/python3.8")
while getopts "d:p:x:c:" parameter_Option
do case "${parameter_Option}"
in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ FROM build_cpython AS build_cpython311
COPY build_scripts/cpython-pubkey-310-311.txt /build_scripts/cpython-pubkeys.txt
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.11.2

FROM build_cpython AS build_cpython312
COPY build_scripts/cpython-pubkey-312-313.txt /build_scripts/cpython-pubkeys.txt
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.12.1

FROM build_cpython AS all_python
COPY build_scripts/install-pypy.sh \
build_scripts/pypy.sha256 \
Expand All @@ -127,6 +131,7 @@ COPY --from=build_cpython38 /opt/_internal /opt/_internal/
COPY --from=build_cpython39 /opt/_internal /opt/_internal/
COPY --from=build_cpython310 /opt/_internal /opt/_internal/
COPY --from=build_cpython311 /opt/_internal /opt/_internal/
COPY --from=build_cpython312 /opt/_internal /opt/_internal/
RUN manylinux-entrypoint /build_scripts/finalize-python.sh


Expand All @@ -140,6 +145,7 @@ COPY build_scripts/finalize.sh \
build_scripts/requirements3.9.txt \
build_scripts/requirements3.10.txt \
build_scripts/requirements3.11.txt \
build_scripts/requirements3.12.txt \
build_scripts/requirements-base-tools.txt \
/build_scripts/
COPY build_scripts/requirements-tools/* /build_scripts/requirements-tools/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ FROM build_cpython AS build_cpython311
COPY build_scripts/cpython-pubkey-310-311.txt /build_scripts/cpython-pubkeys.txt
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.11.2

FROM build_cpython AS build_cpython312
COPY build_scripts/cpython-pubkey-312-313.txt /build_scripts/cpython-pubkeys.txt
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.12.1

FROM build_cpython AS all_python
COPY build_scripts/install-pypy.sh \
build_scripts/pypy.sha256 \
Expand All @@ -131,6 +135,7 @@ COPY --from=build_cpython38 /opt/_internal /opt/_internal/
COPY --from=build_cpython39 /opt/_internal /opt/_internal/
COPY --from=build_cpython310 /opt/_internal /opt/_internal/
COPY --from=build_cpython311 /opt/_internal /opt/_internal/
COPY --from=build_cpython312 /opt/_internal /opt/_internal/
RUN manylinux-entrypoint /build_scripts/finalize-python.sh

FROM runtime_base
Expand All @@ -143,6 +148,7 @@ COPY build_scripts/finalize.sh \
build_scripts/requirements3.9.txt \
build_scripts/requirements3.10.txt \
build_scripts/requirements3.11.txt \
build_scripts/requirements3.12.txt \
build_scripts/requirements-base-tools.txt \
/build_scripts/
COPY build_scripts/requirements-tools/* /build_scripts/requirements-tools/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ FROM build_cpython AS build_cpython311
COPY build_scripts/cpython-pubkey-310-311.txt /build_scripts/cpython-pubkeys.txt
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.11.2

FROM build_cpython AS build_cpython312
COPY build_scripts/cpython-pubkey-312-313.txt /build_scripts/cpython-pubkeys.txt
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.12.1


FROM build_cpython AS all_python
COPY build_scripts/install-pypy.sh \
Expand All @@ -147,6 +151,7 @@ COPY --from=build_cpython38 /opt/_internal /opt/_internal/
COPY --from=build_cpython39 /opt/_internal /opt/_internal/
COPY --from=build_cpython310 /opt/_internal /opt/_internal/
COPY --from=build_cpython311 /opt/_internal /opt/_internal/
COPY --from=build_cpython312 /opt/_internal /opt/_internal/
RUN manylinux-entrypoint /build_scripts/finalize-python.sh


Expand All @@ -160,6 +165,7 @@ COPY build_scripts/finalize.sh \
build_scripts/requirements3.9.txt \
build_scripts/requirements3.10.txt \
build_scripts/requirements3.11.txt \
build_scripts/requirements3.12.txt \
build_scripts/requirements-base-tools.txt \
/build_scripts/
COPY build_scripts/requirements-tools/* /build_scripts/requirements-tools/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ FROM build_cpython AS build_cpython311
COPY build_scripts/cpython-pubkey-310-311.txt /build_scripts/cpython-pubkeys.txt
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.11.2

FROM build_cpython AS build_cpython312
COPY build_scripts/cpython-pubkey-312-313.txt /build_scripts/cpython-pubkeys.txt
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.12.1

FROM build_cpython AS all_python
COPY build_scripts/install-pypy.sh \
build_scripts/pypy.sha256 \
Expand All @@ -130,6 +134,7 @@ COPY --from=build_cpython38 /opt/_internal /opt/_internal/
COPY --from=build_cpython39 /opt/_internal /opt/_internal/
COPY --from=build_cpython310 /opt/_internal /opt/_internal/
COPY --from=build_cpython311 /opt/_internal /opt/_internal/
COPY --from=build_cpython312 /opt/_internal /opt/_internal/
RUN manylinux-entrypoint /build_scripts/finalize-python.sh


Expand All @@ -143,6 +148,7 @@ COPY build_scripts/finalize.sh \
build_scripts/requirements3.9.txt \
build_scripts/requirements3.10.txt \
build_scripts/requirements3.11.txt \
build_scripts/requirements3.12.txt \
build_scripts/requirements-base-tools.txt \
/build_scripts/
COPY build_scripts/requirements-tools/* /build_scripts/requirements-tools/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ FROM build_cpython AS build_cpython311
COPY build_scripts/cpython-pubkey-310-311.txt /build_scripts/cpython-pubkeys.txt
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.11.2

FROM build_cpython AS build_cpython312
COPY build_scripts/cpython-pubkey-312-313.txt /build_scripts/cpython-pubkeys.txt
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.12.1

FROM build_cpython AS all_python
COPY build_scripts/install-pypy.sh \
build_scripts/pypy.sha256 \
Expand All @@ -130,6 +134,7 @@ COPY --from=build_cpython38 /opt/_internal /opt/_internal/
COPY --from=build_cpython39 /opt/_internal /opt/_internal/
COPY --from=build_cpython310 /opt/_internal /opt/_internal/
COPY --from=build_cpython311 /opt/_internal /opt/_internal/
COPY --from=build_cpython312 /opt/_internal /opt/_internal/
RUN manylinux-entrypoint /build_scripts/finalize-python.sh


Expand All @@ -143,6 +148,7 @@ COPY build_scripts/finalize.sh \
build_scripts/requirements3.9.txt \
build_scripts/requirements3.10.txt \
build_scripts/requirements3.11.txt \
build_scripts/requirements3.12.txt \
build_scripts/requirements-base-tools.txt \
/build_scripts/
COPY build_scripts/requirements-tools/* /build_scripts/requirements-tools/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ FROM build_cpython AS build_cpython311
COPY build_scripts/cpython-pubkey-310-311.txt /build_scripts/cpython-pubkeys.txt
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.11.2

FROM build_cpython AS build_cpython312
COPY build_scripts/cpython-pubkey-312-313.txt /build_scripts/cpython-pubkeys.txt
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.12.1

FROM build_cpython AS all_python
COPY build_scripts/finalize-python.sh \
/build_scripts/
Expand All @@ -122,6 +126,7 @@ COPY --from=build_cpython38 /opt/_internal /opt/_internal/
COPY --from=build_cpython39 /opt/_internal /opt/_internal/
COPY --from=build_cpython310 /opt/_internal /opt/_internal/
COPY --from=build_cpython311 /opt/_internal /opt/_internal/
COPY --from=build_cpython312 /opt/_internal /opt/_internal/
RUN manylinux-entrypoint /build_scripts/finalize-python.sh


Expand All @@ -135,6 +140,7 @@ COPY build_scripts/finalize.sh \
build_scripts/requirements3.9.txt \
build_scripts/requirements3.10.txt \
build_scripts/requirements3.11.txt \
build_scripts/requirements3.12.txt \
build_scripts/requirements-base-tools.txt \
/build_scripts/
COPY build_scripts/requirements-tools/* /build_scripts/requirements-tools/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e -x
pushd .
PYTHON_EXES=("/opt/python/cp38-cp38/bin/python3.8" "/opt/python/cp39-cp39/bin/python3.9" "/opt/python/cp310-cp310/bin/python3.10" "/opt/python/cp311-cp311/bin/python3.11")
PYTHON_EXES=("/opt/python/cp38-cp38/bin/python3.8" "/opt/python/cp39-cp39/bin/python3.9" "/opt/python/cp310-cp310/bin/python3.10" "/opt/python/cp311-cp311/bin/python3.11" "/opt/python/cp312-cp312/bin/python3.12")
CURRENT_DIR=$(pwd)
if ! [ -x "$(command -v protoc)" ]; then
$CURRENT_DIR/install_protobuf.sh
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
numpy==1.21.6 ; python_version < '3.11'
numpy==1.24.2 ; python_version >= '3.11'
numpy==1.24.2 ; python_version == '3.11'
numpy==1.26.0 ; python_version >= '3.12'
mypy
pytest
setuptools>=68.2.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ elif [[ "$PYTHON_VER" = "3.10" && -d "/opt/python/cp310-cp310" ]]; then
PYTHON_EXE="/opt/python/cp310-cp310/bin/python3.10"
elif [[ "$PYTHON_VER" = "3.11" && -d "/opt/python/cp311-cp311" ]]; then
PYTHON_EXE="/opt/python/cp311-cp311/bin/python3.11"
elif [[ "$PYTHON_VER" = "3.12" && -d "/opt/python/cp312-cp312" ]]; then
PYTHON_EXE="/opt/python/cp312-cp312/bin/python3.12"
else
PYTHON_EXE="/usr/bin/python${PYTHON_VER}"
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ PARENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)"
source "$PARENT_DIR/install_dotnet.sh"

if [ ! -d "/opt/conda/bin" ]; then
PYTHON_EXES=("/opt/python/cp38-cp38/bin/python3.8" "/opt/python/cp39-cp39/bin/python3.9" "/opt/python/cp310-cp310/bin/python3.10" "/opt/python/cp311-cp311/bin/python3.11")
PYTHON_EXES=("/opt/python/cp38-cp38/bin/python3.8" "/opt/python/cp39-cp39/bin/python3.9" "/opt/python/cp310-cp310/bin/python3.10" "/opt/python/cp311-cp311/bin/python3.11" "/opt/python/cp312-cp312/bin/python3.12")
else
PYTHON_EXES=("/opt/conda/bin/python")
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ yum -y install \
graphviz

if [ ! -d "/opt/conda/bin" ]; then
PYTHON_EXES=("/opt/python/cp38-cp38/bin/python3.8" "/opt/python/cp39-cp39/bin/python3.9" "/opt/python/cp310-cp310/bin/python3.10" "/opt/python/cp311-cp311/bin/python3.11")
PYTHON_EXES=("/opt/python/cp38-cp38/bin/python3.8" "/opt/python/cp39-cp39/bin/python3.9" "/opt/python/cp310-cp310/bin/python3.10" "/opt/python/cp311-cp311/bin/python3.11" "/opt/python/cp312-cp312/bin/python3.12")
else
PYTHON_EXES=("/opt/conda/bin/python")
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
numpy==1.21.6 ; python_version < '3.11'
numpy==1.24.2 ; python_version >= '3.11'
numpy==1.24.2 ; python_version == '3.11'
numpy==1.26.0 ; python_version >= '3.12'
mypy
pytest
setuptools>=68.2.2
Expand Down
3 changes: 2 additions & 1 deletion tools/ci_build/github/linux/docker/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cerberus
numpy==1.21.6 ; python_version < '3.11'
numpy==1.24.2 ; python_version >= '3.11'
numpy==1.24.2 ; python_version == '3.11'
numpy==1.26.0 ; python_version >= '3.12'
mypy
pytest
setuptools==69.0.3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
numpy==1.21.6 ; python_version < '3.11'
numpy==1.24.2 ; python_version >= '3.11'
numpy==1.24.2 ; python_version == '3.11'
numpy==1.26.0 ; python_version >= '3.12'
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pandas
scikit-learn
numpy==1.21.6 ; python_version < '3.11'
numpy==1.24.2 ; python_version >= '3.11'
numpy==1.24.2 ; python_version == '3.11'
numpy==1.26.0 ; python_version >= '3.12'
transformers==v4.36.0
accelerate==0.25.0
rsa==4.9
Expand Down
3 changes: 2 additions & 1 deletion tools/ci_build/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# packages used by transformers python unittest (only enabled in Linux CPU CI Pipeline)
packaging
protobuf==3.20.2
numpy==1.24.0
numpy==1.24.0 ; python_version < '3.12'
numpy==1.26.0 ; python_version >= '3.12'
coloredlogs==15.0
transformers==4.36.0
psutil
Expand Down

0 comments on commit 2eb3db6

Please sign in to comment.