From d7088c7904473b3f80465a9e1513b0532b9034ab Mon Sep 17 00:00:00 2001 From: Xu Zhao Date: Mon, 17 Jun 2024 18:11:04 -0400 Subject: [PATCH 1/6] Roll numpy version --- utils/cuda_utils.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/utils/cuda_utils.py b/utils/cuda_utils.py index 80f677af1e..85f64e1288 100644 --- a/utils/cuda_utils.py +++ b/utils/cuda_utils.py @@ -5,6 +5,8 @@ import subprocess from pathlib import Path +from .python_utils import DEFAULT_PYTHON_VERSION + from typing import Optional # defines the default CUDA version to compile against @@ -17,11 +19,18 @@ }, } PIN_CMAKE_VERSION = "3.22.*" -# the numpy version needs to be consistent with -# https://github.com/pytorch/builder/blob/e66e48f9b1968213c6a7ce3ca8df6621435f0a9c/wheel/build_wheel.sh#L146 -PIN_NUMPY_VERSION = "1.23.5" + TORCHBENCH_TORCH_NIGHTLY_PACKAGES = ["torch", "torchvision", "torchaudio"] +def _get_pin_numpy_version() -> str: + # the numpy version needs to be consistent with + # https://github.com/pytorch/builder/blob/main/wheel/build_wheel.sh#L146 + RAW_GITHUB_BUILDER_SCRIPT = "https://raw.githubusercontent.com/pytorch/builder/main/wheel/build_wheel.sh" + numpy_version = "2.0.0rc1" + print(f"Pinned NUMPY version: {numpy_version}") + return numpy_version + +PIN_CMAKE_VERSION = _get_pin_numpy_version() def _nvcc_output_match(nvcc_output, target_cuda_version): regex = "release (.*)," From 4f1d61d7876e8c246580b3192b02bf4845673384 Mon Sep 17 00:00:00 2001 From: Xu Zhao Date: Wed, 19 Jun 2024 12:19:38 -0400 Subject: [PATCH 2/6] Hardcode numpy version --- requirements.txt | 4 +++- torchbenchmark/models/Background_Matting/requirements.txt | 2 +- torchbenchmark/models/hf_Whisper/requirements.txt | 3 ++- torchbenchmark/models/tacotron2/requirements.txt | 2 +- torchbenchmark/util/framework/detectron2/requirements.txt | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index b9d52c5b24..8d9f74d3bf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,9 @@ transformers==4.38.1 MonkeyType psutil pyyaml -numpy +# We need to pin numpy version to the same as the torch testing environment +# which still supports python 3.8 +numpy==1.21.2 opencv-python submitit pynvml diff --git a/torchbenchmark/models/Background_Matting/requirements.txt b/torchbenchmark/models/Background_Matting/requirements.txt index 188e465c72..790964e8cd 100644 --- a/torchbenchmark/models/Background_Matting/requirements.txt +++ b/torchbenchmark/models/Background_Matting/requirements.txt @@ -1,4 +1,4 @@ -numpy +numpy==1.21.2 opencv-python pandas Pillow diff --git a/torchbenchmark/models/hf_Whisper/requirements.txt b/torchbenchmark/models/hf_Whisper/requirements.txt index fd0728f16f..fb91cc87b5 100644 --- a/torchbenchmark/models/hf_Whisper/requirements.txt +++ b/torchbenchmark/models/hf_Whisper/requirements.txt @@ -1 +1,2 @@ -numba \ No newline at end of file +numba +numpy==1.21.2 diff --git a/torchbenchmark/models/tacotron2/requirements.txt b/torchbenchmark/models/tacotron2/requirements.txt index 39e8afb167..598a2b11d2 100644 --- a/torchbenchmark/models/tacotron2/requirements.txt +++ b/torchbenchmark/models/tacotron2/requirements.txt @@ -1,4 +1,4 @@ -numpy +numpy==1.21.2 inflect scipy Unidecode diff --git a/torchbenchmark/util/framework/detectron2/requirements.txt b/torchbenchmark/util/framework/detectron2/requirements.txt index f38075ddd7..2a049c08b1 100644 --- a/torchbenchmark/util/framework/detectron2/requirements.txt +++ b/torchbenchmark/util/framework/detectron2/requirements.txt @@ -1,3 +1,3 @@ git+https://github.com/facebookresearch/detectron2.git@0df2d73d0013db7de629602c23cc120219b4f2b8 omegaconf==2.3.0 -numpy +numpy==1.21.2 From 6323b0bac7be80de470d3a242442656e93c09abf Mon Sep 17 00:00:00 2001 From: Xu Zhao Date: Wed, 19 Jun 2024 12:27:11 -0400 Subject: [PATCH 3/6] Read from hardcoded numpy version --- utils/cuda_utils.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/utils/cuda_utils.py b/utils/cuda_utils.py index 85f64e1288..7155b63377 100644 --- a/utils/cuda_utils.py +++ b/utils/cuda_utils.py @@ -5,12 +5,11 @@ import subprocess from pathlib import Path -from .python_utils import DEFAULT_PYTHON_VERSION - from typing import Optional # defines the default CUDA version to compile against DEFAULT_CUDA_VERSION = "12.4" +REPO_ROOT = Path(__file__).parent.parent CUDA_VERSION_MAP = { "12.4": { @@ -23,14 +22,16 @@ TORCHBENCH_TORCH_NIGHTLY_PACKAGES = ["torch", "torchvision", "torchaudio"] def _get_pin_numpy_version() -> str: - # the numpy version needs to be consistent with - # https://github.com/pytorch/builder/blob/main/wheel/build_wheel.sh#L146 - RAW_GITHUB_BUILDER_SCRIPT = "https://raw.githubusercontent.com/pytorch/builder/main/wheel/build_wheel.sh" - numpy_version = "2.0.0rc1" + requirements_file = REPO_ROOT.joinpath("requirements.txt") + numpy_reg = "numpy==(.*)" + with open(requirements_file, "r") as fp: + numpy_requirement = list(filter(lambda x: "numpy==" in x, fp.readlines())) + assert numpy_requirement, f"Expected numpy version hardcoded in {str(requirements_file.resolve())}." + numpy_version = re.match(numpy_reg, numpy_requirement[0]).groups()[0] print(f"Pinned NUMPY version: {numpy_version}") return numpy_version -PIN_CMAKE_VERSION = _get_pin_numpy_version() +PIN_NUMPY_VERSION = _get_pin_numpy_version() def _nvcc_output_match(nvcc_output, target_cuda_version): regex = "release (.*)," From 3f14196bfe62444050c54656922ecd6ce6e30c79 Mon Sep 17 00:00:00 2001 From: Xu Zhao Date: Wed, 19 Jun 2024 12:39:06 -0400 Subject: [PATCH 4/6] Fix numpy version --- requirements.txt | 3 ++- torchbenchmark/models/Background_Matting/requirements.txt | 5 ++++- torchbenchmark/models/hf_Whisper/requirements.txt | 5 ++++- torchbenchmark/models/tacotron2/requirements.txt | 5 ++++- torchbenchmark/util/framework/detectron2/requirements.txt | 5 ++++- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8d9f74d3bf..8939e5dbaf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,7 +17,8 @@ psutil pyyaml # We need to pin numpy version to the same as the torch testing environment # which still supports python 3.8 -numpy==1.21.2 +numpy==1.21.2; python_version < '3.11' +numpy==2.0.0; python_version >= '3.11' opencv-python submitit pynvml diff --git a/torchbenchmark/models/Background_Matting/requirements.txt b/torchbenchmark/models/Background_Matting/requirements.txt index 790964e8cd..4e75912d4a 100644 --- a/torchbenchmark/models/Background_Matting/requirements.txt +++ b/torchbenchmark/models/Background_Matting/requirements.txt @@ -1,4 +1,7 @@ -numpy==1.21.2 +# We need to pin numpy version to the same as the torch testing environment +# which still supports python 3.8 +numpy==1.21.2; python_version < '3.11' +numpy==2.0.0; python_version >= '3.11' opencv-python pandas Pillow diff --git a/torchbenchmark/models/hf_Whisper/requirements.txt b/torchbenchmark/models/hf_Whisper/requirements.txt index fb91cc87b5..a1ee27678f 100644 --- a/torchbenchmark/models/hf_Whisper/requirements.txt +++ b/torchbenchmark/models/hf_Whisper/requirements.txt @@ -1,2 +1,5 @@ numba -numpy==1.21.2 +# We need to pin numpy version to the same as the torch testing environment +# which still supports python 3.8 +numpy==1.21.2; python_version < '3.11' +numpy==2.0.0; python_version >= '3.11' \ No newline at end of file diff --git a/torchbenchmark/models/tacotron2/requirements.txt b/torchbenchmark/models/tacotron2/requirements.txt index 598a2b11d2..5a8afc5a3b 100644 --- a/torchbenchmark/models/tacotron2/requirements.txt +++ b/torchbenchmark/models/tacotron2/requirements.txt @@ -1,4 +1,7 @@ -numpy==1.21.2 +# We need to pin numpy version to the same as the torch testing environment +# which still supports python 3.8 +numpy==1.21.2; python_version < '3.11' +numpy==2.0.0; python_version >= '3.11' inflect scipy Unidecode diff --git a/torchbenchmark/util/framework/detectron2/requirements.txt b/torchbenchmark/util/framework/detectron2/requirements.txt index 2a049c08b1..680223d72f 100644 --- a/torchbenchmark/util/framework/detectron2/requirements.txt +++ b/torchbenchmark/util/framework/detectron2/requirements.txt @@ -1,3 +1,6 @@ git+https://github.com/facebookresearch/detectron2.git@0df2d73d0013db7de629602c23cc120219b4f2b8 omegaconf==2.3.0 -numpy==1.21.2 +# We need to pin numpy version to the same as the torch testing environment +# which still supports python 3.8 +numpy==1.21.2; python_version < '3.11' +numpy==2.0.0; python_version >= '3.11' From c3879482640721e0cef9b02b7c72c24db9a665ea Mon Sep 17 00:00:00 2001 From: Xu Zhao Date: Wed, 19 Jun 2024 12:46:25 -0400 Subject: [PATCH 5/6] Use numpy 1.26.0 --- requirements.txt | 2 +- torchbenchmark/models/Background_Matting/requirements.txt | 2 +- torchbenchmark/models/hf_Whisper/requirements.txt | 2 +- torchbenchmark/models/tacotron2/requirements.txt | 2 +- torchbenchmark/util/framework/detectron2/requirements.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8939e5dbaf..e38ba85136 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,7 @@ pyyaml # We need to pin numpy version to the same as the torch testing environment # which still supports python 3.8 numpy==1.21.2; python_version < '3.11' -numpy==2.0.0; python_version >= '3.11' +numpy==1.26.0; python_version >= '3.11' opencv-python submitit pynvml diff --git a/torchbenchmark/models/Background_Matting/requirements.txt b/torchbenchmark/models/Background_Matting/requirements.txt index 4e75912d4a..3250404275 100644 --- a/torchbenchmark/models/Background_Matting/requirements.txt +++ b/torchbenchmark/models/Background_Matting/requirements.txt @@ -1,7 +1,7 @@ # We need to pin numpy version to the same as the torch testing environment # which still supports python 3.8 numpy==1.21.2; python_version < '3.11' -numpy==2.0.0; python_version >= '3.11' +numpy==1.26.0; python_version >= '3.11' opencv-python pandas Pillow diff --git a/torchbenchmark/models/hf_Whisper/requirements.txt b/torchbenchmark/models/hf_Whisper/requirements.txt index a1ee27678f..461b9ef776 100644 --- a/torchbenchmark/models/hf_Whisper/requirements.txt +++ b/torchbenchmark/models/hf_Whisper/requirements.txt @@ -2,4 +2,4 @@ numba # We need to pin numpy version to the same as the torch testing environment # which still supports python 3.8 numpy==1.21.2; python_version < '3.11' -numpy==2.0.0; python_version >= '3.11' \ No newline at end of file +numpy==1.26.0; python_version >= '3.11' \ No newline at end of file diff --git a/torchbenchmark/models/tacotron2/requirements.txt b/torchbenchmark/models/tacotron2/requirements.txt index 5a8afc5a3b..4f642207d5 100644 --- a/torchbenchmark/models/tacotron2/requirements.txt +++ b/torchbenchmark/models/tacotron2/requirements.txt @@ -1,7 +1,7 @@ # We need to pin numpy version to the same as the torch testing environment # which still supports python 3.8 numpy==1.21.2; python_version < '3.11' -numpy==2.0.0; python_version >= '3.11' +numpy==1.26.0; python_version >= '3.11' inflect scipy Unidecode diff --git a/torchbenchmark/util/framework/detectron2/requirements.txt b/torchbenchmark/util/framework/detectron2/requirements.txt index 680223d72f..acec6a1840 100644 --- a/torchbenchmark/util/framework/detectron2/requirements.txt +++ b/torchbenchmark/util/framework/detectron2/requirements.txt @@ -3,4 +3,4 @@ omegaconf==2.3.0 # We need to pin numpy version to the same as the torch testing environment # which still supports python 3.8 numpy==1.21.2; python_version < '3.11' -numpy==2.0.0; python_version >= '3.11' +numpy==1.26.0; python_version >= '3.11' From 637961ba3258e987bec5fa51c220c08fd6c684c2 Mon Sep 17 00:00:00 2001 From: Xu Zhao Date: Wed, 19 Jun 2024 12:55:17 -0400 Subject: [PATCH 6/6] Add build requirements --- utils/build_requirements.txt | 6 ++++++ utils/cuda_utils.py | 18 +++--------------- 2 files changed, 9 insertions(+), 15 deletions(-) create mode 100644 utils/build_requirements.txt diff --git a/utils/build_requirements.txt b/utils/build_requirements.txt new file mode 100644 index 0000000000..36490ccac8 --- /dev/null +++ b/utils/build_requirements.txt @@ -0,0 +1,6 @@ +# We need to pin numpy version to the same as the torch testing environment +# which still supports python 3.8 +numpy==1.21.2; python_version < '3.11' +numpy==1.26.0; python_version >= '3.11' +psutil +pyyaml \ No newline at end of file diff --git a/utils/cuda_utils.py b/utils/cuda_utils.py index 7155b63377..92815679df 100644 --- a/utils/cuda_utils.py +++ b/utils/cuda_utils.py @@ -20,18 +20,7 @@ PIN_CMAKE_VERSION = "3.22.*" TORCHBENCH_TORCH_NIGHTLY_PACKAGES = ["torch", "torchvision", "torchaudio"] - -def _get_pin_numpy_version() -> str: - requirements_file = REPO_ROOT.joinpath("requirements.txt") - numpy_reg = "numpy==(.*)" - with open(requirements_file, "r") as fp: - numpy_requirement = list(filter(lambda x: "numpy==" in x, fp.readlines())) - assert numpy_requirement, f"Expected numpy version hardcoded in {str(requirements_file.resolve())}." - numpy_version = re.match(numpy_reg, numpy_requirement[0]).groups()[0] - print(f"Pinned NUMPY version: {numpy_version}") - return numpy_version - -PIN_NUMPY_VERSION = _get_pin_numpy_version() +BUILD_REQUIREMENTS_FILE = REPO_ROOT.joinpath("utils", "build_requirements.txt") def _nvcc_output_match(nvcc_output, target_cuda_version): regex = "release (.*)," @@ -163,9 +152,8 @@ def install_torch_build_deps(cuda_version: str): build_deps = ["ffmpeg"] cmd = ["conda", "install", "-y"] + build_deps subprocess.check_call(cmd) - # pip deps - pip_deps = [f"numpy=={PIN_NUMPY_VERSION}"] - cmd = ["pip", "install"] + pip_deps + # pip build deps + cmd = ["pip", "install", "-r"] + str(BUILD_REQUIREMENTS_FILE.resolve()) subprocess.check_call(cmd) # conda forge deps # ubuntu 22.04 comes with libstdcxx6 12.3.0