From d1ab94c2b0697c0268abca1f096f641675dc3b07 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Thu, 27 Jun 2024 13:50:53 -0700 Subject: [PATCH] Add compatibility for NumPy 2.0 (#21085) ### Description As suggested by SciPy's doc, we will `Build against NumPy 2.0.0, then it will work for all NumPy versions with the same major version number (NumPy does maintain backwards ABI compatibility), and as far back as NumPy 1.19 series at the time of writing` I think it works because in [numpyconfig.h#L64](https://github.com/numpy/numpy/blob/main/numpy/_core/include/numpy/numpyconfig.h#L64) there is a macro NPY_FEATURE_VERSION. By default it is set to NPY_1_19_API_VERSION. And the NPY_FEATURE_VERSION macro controls ABI. This PR only upgrade the build time dependency; When a user installs ONNX Runtime, they still can use numpy 1.x. ### Motivation and Context Recently numpy published a new version, 2.0.0, which is incompatible with the latest ONNX Runtime release. --- cmake/CMakeLists.txt | 12 +++---- cmake/onnxruntime_python.cmake | 3 ++ onnxruntime/test/onnx/gen_test_models.py | 2 +- .../python/quantization/test_quant_util.py | 32 +++++++++++-------- .../test_quantizeblockwise_bnb4.py | 6 ++-- requirements.txt.in => requirements.txt | 2 +- .../py-packaging-selectable-stage.yml | 22 ------------- .../templates/py-packaging-stage.yml | 11 ------- .../azure-pipelines/templates/py-win-gpu.yml | 14 -------- .../templates/py-win-x64-qnn.yml | 11 ------- .../python/cpu/scripts/requirements.txt | 5 ++- .../python/cpu/scripts/requirements.txt | 5 ++- .../python/cuda/scripts/requirements.txt | 5 ++- .../docker/scripts/lort/requirements.txt | 3 +- .../docker/scripts/manylinux/requirements.txt | 5 ++- .../linux/docker/scripts/requirements.txt | 5 ++- .../stage1/requirements_rocm/requirements.txt | 5 ++- .../stage1/torch_eager_cpu/requirements.txt | 3 +- .../ortmodule/stage2/requirements.txt | 5 ++- .../linux/test_custom_ops_pytorch_export.sh | 2 +- .../github/windows/eager/requirements.txt | 3 +- tools/ci_build/github/windows/helpers.ps1 | 8 +++-- 22 files changed, 56 insertions(+), 113 deletions(-) rename requirements.txt.in => requirements.txt (60%) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 9670dcb97abb2..6ba0db789965c 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -579,6 +579,10 @@ if (onnxruntime_BUILD_SHARED_LIB OR onnxruntime_ENABLE_PYTHON) else() find_package(Python 3.8 COMPONENTS Interpreter Development.Module NumPy) endif() + message("Numpy version: ${Python_NumPy_VERSION}") + if(Python_NumPy_VERSION VERSION_LESS "2.0.0") + message(WARNING "The build binary will not be compatible with NumPy 2.0 because the NumPy installed on this machine is too low.") + endif() else() find_package(Python 3.8 COMPONENTS Interpreter) endif() @@ -1406,14 +1410,6 @@ string(APPEND ORT_BUILD_INFO "build type=${CMAKE_BUILD_TYPE}") string(APPEND ORT_BUILD_INFO ", cmake cxx flags: ${CMAKE_CXX_FLAGS}") configure_file(onnxruntime_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/onnxruntime_config.h) get_property(onnxruntime_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) -if (onnxruntime_GENERATOR_IS_MULTI_CONFIG) - configure_file(../requirements.txt.in ${CMAKE_CURRENT_BINARY_DIR}/Debug/requirements.txt) - configure_file(../requirements.txt.in ${CMAKE_CURRENT_BINARY_DIR}/Release/requirements.txt) - configure_file(../requirements.txt.in ${CMAKE_CURRENT_BINARY_DIR}/RelWithDebInfo/requirements.txt) - configure_file(../requirements.txt.in ${CMAKE_CURRENT_BINARY_DIR}/MinSizeRel/requirements.txt) -else() - configure_file(../requirements.txt.in ${CMAKE_CURRENT_BINARY_DIR}/requirements.txt) -endif() if (onnxruntime_USE_CUDA) set(CMAKE_CUDA_RUNTIME_LIBRARY Shared) diff --git a/cmake/onnxruntime_python.cmake b/cmake/onnxruntime_python.cmake index 3c2833d87d652..062cc8f9dbff3 100644 --- a/cmake/onnxruntime_python.cmake +++ b/cmake/onnxruntime_python.cmake @@ -562,6 +562,9 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E copy ${ONNXRUNTIME_ROOT}/__init__.py $/onnxruntime/ + COMMAND ${CMAKE_COMMAND} -E copy + ${REPO_ROOT}/requirements.txt + $ COMMAND ${CMAKE_COMMAND} -E copy ${REPO_ROOT}/ThirdPartyNotices.txt $/onnxruntime/ diff --git a/onnxruntime/test/onnx/gen_test_models.py b/onnxruntime/test/onnx/gen_test_models.py index 1a64df2936810..a5224925251cf 100644 --- a/onnxruntime/test/onnx/gen_test_models.py +++ b/onnxruntime/test/onnx/gen_test_models.py @@ -144,7 +144,7 @@ def test_abs(output_dir): ) generate_abs_op_test( TensorProto.UINT16, - np.uint16([-32767, -4, 0, 3, 32767]), + np.uint16([0, 3, 32767, 65535]), os.path.join(output_dir, "test_abs_uint16"), ) generate_abs_op_test( diff --git a/onnxruntime/test/python/quantization/test_quant_util.py b/onnxruntime/test/python/quantization/test_quant_util.py index 7b3fc08982ac1..96d841654adbd 100644 --- a/onnxruntime/test/python/quantization/test_quant_util.py +++ b/onnxruntime/test/python/quantization/test_quant_util.py @@ -37,41 +37,45 @@ def _compute_scale_zp(rmin, rmax, qmin, qmax, qtype, symmetric=False, min_real_r assert isinstance(scale, numpy.ndarray) return [float(zp), float(scale)] - self.assertEqual(_compute_scale_zp(0.0, 0.0, -127, 127, numpy.int8, symmetric=True), [0, 1.0]) - self.assertEqual(_compute_scale_zp(1.0, -1.0, -127, 127, numpy.int8, symmetric=True), [0, 1.0]) - self.assertEqual(_compute_scale_zp(0.0, 0.0, 0, 255, numpy.uint8, symmetric=True), [0, 1.0]) - self.assertEqual(_compute_scale_zp(1.0, -1.0, 0, 255, numpy.uint8, symmetric=True), [0, 1.0]) + numpy.testing.assert_allclose(_compute_scale_zp(0.0, 0.0, -127, 127, numpy.int8, symmetric=True), [0, 1.0]) + numpy.testing.assert_allclose(_compute_scale_zp(1.0, -1.0, -127, 127, numpy.int8, symmetric=True), [0, 1.0]) + numpy.testing.assert_allclose(_compute_scale_zp(0.0, 0.0, 0, 255, numpy.uint8, symmetric=True), [0, 1.0]) + numpy.testing.assert_allclose(_compute_scale_zp(1.0, -1.0, 0, 255, numpy.uint8, symmetric=True), [0, 1.0]) - self.assertEqual( + numpy.testing.assert_allclose( _compute_scale_zp(-1.0, 2.0, -127, 127, numpy.int8, symmetric=True), [0, numpy.float32(2.0 / 127)] ) - self.assertEqual( + numpy.testing.assert_allclose( _compute_scale_zp(-1.0, 2.0, -127, 127, numpy.int8, symmetric=False), [-42, numpy.float32(3.0 / 254)] ) - self.assertEqual( + numpy.testing.assert_allclose( _compute_scale_zp(-1.0, 2.0, 0, 255, numpy.uint8, symmetric=True), [128, numpy.float32(4.0 / 255)] ) - self.assertEqual( + numpy.testing.assert_allclose( _compute_scale_zp(-1.0, 2.0, 0, 255, numpy.uint8, symmetric=False), [85, numpy.float32(3.0 / 255)] ) tiny_float = numpy.float32(numpy.finfo(numpy.float32).tiny * 0.1) - self.assertEqual(_compute_scale_zp(-tiny_float, tiny_float, 0, 255, numpy.uint8, symmetric=True), [0, 1.0]) - self.assertEqual(_compute_scale_zp(-tiny_float, 0.0, 0, 255, numpy.uint8, symmetric=False), [0, 1.0]) + numpy.testing.assert_allclose( + _compute_scale_zp(-tiny_float, tiny_float, 0, 255, numpy.uint8, symmetric=True), [0, 1.0] + ) + numpy.testing.assert_allclose( + _compute_scale_zp(-tiny_float, 0.0, 0, 255, numpy.uint8, symmetric=False), [0, 1.0] + ) # Test enforcing a minimum floatint-point range. - self.assertEqual( + numpy.testing.assert_allclose( _compute_scale_zp(0.0, 0.0, 0, 255, numpy.uint8, symmetric=False, min_real_range=0.0001), [0, 0.0001 / 255] ) - self.assertEqual( + numpy.testing.assert_allclose( _compute_scale_zp(0.0, 0.0, -128, 127, numpy.int8, symmetric=True, min_real_range=0.0001), [0, 0.0002 / 255] ) - self.assertEqual( + numpy.testing.assert_allclose( _compute_scale_zp(0.0, 0.0, 0, 65535, numpy.uint16, symmetric=False, min_real_range=0.0001), [0, 0.0001 / 65535], ) - self.assertEqual( + numpy.testing.assert_allclose( _compute_scale_zp(0.0, 0.0, -32768, 32767, numpy.int16, symmetric=True, min_real_range=0.0001), [0, 0.0002 / 65535], ) diff --git a/onnxruntime/test/python/quantization/test_quantizeblockwise_bnb4.py b/onnxruntime/test/python/quantization/test_quantizeblockwise_bnb4.py index 9e9d05fae027d..eafab0c03a951 100644 --- a/onnxruntime/test/python/quantization/test_quantizeblockwise_bnb4.py +++ b/onnxruntime/test/python/quantization/test_quantizeblockwise_bnb4.py @@ -87,7 +87,7 @@ def quantize_blockwise_bnb4_ref(matrix_float: npt.ArrayLike, block_size: int, qu absmax[block_idx] = block_absmax if block_len % 2 != 0: - block = np.append(block, 0.0) + block = np.append(block, np.float32(0.0)) block_len += 1 block *= reciprocal_absmax @@ -131,8 +131,8 @@ def test_quantize_blockwise_bnb4(self): matrix_float = np.random.uniform(-1, 1, (k, n)).astype(type) quant_value_ref, absmax_ref = quantize_blockwise_bnb4_ref(matrix_float, block_size, quant_type) quant_value, absmax = quantize_blockwise_bnb4_target(matrix_float, block_size, quant_type) - assert np.allclose(quant_value_ref, quant_value) - assert np.allclose(absmax_ref, absmax) + np.testing.assert_allclose(quant_value_ref, quant_value) + np.testing.assert_allclose(absmax_ref, absmax) if __name__ == "__main__": diff --git a/requirements.txt.in b/requirements.txt similarity index 60% rename from requirements.txt.in rename to requirements.txt index 89242061fb119..2fd9362c949dd 100644 --- a/requirements.txt.in +++ b/requirements.txt @@ -1,6 +1,6 @@ coloredlogs flatbuffers -numpy >= @Python_NumPy_VERSION@ +numpy >= 1.21.6 packaging protobuf sympy diff --git a/tools/ci_build/github/azure-pipelines/templates/py-packaging-selectable-stage.yml b/tools/ci_build/github/azure-pipelines/templates/py-packaging-selectable-stage.yml index cc07df59da619..3f1c4ef0f8d61 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-packaging-selectable-stage.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-packaging-selectable-stage.yml @@ -152,17 +152,6 @@ stages: filename: 'C:\Program Files\Intel\openvino_2021.4.752\bin\setupvars.bat' modifyEnvironment: true - - task: PythonScript@0 - inputs: - scriptSource: inline - script: | - import sys - np_version = 'numpy==1.21.6' if sys.version_info < (3, 11) else 'numpy==1.24.2' - import subprocess - subprocess.call(['pip', 'install', '-q', 'setuptools', 'wheel', np_version]) - workingDirectory: '$(Build.BinariesDirectory)' - displayName: 'Install python modules' - - task: PowerShell@2 displayName: 'Install ONNX' inputs: @@ -419,17 +408,6 @@ stages: modifyEnvironment: true workingFolder: '$(Build.BinariesDirectory)' - - task: PythonScript@0 - inputs: - scriptSource: inline - script: | - import sys - np_version = 'numpy==1.21.6' if sys.version_info < (3, 11) else 'numpy==1.24.2' - import subprocess - subprocess.call(['pip', 'install', '-q', 'setuptools', 'wheel', np_version]) - workingDirectory: '$(Build.BinariesDirectory)' - displayName: 'Install python modules' - - task: PowerShell@2 displayName: 'Install ONNX' inputs: diff --git a/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml b/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml index 588ffca30c262..9e14789f3b234 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml @@ -153,17 +153,6 @@ stages: modifyEnvironment: true workingFolder: '$(Build.BinariesDirectory)' - - task: PythonScript@0 - inputs: - scriptSource: inline - script: | - import sys - np_version = 'numpy==1.21.6' if sys.version_info < (3, 11) else 'numpy==1.24.2' - import subprocess - subprocess.call(['pip', 'install', '-q', 'setuptools', 'wheel', np_version]) - workingDirectory: '$(Build.BinariesDirectory)' - displayName: 'Install python modules' - - template: download-deps.yml - task: PythonScript@0 diff --git a/tools/ci_build/github/azure-pipelines/templates/py-win-gpu.yml b/tools/ci_build/github/azure-pipelines/templates/py-win-gpu.yml index c7a74a7f0e9c7..e89227d51de32 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-win-gpu.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-win-gpu.yml @@ -89,20 +89,6 @@ stages: tsaConfigFilePath: '$(Build.SourcesDirectory)\.config\tsaoptions.json' appendSourceBranchName: false - - task: PythonScript@0 - inputs: - scriptSource: inline - script: | - import sys - np_version = 'numpy==1.21.6' if sys.version_info < (3, 11) else 'numpy==1.26' - import subprocess - try: - subprocess.check_call(['pip', 'install', '-q', 'setuptools', 'wheel', np_version]) - except subprocess.CalledProcessError: - sys.exit(1) - workingDirectory: '$(Build.BinariesDirectory)' - displayName: 'Install python modules' - - template: download-deps.yml - ${{ if ne(parameters.ENV_SETUP_SCRIPT, '') }}: diff --git a/tools/ci_build/github/azure-pipelines/templates/py-win-x64-qnn.yml b/tools/ci_build/github/azure-pipelines/templates/py-win-x64-qnn.yml index 0d1d3c5ced400..884e6eafee965 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-win-x64-qnn.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-win-x64-qnn.yml @@ -60,17 +60,6 @@ jobs: tsaConfigFilePath: '$(Build.SourcesDirectory)\.config\tsaoptions.json' appendSourceBranchName: false - - task: PythonScript@0 - inputs: - scriptSource: inline - script: | - import sys - np_version = 'numpy==1.21.6' if sys.version_info < (3, 11) else 'numpy==1.24.2' - import subprocess - subprocess.call(['pip', 'install', '-q', 'setuptools', 'wheel', np_version]) - workingDirectory: '$(Build.BinariesDirectory)' - displayName: 'Install python modules' - - template: download-deps.yml - task: PythonScript@0 diff --git a/tools/ci_build/github/linux/docker/inference/aarch64/python/cpu/scripts/requirements.txt b/tools/ci_build/github/linux/docker/inference/aarch64/python/cpu/scripts/requirements.txt index cc47718f78a46..a977ccae1922f 100644 --- a/tools/ci_build/github/linux/docker/inference/aarch64/python/cpu/scripts/requirements.txt +++ b/tools/ci_build/github/linux/docker/inference/aarch64/python/cpu/scripts/requirements.txt @@ -1,6 +1,5 @@ -numpy==1.21.6 ; python_version < '3.11' -numpy==1.24.2 ; python_version == '3.11' -numpy==1.26.0 ; python_version >= '3.12' +numpy==1.21.6 ; python_version < '3.9' +numpy==2.0.0 ; python_version >= '3.9' mypy pytest setuptools>=68.2.2 diff --git a/tools/ci_build/github/linux/docker/inference/x86_64/python/cpu/scripts/requirements.txt b/tools/ci_build/github/linux/docker/inference/x86_64/python/cpu/scripts/requirements.txt index cc47718f78a46..a977ccae1922f 100644 --- a/tools/ci_build/github/linux/docker/inference/x86_64/python/cpu/scripts/requirements.txt +++ b/tools/ci_build/github/linux/docker/inference/x86_64/python/cpu/scripts/requirements.txt @@ -1,6 +1,5 @@ -numpy==1.21.6 ; python_version < '3.11' -numpy==1.24.2 ; python_version == '3.11' -numpy==1.26.0 ; python_version >= '3.12' +numpy==1.21.6 ; python_version < '3.9' +numpy==2.0.0 ; python_version >= '3.9' mypy pytest setuptools>=68.2.2 diff --git a/tools/ci_build/github/linux/docker/inference/x86_64/python/cuda/scripts/requirements.txt b/tools/ci_build/github/linux/docker/inference/x86_64/python/cuda/scripts/requirements.txt index cc47718f78a46..a977ccae1922f 100644 --- a/tools/ci_build/github/linux/docker/inference/x86_64/python/cuda/scripts/requirements.txt +++ b/tools/ci_build/github/linux/docker/inference/x86_64/python/cuda/scripts/requirements.txt @@ -1,6 +1,5 @@ -numpy==1.21.6 ; python_version < '3.11' -numpy==1.24.2 ; python_version == '3.11' -numpy==1.26.0 ; python_version >= '3.12' +numpy==1.21.6 ; python_version < '3.9' +numpy==2.0.0 ; python_version >= '3.9' mypy pytest setuptools>=68.2.2 diff --git a/tools/ci_build/github/linux/docker/scripts/lort/requirements.txt b/tools/ci_build/github/linux/docker/scripts/lort/requirements.txt index e9b222fe09711..d76a4337e7487 100644 --- a/tools/ci_build/github/linux/docker/scripts/lort/requirements.txt +++ b/tools/ci_build/github/linux/docker/scripts/lort/requirements.txt @@ -8,7 +8,8 @@ onnx==1.16.1 astunparse expecttest!=0.2.0 hypothesis -numpy +numpy==1.21.6 ; python_version < '3.9' +numpy==2.0.0 ; python_version >= '3.9' psutil pyyaml requests diff --git a/tools/ci_build/github/linux/docker/scripts/manylinux/requirements.txt b/tools/ci_build/github/linux/docker/scripts/manylinux/requirements.txt index bdae9d72a1a63..12db3bd132bb7 100644 --- a/tools/ci_build/github/linux/docker/scripts/manylinux/requirements.txt +++ b/tools/ci_build/github/linux/docker/scripts/manylinux/requirements.txt @@ -1,6 +1,5 @@ -numpy==1.21.6 ; python_version < '3.11' -numpy==1.24.2 ; python_version == '3.11' -numpy==1.26.0 ; python_version >= '3.12' +numpy==1.21.6 ; python_version < '3.9' +numpy==2.0.0 ; python_version >= '3.9' mypy pytest setuptools>=68.2.2 diff --git a/tools/ci_build/github/linux/docker/scripts/requirements.txt b/tools/ci_build/github/linux/docker/scripts/requirements.txt index 3e619ea3dfb56..36af6aa71b075 100644 --- a/tools/ci_build/github/linux/docker/scripts/requirements.txt +++ b/tools/ci_build/github/linux/docker/scripts/requirements.txt @@ -1,7 +1,6 @@ cerberus -numpy==1.21.6 ; python_version < '3.11' -numpy==1.24.2 ; python_version == '3.11' -numpy==1.26.0 ; python_version >= '3.12' +numpy==1.24.4 ; python_version < '3.9' +numpy==2.0.0; python_version >= '3.9' mypy pytest setuptools==69.0.3 diff --git a/tools/ci_build/github/linux/docker/scripts/training/ortmodule/stage1/requirements_rocm/requirements.txt b/tools/ci_build/github/linux/docker/scripts/training/ortmodule/stage1/requirements_rocm/requirements.txt index 57331d6df97d9..89bda11737d10 100644 --- a/tools/ci_build/github/linux/docker/scripts/training/ortmodule/stage1/requirements_rocm/requirements.txt +++ b/tools/ci_build/github/linux/docker/scripts/training/ortmodule/stage1/requirements_rocm/requirements.txt @@ -1,3 +1,2 @@ -numpy==1.21.6 ; python_version < '3.11' -numpy==1.24.2 ; python_version == '3.11' -numpy==1.26.0 ; python_version >= '3.12' \ No newline at end of file +numpy==1.21.6 ; python_version < '3.9' +numpy==2.0.0 ; python_version >= '3.9' diff --git a/tools/ci_build/github/linux/docker/scripts/training/ortmodule/stage1/torch_eager_cpu/requirements.txt b/tools/ci_build/github/linux/docker/scripts/training/ortmodule/stage1/torch_eager_cpu/requirements.txt index 08e251eddbf96..ee4f8bd586804 100644 --- a/tools/ci_build/github/linux/docker/scripts/training/ortmodule/stage1/torch_eager_cpu/requirements.txt +++ b/tools/ci_build/github/linux/docker/scripts/training/ortmodule/stage1/torch_eager_cpu/requirements.txt @@ -5,6 +5,7 @@ setuptools>=68.2.2 cerberus h5py scikit-learn -numpy +numpy==1.21.6 ; python_version < '3.9' +numpy==2.0.0 ; python_version >= '3.9' pandas parameterized diff --git a/tools/ci_build/github/linux/docker/scripts/training/ortmodule/stage2/requirements.txt b/tools/ci_build/github/linux/docker/scripts/training/ortmodule/stage2/requirements.txt index 47f64568f424a..d7fab6a1c8a27 100644 --- a/tools/ci_build/github/linux/docker/scripts/training/ortmodule/stage2/requirements.txt +++ b/tools/ci_build/github/linux/docker/scripts/training/ortmodule/stage2/requirements.txt @@ -1,8 +1,7 @@ pandas scikit-learn -numpy==1.21.6 ; python_version < '3.11' -numpy==1.24.2 ; python_version == '3.11' -numpy==1.26.0 ; python_version >= '3.12' +numpy==1.21.6 ; python_version < '3.9' +numpy==2.0.0 ; python_version >= '3.9' transformers==v4.36.0 accelerate==0.25.0 rsa==4.9 diff --git a/tools/ci_build/github/linux/test_custom_ops_pytorch_export.sh b/tools/ci_build/github/linux/test_custom_ops_pytorch_export.sh index 56f5ff9f9eac0..9cd1222cabfa6 100755 --- a/tools/ci_build/github/linux/test_custom_ops_pytorch_export.sh +++ b/tools/ci_build/github/linux/test_custom_ops_pytorch_export.sh @@ -2,7 +2,7 @@ pip3 install --user --upgrade pip -pip3 install --user numpy==1.19.0 torch pytest +pip3 install --user numpy torch pytest pip3 install --user /build/Release/dist/*.whl export PYTHONPATH=/onnxruntime_src/tools:/usr/local/lib/python3.8/site-packages:$PYTHONPATH diff --git a/tools/ci_build/github/windows/eager/requirements.txt b/tools/ci_build/github/windows/eager/requirements.txt index a820174957185..08e7baa76471b 100644 --- a/tools/ci_build/github/windows/eager/requirements.txt +++ b/tools/ci_build/github/windows/eager/requirements.txt @@ -1,6 +1,7 @@ setuptools wheel -numpy +numpy==1.21.6 ; python_version < '3.9' +numpy==2.0.0 ; python_version >= '3.9' typing_extensions torch==1.13.1 parameterized diff --git a/tools/ci_build/github/windows/helpers.ps1 b/tools/ci_build/github/windows/helpers.ps1 index 0e7d279c9fa49..95a36aa24e904 100644 --- a/tools/ci_build/github/windows/helpers.ps1 +++ b/tools/ci_build/github/windows/helpers.ps1 @@ -635,16 +635,18 @@ function Install-ONNX { if ($lastExitCode -ne 0) { exit $lastExitCode } - + $temp_dir = Get-TempDirectory + $new_requirements_text_file = Join-Path $temp_dir "new_requirements.txt" Write-Host "Installing python packages..." - [string[]]$pip_args = "-m", "pip", "install", "-qq", "--disable-pip-version-check", "setuptools>=68.2.2", "wheel", "numpy", "protobuf==$protobuf_version" + Get-Content "$src_root\tools\ci_build\github\linux\docker\inference\x86_64\python\cpu\scripts\requirements.txt" | Select-String -pattern 'onnx' -notmatch | Out-File $new_requirements_text_file + + [string[]]$pip_args = "-m", "pip", "install", "-qq", "--disable-pip-version-check", "-r", $new_requirements_text_file &"python.exe" $pip_args if ($lastExitCode -ne 0) { exit $lastExitCode } $url=Get-DownloadURL -name onnx -src_root $src_root - $temp_dir = Get-TempDirectory $onnx_src_dir = Join-Path $temp_dir "onnx" $download_finished = DownloadAndExtract -Uri $url -InstallDirectory $onnx_src_dir -Force if(-Not $download_finished){