diff --git a/install.py b/install.py index b4d9903936..16da867e5b 100644 --- a/install.py +++ b/install.py @@ -5,26 +5,12 @@ from pathlib import Path from userbenchmark import list_userbenchmarks -from utils import get_pkg_versions, TORCH_DEPS +from utils import get_pkg_versions, TORCH_DEPS, generate_pkg_constraints +from utils.python_utils import pip_install_requirements REPO_ROOT = Path(__file__).parent -def pip_install_requirements(requirements_txt="requirements.txt"): - try: - subprocess.run( - [sys.executable, "-m", "pip", "install", "-q", "-r", requirements_txt], - check=True, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - ) - except subprocess.CalledProcessError as e: - return (False, e.output) - except Exception as e: - return (False, e) - return True, None - - if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( @@ -54,6 +40,11 @@ def pip_install_requirements(requirements_txt="requirements.txt"): action="store_true", help="Only require numpy to be installed, ignore torch, torchvision and torchaudio." ) + parser.add_argument( + "--check-only", + action="store_true", + help="Only run the version check and generate the contraints" + ) parser.add_argument("--canary", action="store_true", help="Install canary model.") parser.add_argument("--continue_on_fail", action="store_true") parser.add_argument("--verbose", "-v", action="store_true") @@ -71,10 +62,12 @@ def pip_install_requirements(requirements_txt="requirements.txt"): if args.numpy: TORCH_DEPS = ["numpy"] print( - f"checking packages {', '.join(TORCH_DEPS)} are installed...", + f"checking packages {', '.join(TORCH_DEPS)} are installed, generating constaints...", end="", flush=True, ) + if args.userbenchmark: + TORCH_DEPS = ["numpy", "torch"] try: versions = get_pkg_versions(TORCH_DEPS) except ModuleNotFoundError as e: @@ -83,8 +76,12 @@ def pip_install_requirements(requirements_txt="requirements.txt"): f"Error: Users must first manually install packages {TORCH_DEPS} before installing the benchmark." ) sys.exit(-1) + generate_pkg_constraints(versions) print("OK") + if args.check_only: + exit(0) + if args.userbenchmark: # Install userbenchmark dependencies if exists userbenchmark_dir = REPO_ROOT.joinpath("userbenchmark", args.userbenchmark) @@ -96,7 +93,7 @@ def pip_install_requirements(requirements_txt="requirements.txt"): ) sys.exit(0) - success, errmsg = pip_install_requirements() + success, errmsg = pip_install_requirements(continue_on_fail=True) if not success: print("Failed to install torchbenchmark requirements:") print(errmsg) @@ -120,7 +117,9 @@ def pip_install_requirements(requirements_txt="requirements.txt"): new_versions = get_pkg_versions(TORCH_DEPS) if versions != new_versions: print( - f"The torch packages are re-installed after installing the benchmark deps. \ + f"The numpy and torch package versions become inconsistent after installing the benchmark deps. \ Before: {versions}, after: {new_versions}" ) sys.exit(-1) + else: + print(f"installed torchbench with package constraints: {versions}") diff --git a/requirements.txt b/requirements.txt index e38ba85136..b9d52c5b24 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,10 +15,7 @@ transformers==4.38.1 MonkeyType 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; python_version < '3.11' -numpy==1.26.0; python_version >= '3.11' +numpy opencv-python submitit pynvml diff --git a/torchbenchmark/__init__.py b/torchbenchmark/__init__.py index e83ac449cf..dfbbd1eae5 100644 --- a/torchbenchmark/__init__.py +++ b/torchbenchmark/__init__.py @@ -184,10 +184,10 @@ def setup( versions = get_pkg_versions(TORCH_DEPS) success, errmsg, stdout_stderr = _install_deps(model_path, verbose=verbose) if test_mode: - new_versions = get_pkg_versions(TORCH_DEPS, reload=True) + new_versions = get_pkg_versions(TORCH_DEPS) if versions != new_versions: print( - f"The torch packages are re-installed after installing the benchmark model {model_path}. \ + f"The numpy and torch packages are re-installed after installing the benchmark model {model_path}. \ Before: {versions}, after: {new_versions}" ) sys.exit(-1) diff --git a/torchbenchmark/canary_models/DALLE2_pytorch/install.py b/torchbenchmark/canary_models/DALLE2_pytorch/install.py index 22f7c52a3d..9ec98b38c0 100644 --- a/torchbenchmark/canary_models/DALLE2_pytorch/install.py +++ b/torchbenchmark/canary_models/DALLE2_pytorch/install.py @@ -2,6 +2,7 @@ import patch import subprocess import sys +from utils.python_utils import pip_install_requirements def patch_dalle2(): import dalle2_pytorch @@ -12,8 +13,8 @@ def patch_dalle2(): print("Failed to patch dalle2_pytorch/dalle2_pytorch.py. Exit.") exit(1) -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +def pip_install_requirements_dalle2(): + pip_install_requirements() # DALLE2_pytorch requires embedding-reader # https://github.com/lucidrains/DALLE2-pytorch/blob/00e07b7d61e21447d55e6d06d5c928cf8b67601d/setup.py#L34 # embedding-reader requires an old version of pandas and pyarrow @@ -22,5 +23,5 @@ def pip_install_requirements(): subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-U', 'pandas', 'pyarrow']) if __name__ == '__main__': - pip_install_requirements() + pip_install_requirements_dalle2() patch_dalle2() \ No newline at end of file diff --git a/torchbenchmark/canary_models/codellama/install.py b/torchbenchmark/canary_models/codellama/install.py index cc27b6e7cf..9ebc7b8179 100644 --- a/torchbenchmark/canary_models/codellama/install.py +++ b/torchbenchmark/canary_models/codellama/install.py @@ -1,6 +1,4 @@ -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model diff --git a/torchbenchmark/canary_models/fambench_dlrm/install.py b/torchbenchmark/canary_models/fambench_dlrm/install.py index df5435fecc..2bb9cae7c4 100644 --- a/torchbenchmark/canary_models/fambench_dlrm/install.py +++ b/torchbenchmark/canary_models/fambench_dlrm/install.py @@ -2,6 +2,7 @@ import sys import subprocess from torchbenchmark import REPO_PATH +from utils.python_utils import pip_install_requirements def update_fambench_submodule(): @@ -17,12 +18,6 @@ def update_fambench_submodule(): subprocess.check_call(update_command, cwd=REPO_PATH) -def pip_install_requirements(): - subprocess.check_call( - [sys.executable, "-m", "pip", "install", "-q", "-r", "requirements.txt"] - ) - - if __name__ == "__main__": update_fambench_submodule() pip_install_requirements() diff --git a/torchbenchmark/canary_models/fambench_xlmr/install.py b/torchbenchmark/canary_models/fambench_xlmr/install.py index c36963ae7e..fad0952bdb 100644 --- a/torchbenchmark/canary_models/fambench_xlmr/install.py +++ b/torchbenchmark/canary_models/fambench_xlmr/install.py @@ -2,7 +2,7 @@ import sys import subprocess from torchbenchmark import REPO_PATH - +from utils.python_utils import pip_install_requirements def update_fambench_submodule(): "Update FAMBench submodule of the benchmark repo" @@ -19,9 +19,7 @@ def update_fambench_submodule(): def pip_install_requirements(): try: - subprocess.check_call( - [sys.executable, "-m", "pip", "install", "-q", "-r", "requirements.txt"] - ) + pip_install_requirements() # pin fairseq version # ignore deps specified in requirements.txt subprocess.check_call( diff --git a/torchbenchmark/canary_models/gat/install.py b/torchbenchmark/canary_models/gat/install.py index cdcba10a41..e67c0c5317 100644 --- a/torchbenchmark/canary_models/gat/install.py +++ b/torchbenchmark/canary_models/gat/install.py @@ -1,13 +1,6 @@ - -import subprocess -import sys from utils import s3_utils - - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt', '-f', 'https://data.pyg.org/whl/torch-2.1.0+cpu.html']) - +from utils.python_utils import pip_install_requirements if __name__ == '__main__': s3_utils.checkout_s3_data("INPUT_TARBALLS", "Reddit_minimal.tar.gz", decompress=True) - pip_install_requirements() + pip_install_requirements(extra_args=["-f", "https://data.pyg.org/whl/torch-2.1.0+cpu.html"]) diff --git a/torchbenchmark/canary_models/hf_MPT_7b_instruct/install.py b/torchbenchmark/canary_models/hf_MPT_7b_instruct/install.py index 1a49905932..123372a8de 100644 --- a/torchbenchmark/canary_models/hf_MPT_7b_instruct/install.py +++ b/torchbenchmark/canary_models/hf_MPT_7b_instruct/install.py @@ -1,10 +1,6 @@ -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/canary_models/hf_Yi/install.py b/torchbenchmark/canary_models/hf_Yi/install.py index 1a49905932..aab10dfd24 100644 --- a/torchbenchmark/canary_models/hf_Yi/install.py +++ b/torchbenchmark/canary_models/hf_Yi/install.py @@ -2,9 +2,7 @@ import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/canary_models/hf_mixtral/install.py b/torchbenchmark/canary_models/hf_mixtral/install.py index 1a49905932..b3013e1fa7 100644 --- a/torchbenchmark/canary_models/hf_mixtral/install.py +++ b/torchbenchmark/canary_models/hf_mixtral/install.py @@ -1,10 +1,7 @@ -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model +from utils.python_utils import pip_install_requirements -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/canary_models/phi_1_5/install.py b/torchbenchmark/canary_models/phi_1_5/install.py index 1a49905932..aab10dfd24 100644 --- a/torchbenchmark/canary_models/phi_1_5/install.py +++ b/torchbenchmark/canary_models/phi_1_5/install.py @@ -2,9 +2,7 @@ import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/canary_models/phi_2/install.py b/torchbenchmark/canary_models/phi_2/install.py index 1a49905932..123372a8de 100644 --- a/torchbenchmark/canary_models/phi_2/install.py +++ b/torchbenchmark/canary_models/phi_2/install.py @@ -1,10 +1,6 @@ -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/canary_models/sage/install.py b/torchbenchmark/canary_models/sage/install.py index cdcba10a41..4a57983e56 100644 --- a/torchbenchmark/canary_models/sage/install.py +++ b/torchbenchmark/canary_models/sage/install.py @@ -1,12 +1,5 @@ - -import subprocess -import sys from utils import s3_utils - - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt', '-f', 'https://data.pyg.org/whl/torch-2.1.0+cpu.html']) - +from utils.python_utils import pip_install_requirements if __name__ == '__main__': s3_utils.checkout_s3_data("INPUT_TARBALLS", "Reddit_minimal.tar.gz", decompress=True) diff --git a/torchbenchmark/canary_models/torchrec_dlrm/install.py b/torchbenchmark/canary_models/torchrec_dlrm/install.py index e92d8783ca..df4fdfae39 100644 --- a/torchbenchmark/canary_models/torchrec_dlrm/install.py +++ b/torchbenchmark/canary_models/torchrec_dlrm/install.py @@ -1,12 +1,4 @@ -import subprocess -import sys - - -def pip_install_requirements(): - subprocess.check_call( - [sys.executable, "-m", "pip", "install", "-q", "-r", "requirements.txt"] - ) - +from utils.python_utils import pip_install_requirements if __name__ == "__main__": pip_install_requirements() diff --git a/torchbenchmark/models/Background_Matting/install.py b/torchbenchmark/models/Background_Matting/install.py index 97b247920d..66c1bff7fb 100644 --- a/torchbenchmark/models/Background_Matting/install.py +++ b/torchbenchmark/models/Background_Matting/install.py @@ -1,10 +1,7 @@ -import subprocess -import sys -from utils import s3_utils +from utils import s3_utils, python_utils def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', - 'install', '-q', '-r', 'requirements.txt']) + python_utils.pip_install_requirements('requirements.txt') if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/Background_Matting/requirements.txt b/torchbenchmark/models/Background_Matting/requirements.txt index 3250404275..188e465c72 100644 --- a/torchbenchmark/models/Background_Matting/requirements.txt +++ b/torchbenchmark/models/Background_Matting/requirements.txt @@ -1,7 +1,4 @@ -# 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' +numpy opencv-python pandas Pillow diff --git a/torchbenchmark/models/LearningToPaint/install.py b/torchbenchmark/models/LearningToPaint/install.py index f07ff09530..d3171878f3 100755 --- a/torchbenchmark/models/LearningToPaint/install.py +++ b/torchbenchmark/models/LearningToPaint/install.py @@ -1,11 +1,7 @@ -import subprocess -import sys from utils import s3_utils +from utils.python_utils import pip_install_requirements -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) - if __name__ == '__main__': s3_utils.checkout_s3_data("INPUT_TARBALLS", "Super_SloMo_inputs.tar.gz", decompress=True) pip_install_requirements() diff --git a/torchbenchmark/models/Super_SloMo/install.py b/torchbenchmark/models/Super_SloMo/install.py index 4762aab2af..8f5b834819 100644 --- a/torchbenchmark/models/Super_SloMo/install.py +++ b/torchbenchmark/models/Super_SloMo/install.py @@ -1,11 +1,5 @@ -import subprocess -import sys from utils import s3_utils - - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) - +from utils.python_utils import pip_install_requirements if __name__ == '__main__': s3_utils.checkout_s3_data("INPUT_TARBALLS", "Super_SloMo_inputs.tar.gz", decompress=True) diff --git a/torchbenchmark/models/dcgan/install.py b/torchbenchmark/models/dcgan/install.py index 76fc6193d5..4ae5bae9c5 100644 --- a/torchbenchmark/models/dcgan/install.py +++ b/torchbenchmark/models/dcgan/install.py @@ -1,9 +1,4 @@ -import subprocess -import sys - - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/demucs/install.py b/torchbenchmark/models/demucs/install.py index b550c34e8a..44bd90cc2c 100644 --- a/torchbenchmark/models/demucs/install.py +++ b/torchbenchmark/models/demucs/install.py @@ -1,17 +1,4 @@ -import subprocess -import sys - - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) - -def spacy_download(language): - pass - -def preprocess(): - pass +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() - spacy_download('') - preprocess() diff --git a/torchbenchmark/models/dlrm/install.py b/torchbenchmark/models/dlrm/install.py index e89de1f48e..44bd90cc2c 100644 --- a/torchbenchmark/models/dlrm/install.py +++ b/torchbenchmark/models/dlrm/install.py @@ -1,8 +1,4 @@ -import subprocess -import sys - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/doctr_det_predictor/install.py b/torchbenchmark/models/doctr_det_predictor/install.py index cc1a5c8e60..28ea3ab5d1 100644 --- a/torchbenchmark/models/doctr_det_predictor/install.py +++ b/torchbenchmark/models/doctr_det_predictor/install.py @@ -1,9 +1,9 @@ import warnings import subprocess -import sys +from utils.python_utils import pip_install_requirements -def pip_install_requirements(): +def pip_install_requirements_doctr(): try: subprocess.check_call( [ @@ -21,10 +21,8 @@ def pip_install_requirements(): warnings.warn( "The doctr_det_predictor model requires conda binary libaries to be installed. Missing conda packages might break this model." ) - subprocess.check_call( - [sys.executable, "-m", "pip", "install", "-q", "-r", "requirements.txt"] - ) + pip_install_requirements() if __name__ == "__main__": - pip_install_requirements() + pip_install_requirements_doctr() diff --git a/torchbenchmark/models/doctr_reco_predictor/install.py b/torchbenchmark/models/doctr_reco_predictor/install.py index e2a71a867e..fa88db86d8 100644 --- a/torchbenchmark/models/doctr_reco_predictor/install.py +++ b/torchbenchmark/models/doctr_reco_predictor/install.py @@ -1,9 +1,9 @@ import warnings import subprocess -import sys +from utils.python_utils import pip_install_requirements -def pip_install_requirements(): +def pip_install_requirements_doctr(): try: subprocess.check_call( [ @@ -21,10 +21,8 @@ def pip_install_requirements(): warnings.warn( "The doctr_reco_predictor model requires conda binary libaries to be installed. Missing conda packages might break this model." ) - subprocess.check_call( - [sys.executable, "-m", "pip", "install", "-q", "-r", "requirements.txt"] - ) + pip_install_requirements() if __name__ == "__main__": - pip_install_requirements() + pip_install_requirements_doctr() diff --git a/torchbenchmark/models/drq/install.py b/torchbenchmark/models/drq/install.py index e23c24a52e..e5ce478f75 100644 --- a/torchbenchmark/models/drq/install.py +++ b/torchbenchmark/models/drq/install.py @@ -1,9 +1,5 @@ -import subprocess -import sys from utils import s3_utils - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/fastNLP_Bert/install.py b/torchbenchmark/models/fastNLP_Bert/install.py index 72c21ef3e6..1b9b298fb2 100644 --- a/torchbenchmark/models/fastNLP_Bert/install.py +++ b/torchbenchmark/models/fastNLP_Bert/install.py @@ -1,7 +1,6 @@ -import subprocess import os -import sys import patch +from utils.python_utils import pip_install_requirements def patch_fastnlp(): import fastNLP @@ -14,9 +13,6 @@ def patch_fastnlp(): print("Failed to patch fastNLP. Exit.") exit(1) -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) - if __name__ == '__main__': pip_install_requirements() patch_fastnlp() diff --git a/torchbenchmark/models/functorch_dp_cifar10/install.py b/torchbenchmark/models/functorch_dp_cifar10/install.py index be308ead48..44bd90cc2c 100644 --- a/torchbenchmark/models/functorch_dp_cifar10/install.py +++ b/torchbenchmark/models/functorch_dp_cifar10/install.py @@ -1,9 +1,4 @@ -import subprocess -import sys - - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/functorch_maml_omniglot/install.py b/torchbenchmark/models/functorch_maml_omniglot/install.py index d3e20cdb9b..117c8cf1dc 100644 --- a/torchbenchmark/models/functorch_maml_omniglot/install.py +++ b/torchbenchmark/models/functorch_maml_omniglot/install.py @@ -1,10 +1,5 @@ -import subprocess -import sys from utils import s3_utils - - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/hf_Albert/install.py b/torchbenchmark/models/hf_Albert/install.py index c7855f3fef..81d8d0492c 100644 --- a/torchbenchmark/models/hf_Albert/install.py +++ b/torchbenchmark/models/hf_Albert/install.py @@ -1,11 +1,6 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/hf_Bart/install.py b/torchbenchmark/models/hf_Bart/install.py index c7855f3fef..81d8d0492c 100644 --- a/torchbenchmark/models/hf_Bart/install.py +++ b/torchbenchmark/models/hf_Bart/install.py @@ -1,11 +1,6 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/hf_Bert/install.py b/torchbenchmark/models/hf_Bert/install.py index c7855f3fef..81d8d0492c 100644 --- a/torchbenchmark/models/hf_Bert/install.py +++ b/torchbenchmark/models/hf_Bert/install.py @@ -1,11 +1,6 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/hf_Bert_large/install.py b/torchbenchmark/models/hf_Bert_large/install.py index c7855f3fef..81d8d0492c 100644 --- a/torchbenchmark/models/hf_Bert_large/install.py +++ b/torchbenchmark/models/hf_Bert_large/install.py @@ -1,11 +1,6 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/hf_BigBird/install.py b/torchbenchmark/models/hf_BigBird/install.py index a906fe3141..81d8d0492c 100644 --- a/torchbenchmark/models/hf_BigBird/install.py +++ b/torchbenchmark/models/hf_BigBird/install.py @@ -1,14 +1,9 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() patch_transformers() model_name = os.path.basename(os.path.dirname(os.path.abspath(__file__))) - cache_model(model_name) \ No newline at end of file + cache_model(model_name) diff --git a/torchbenchmark/models/hf_DistilBert/install.py b/torchbenchmark/models/hf_DistilBert/install.py index c7855f3fef..81d8d0492c 100644 --- a/torchbenchmark/models/hf_DistilBert/install.py +++ b/torchbenchmark/models/hf_DistilBert/install.py @@ -1,11 +1,6 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/hf_GPT2/install.py b/torchbenchmark/models/hf_GPT2/install.py index c7855f3fef..81d8d0492c 100644 --- a/torchbenchmark/models/hf_GPT2/install.py +++ b/torchbenchmark/models/hf_GPT2/install.py @@ -1,11 +1,6 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/hf_GPT2_large/install.py b/torchbenchmark/models/hf_GPT2_large/install.py index c7855f3fef..81d8d0492c 100644 --- a/torchbenchmark/models/hf_GPT2_large/install.py +++ b/torchbenchmark/models/hf_GPT2_large/install.py @@ -1,11 +1,6 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/hf_Longformer/install.py b/torchbenchmark/models/hf_Longformer/install.py index c7855f3fef..81d8d0492c 100644 --- a/torchbenchmark/models/hf_Longformer/install.py +++ b/torchbenchmark/models/hf_Longformer/install.py @@ -1,11 +1,6 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/hf_Reformer/install.py b/torchbenchmark/models/hf_Reformer/install.py index c7855f3fef..81d8d0492c 100644 --- a/torchbenchmark/models/hf_Reformer/install.py +++ b/torchbenchmark/models/hf_Reformer/install.py @@ -1,11 +1,6 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/hf_T5/install.py b/torchbenchmark/models/hf_T5/install.py index c7855f3fef..81d8d0492c 100644 --- a/torchbenchmark/models/hf_T5/install.py +++ b/torchbenchmark/models/hf_T5/install.py @@ -1,11 +1,6 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/hf_T5_base/install.py b/torchbenchmark/models/hf_T5_base/install.py index c7855f3fef..81d8d0492c 100644 --- a/torchbenchmark/models/hf_T5_base/install.py +++ b/torchbenchmark/models/hf_T5_base/install.py @@ -1,11 +1,6 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/hf_T5_large/install.py b/torchbenchmark/models/hf_T5_large/install.py index c7855f3fef..81d8d0492c 100644 --- a/torchbenchmark/models/hf_T5_large/install.py +++ b/torchbenchmark/models/hf_T5_large/install.py @@ -1,11 +1,6 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/hf_Whisper/install.py b/torchbenchmark/models/hf_Whisper/install.py index 1a49905932..b0fe419716 100644 --- a/torchbenchmark/models/hf_Whisper/install.py +++ b/torchbenchmark/models/hf_Whisper/install.py @@ -1,11 +1,7 @@ -import subprocess -import sys import os +from utils.python_utils import pip_install_requirements from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) - if __name__ == '__main__': pip_install_requirements() patch_transformers() diff --git a/torchbenchmark/models/hf_Whisper/requirements.txt b/torchbenchmark/models/hf_Whisper/requirements.txt index 461b9ef776..c3db4451e8 100644 --- a/torchbenchmark/models/hf_Whisper/requirements.txt +++ b/torchbenchmark/models/hf_Whisper/requirements.txt @@ -1,5 +1 @@ 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==1.26.0; python_version >= '3.11' \ No newline at end of file diff --git a/torchbenchmark/models/hf_distil_whisper/install.py b/torchbenchmark/models/hf_distil_whisper/install.py index c7855f3fef..81d8d0492c 100644 --- a/torchbenchmark/models/hf_distil_whisper/install.py +++ b/torchbenchmark/models/hf_distil_whisper/install.py @@ -1,11 +1,6 @@ - -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/lennard_jones/install.py b/torchbenchmark/models/lennard_jones/install.py index be308ead48..44bd90cc2c 100644 --- a/torchbenchmark/models/lennard_jones/install.py +++ b/torchbenchmark/models/lennard_jones/install.py @@ -1,9 +1,4 @@ -import subprocess -import sys - - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/llama/install.py b/torchbenchmark/models/llama/install.py index d6baff0571..44bd90cc2c 100644 --- a/torchbenchmark/models/llama/install.py +++ b/torchbenchmark/models/llama/install.py @@ -1,8 +1,4 @@ -import subprocess -import sys - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': - pip_install_requirements() \ No newline at end of file + pip_install_requirements() diff --git a/torchbenchmark/models/llava/install.py b/torchbenchmark/models/llava/install.py index 1a49905932..81d8d0492c 100644 --- a/torchbenchmark/models/llava/install.py +++ b/torchbenchmark/models/llava/install.py @@ -1,13 +1,9 @@ -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() patch_transformers() model_name = os.path.basename(os.path.dirname(os.path.abspath(__file__))) - cache_model(model_name) \ No newline at end of file + cache_model(model_name) diff --git a/torchbenchmark/models/maml_omniglot/install.py b/torchbenchmark/models/maml_omniglot/install.py index d3e20cdb9b..117c8cf1dc 100644 --- a/torchbenchmark/models/maml_omniglot/install.py +++ b/torchbenchmark/models/maml_omniglot/install.py @@ -1,10 +1,5 @@ -import subprocess -import sys from utils import s3_utils - - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/moondream/install.py b/torchbenchmark/models/moondream/install.py index 1a49905932..b3013e1fa7 100644 --- a/torchbenchmark/models/moondream/install.py +++ b/torchbenchmark/models/moondream/install.py @@ -1,10 +1,7 @@ -import subprocess -import sys import os from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model +from utils.python_utils import pip_install_requirements -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/nvidia_deeprecommender/install.py b/torchbenchmark/models/nvidia_deeprecommender/install.py index 76fc6193d5..6b1178892f 100644 --- a/torchbenchmark/models/nvidia_deeprecommender/install.py +++ b/torchbenchmark/models/nvidia_deeprecommender/install.py @@ -1,9 +1,6 @@ import subprocess import sys - - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/opacus_cifar10/install.py b/torchbenchmark/models/opacus_cifar10/install.py index e89de1f48e..44bd90cc2c 100644 --- a/torchbenchmark/models/opacus_cifar10/install.py +++ b/torchbenchmark/models/opacus_cifar10/install.py @@ -1,8 +1,4 @@ -import subprocess -import sys - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/pytorch_CycleGAN_and_pix2pix/install.py b/torchbenchmark/models/pytorch_CycleGAN_and_pix2pix/install.py index 1ff77b2a20..0c2da1f20f 100644 --- a/torchbenchmark/models/pytorch_CycleGAN_and_pix2pix/install.py +++ b/torchbenchmark/models/pytorch_CycleGAN_and_pix2pix/install.py @@ -1,10 +1,5 @@ -import subprocess -import sys from utils import s3_utils - - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': s3_utils.checkout_s3_data("INPUT_TARBALLS", "pytorch_CycleGAN_and_pix2pix_inputs.tar.gz", decompress=True) diff --git a/torchbenchmark/models/pytorch_stargan/install.py b/torchbenchmark/models/pytorch_stargan/install.py index 1db8bdc758..9b7af53603 100644 --- a/torchbenchmark/models/pytorch_stargan/install.py +++ b/torchbenchmark/models/pytorch_stargan/install.py @@ -1,9 +1,5 @@ -import subprocess -import sys from utils import s3_utils - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': s3_utils.checkout_s3_data("INPUT_TARBALLS", "pytorch_stargan_inputs.tar.gz", decompress=True) diff --git a/torchbenchmark/models/pytorch_unet/install.py b/torchbenchmark/models/pytorch_unet/install.py index 65ac1173a6..d970819692 100644 --- a/torchbenchmark/models/pytorch_unet/install.py +++ b/torchbenchmark/models/pytorch_unet/install.py @@ -1,9 +1,4 @@ -import subprocess -import sys - - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'pytorch_unet/requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': - pip_install_requirements() + pip_install_requirements(requirements_txt="pytorch_unet/requirements.txt") diff --git a/torchbenchmark/models/sam/install.py b/torchbenchmark/models/sam/install.py index 7c94fa7bae..96f6d890f4 100644 --- a/torchbenchmark/models/sam/install.py +++ b/torchbenchmark/models/sam/install.py @@ -2,6 +2,7 @@ import subprocess import sys import requests +from utils.python_utils import pip_install_requirements def download(uri): directory = '.data' @@ -16,10 +17,6 @@ def download(uri): else: print(f'Failed to download file with status code {response.status_code}') - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) - def download_checkpoint(): download('https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth') diff --git a/torchbenchmark/models/sam_fast/install.py b/torchbenchmark/models/sam_fast/install.py index 7c94fa7bae..c12254ce53 100644 --- a/torchbenchmark/models/sam_fast/install.py +++ b/torchbenchmark/models/sam_fast/install.py @@ -1,7 +1,6 @@ import os -import subprocess -import sys import requests +from utils.python_utils import pip_install_requirements def download(uri): directory = '.data' @@ -16,10 +15,6 @@ def download(uri): else: print(f'Failed to download file with status code {response.status_code}') - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) - def download_checkpoint(): download('https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth') diff --git a/torchbenchmark/models/soft_actor_critic/__init__.py b/torchbenchmark/models/soft_actor_critic/__init__.py index 5008ba5c5f..1d76c2442c 100644 --- a/torchbenchmark/models/soft_actor_critic/__init__.py +++ b/torchbenchmark/models/soft_actor_critic/__init__.py @@ -12,7 +12,7 @@ from .envs import load_gym from .sac import SACAgent from .replay import PrioritizedReplayBuffer, ReplayBuffer -from .utils import hard_update, soft_update +from .sac_utils import hard_update, soft_update def learn_standard( diff --git a/torchbenchmark/models/soft_actor_critic/install.py b/torchbenchmark/models/soft_actor_critic/install.py index e92d8783ca..df4fdfae39 100644 --- a/torchbenchmark/models/soft_actor_critic/install.py +++ b/torchbenchmark/models/soft_actor_critic/install.py @@ -1,12 +1,4 @@ -import subprocess -import sys - - -def pip_install_requirements(): - subprocess.check_call( - [sys.executable, "-m", "pip", "install", "-q", "-r", "requirements.txt"] - ) - +from utils.python_utils import pip_install_requirements if __name__ == "__main__": pip_install_requirements() diff --git a/torchbenchmark/models/soft_actor_critic/utils.py b/torchbenchmark/models/soft_actor_critic/sac_utils.py similarity index 100% rename from torchbenchmark/models/soft_actor_critic/utils.py rename to torchbenchmark/models/soft_actor_critic/sac_utils.py diff --git a/torchbenchmark/models/speech_transformer/install.py b/torchbenchmark/models/speech_transformer/install.py index 2627e23a15..c8352f35d6 100644 --- a/torchbenchmark/models/speech_transformer/install.py +++ b/torchbenchmark/models/speech_transformer/install.py @@ -1,9 +1,5 @@ -import sys -import subprocess from utils import s3_utils - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': s3_utils.checkout_s3_data("INPUT_TARBALLS", "speech_transformer_inputs.tar.gz", decompress=True) diff --git a/torchbenchmark/models/tacotron2/install.py b/torchbenchmark/models/tacotron2/install.py index 19760fa148..50eaec2625 100644 --- a/torchbenchmark/models/tacotron2/install.py +++ b/torchbenchmark/models/tacotron2/install.py @@ -1,8 +1,7 @@ import os from pathlib import Path -import subprocess -import sys from utils import s3_utils +from utils.python_utils import pip_install_requirements def check_data_dir(): @@ -10,10 +9,6 @@ def check_data_dir(): tacotron2_data_dir = os.path.join(current_dir.parent.parent, "data", ".data", "tacotron2-minimal") assert os.path.exists(tacotron2_data_dir), "Couldn't find tacotron2 minimal data dir, please run install.py again." - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) - if __name__ == '__main__': pip_install_requirements() s3_utils.checkout_s3_data("INPUT_TARBALLS", "tacotron2-minimal.tar.gz", decompress=True) diff --git a/torchbenchmark/models/tacotron2/requirements.txt b/torchbenchmark/models/tacotron2/requirements.txt index 4f642207d5..39e8afb167 100644 --- a/torchbenchmark/models/tacotron2/requirements.txt +++ b/torchbenchmark/models/tacotron2/requirements.txt @@ -1,7 +1,4 @@ -# 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' +numpy inflect scipy Unidecode diff --git a/torchbenchmark/models/timm_efficientdet/install.py b/torchbenchmark/models/timm_efficientdet/install.py index 6b827c367c..217991d714 100644 --- a/torchbenchmark/models/timm_efficientdet/install.py +++ b/torchbenchmark/models/timm_efficientdet/install.py @@ -1,8 +1,7 @@ import os -import sys import patch -import subprocess from utils import s3_utils +from utils.python_utils import pip_install_requirements def patch_effdet(): @@ -29,12 +28,6 @@ def patch_pycocotools(): exit(1) -def pip_install_requirements(): - subprocess.check_call( - [sys.executable, "-m", "pip", "install", "-q", "-r", "requirements.txt"] - ) - - if __name__ == "__main__": s3_utils.checkout_s3_data( "INPUT_TARBALLS", "coco2017-minimal.tar.gz", decompress=True diff --git a/torchbenchmark/models/torch_multimodal_clip/install.py b/torchbenchmark/models/torch_multimodal_clip/install.py index 91c9f9dbad..ed1a830755 100644 --- a/torchbenchmark/models/torch_multimodal_clip/install.py +++ b/torchbenchmark/models/torch_multimodal_clip/install.py @@ -1,7 +1,6 @@ import os -import subprocess -import sys import requests +from utils.python_utils import pip_install_requirements def download(output_filename, uri): # Download the file with streaming to handle large files @@ -16,9 +15,6 @@ def download(output_filename, uri): else: print(f'Failed to download file with status code {response.status_code}') -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) - def download_data(data_folder): # CC-0 image from wikipedia page on pizza so legal to use download(os.path.join(data_folder, 'pizza.jpg'), 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Pizza-3007395.jpg/2880px-Pizza-3007395.jpg') diff --git a/torchbenchmark/models/tts_angular/install.py b/torchbenchmark/models/tts_angular/install.py index be308ead48..44bd90cc2c 100644 --- a/torchbenchmark/models/tts_angular/install.py +++ b/torchbenchmark/models/tts_angular/install.py @@ -1,9 +1,4 @@ -import subprocess -import sys - - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': pip_install_requirements() diff --git a/torchbenchmark/models/vision_maskrcnn/install.py b/torchbenchmark/models/vision_maskrcnn/install.py index 9202f4d8a4..863a6923ff 100644 --- a/torchbenchmark/models/vision_maskrcnn/install.py +++ b/torchbenchmark/models/vision_maskrcnn/install.py @@ -1,9 +1,5 @@ -import sys -import subprocess from utils import s3_utils - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) +from utils.python_utils import pip_install_requirements if __name__ == '__main__': s3_utils.checkout_s3_data("INPUT_TARBALLS", "coco2017-minimal.tar.gz", decompress=True) diff --git a/torchbenchmark/models/yolov3/install.py b/torchbenchmark/models/yolov3/install.py index acce2aac0c..7859313d21 100644 --- a/torchbenchmark/models/yolov3/install.py +++ b/torchbenchmark/models/yolov3/install.py @@ -1,18 +1,13 @@ -import subprocess -import sys import os from pathlib import Path from utils import s3_utils +from utils.python_utils import pip_install_requirements def setup_data_dir(): current_dir = Path(os.path.dirname(os.path.realpath(__file__))) coco128_data_dir = os.path.join(current_dir.parent.parent, "data", ".data", "coco128") assert os.path.exists(coco128_data_dir), "Couldn't find coco128 data dir, please run install.py again." - -def pip_install_requirements(): - subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt']) - if __name__ == '__main__': s3_utils.checkout_s3_data("INPUT_TARBALLS", "coco128.tar.gz", decompress=True) pip_install_requirements() diff --git a/torchbenchmark/util/env_check.py b/torchbenchmark/util/env_check.py index 9f97babb03..bb9755e0b2 100644 --- a/torchbenchmark/util/env_check.py +++ b/torchbenchmark/util/env_check.py @@ -3,9 +3,7 @@ This file may be loaded without torch packages installed, e.g., in OnDemand CI. """ -import argparse import copy -import importlib import os import shutil import argparse @@ -187,10 +185,13 @@ def deterministic_torch_manual_seed(*args, **kwargs): def get_pkg_versions(packages: List[str]) -> Dict[str, str]: + import sys + import subprocess versions = {} for module in packages: - module = importlib.import_module(module) - versions[module] = module.__version__ + cmd = [sys.executable, "-c", f'import {module}; print({module}.__version__)'] + version = subprocess.check_output(cmd).decode().strip() + versions[module] = version return versions diff --git a/torchbenchmark/util/framework/detectron2/__init__.py b/torchbenchmark/util/framework/detectron2/__init__.py index 2a473e41fd..f6e4020960 100644 --- a/torchbenchmark/util/framework/detectron2/__init__.py +++ b/torchbenchmark/util/framework/detectron2/__init__.py @@ -6,6 +6,7 @@ from urllib import request from utils import s3_utils +from utils.python_utils import pip_install_requirements CURRENT_DIR = Path(os.path.dirname(os.path.realpath(__file__))) # Load pre-trained weights @@ -40,16 +41,14 @@ def install_model_weights(model_name, model_dir): request.urlretrieve(MODEL_WEIGHTS_MAP[model_name], model_full_path) -def pip_install_requirements(): +def pip_install_requirements_detectron2(): requirements_file = os.path.join(CURRENT_DIR, "requirements.txt") # Installing by --no-build-isolation after explicitly installing build-time requirements is required. # See https://github.com/facebookresearch/detectron2/issues/4921 subprocess.check_call( [sys.executable, "-m", "pip", "install", "-q", "wheel", "cython"] # Build-time requirements ) - subprocess.check_call( - [sys.executable, "-m", "pip", "install", "--no-build-isolation", "-q", "-r", requirements_file] - ) + pip_install_requirements(requirements_txt=requirements_file, no_build_isolation=True) # This is to workaround https://github.com/facebookresearch/detectron2/issues/3934 @@ -72,5 +71,5 @@ def install_detectron2(model_name, model_dir): "INPUT_TARBALLS", "coco2017-minimal.tar.gz", decompress=True ) install_model_weights(model_name, model_dir) - pip_install_requirements() + pip_install_requirements_detectron2() remove_tools_directory() diff --git a/torchbenchmark/util/framework/detectron2/requirements.txt b/torchbenchmark/util/framework/detectron2/requirements.txt index acec6a1840..f38075ddd7 100644 --- a/torchbenchmark/util/framework/detectron2/requirements.txt +++ b/torchbenchmark/util/framework/detectron2/requirements.txt @@ -1,6 +1,3 @@ git+https://github.com/facebookresearch/detectron2.git@0df2d73d0013db7de629602c23cc120219b4f2b8 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==1.26.0; python_version >= '3.11' +numpy diff --git a/torchbenchmark/util/framework/diffusers/__init__.py b/torchbenchmark/util/framework/diffusers/__init__.py index 16f7256437..a3153f2027 100644 --- a/torchbenchmark/util/framework/diffusers/__init__.py +++ b/torchbenchmark/util/framework/diffusers/__init__.py @@ -1,17 +1,9 @@ import os -import subprocess -import sys from pathlib import Path +from utils.python_utils import pip_install_requirements CURRENT_DIR = Path(os.path.dirname(os.path.realpath(__file__))) - -def pip_install_requirements(): - requirements_file = os.path.join(CURRENT_DIR, "requirements.txt") - subprocess.check_call( - [sys.executable, "-m", "pip", "install", "-q", "-r", requirements_file] - ) - - def install_diffusers(): - pip_install_requirements() + requirements_file = os.path.join(CURRENT_DIR, "requirements.txt") + pip_install_requirements(requirements_txt=requirements_file) diff --git a/torchbenchmark/util/framework/gnn/__init__.py b/torchbenchmark/util/framework/gnn/__init__.py index 960c115cc1..a37c4896f4 100644 --- a/torchbenchmark/util/framework/gnn/__init__.py +++ b/torchbenchmark/util/framework/gnn/__init__.py @@ -1,16 +1,7 @@ import os.path -import subprocess -import sys +from utils.python_utils import pip_install_requirements CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) - def install_pytorch_geometric(): - pip_install_requirements() - - -def pip_install_requirements(): - requirements_file = os.path.join(CURRENT_DIR, "requirements.txt") - subprocess.check_call( - [sys.executable, "-m", "pip", "install", "-q", "-r", requirements_file] - ) + pip_install_requirements(os.path.join(CURRENT_DIR, "requirements.txt")) diff --git a/torchbenchmark/util/framework/lit_llama.py b/torchbenchmark/util/framework/lit_llama.py index d3f9e9b82a..d8c2e2dd92 100644 --- a/torchbenchmark/util/framework/lit_llama.py +++ b/torchbenchmark/util/framework/lit_llama.py @@ -5,6 +5,7 @@ from pathlib import Path from torchbenchmark import REPO_PATH +from utils.python_utils import pip_install_requirements LIT_LLAMA_PATH = os.path.join(REPO_PATH, "submodules", "lit-llama") @@ -21,20 +22,6 @@ def update_lit_llama_submodule(): subprocess.check_call(update_command, cwd=REPO_PATH) -def pip_install_requirements(): - subprocess.check_call( - [ - sys.executable, - "-m", - "pip", - "install", - "-q", - "-r", - os.path.join(LIT_LLAMA_PATH, "requirements.txt"), - ] - ) - - def openllama_download(): if os.path.exists( os.path.join(LIT_LLAMA_PATH, "checkpoints/lit-llama/7B/lit-llama.pth") diff --git a/utils/__init__.py b/utils/__init__.py index e7d3e2e8d5..49e32c8f7e 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -1,7 +1,9 @@ -import importlib import sys +import subprocess from typing import Dict, List +from pathlib import Path +REPO_DIR = Path(__file__).parent.parent TORCH_DEPS = ["numpy", "torch", "torchvision", "torchaudio"] @@ -18,12 +20,20 @@ def __exit__(self, exc_type, exc_value, traceback): except ValueError: pass - -def get_pkg_versions(packages: List[str], reload: bool = False) -> Dict[str, str]: +def get_pkg_versions(packages: List[str]) -> Dict[str, str]: versions = {} for module in packages: - module = importlib.import_module(module) - if reload: - module = importlib.reload(module) - versions[module.__name__] = module.__version__ + cmd = [sys.executable, "-c", f'import {module}; print({module}.__version__)'] + version = subprocess.check_output(cmd).decode().strip() + versions[module] = version return versions + +def generate_pkg_constraints(package_versions: Dict[str, str]): + """ + Generate package versions dict and save them to {REPO_ROOT}/build/constraints.txt + """ + output_dir = REPO_DIR.joinpath("build") + output_dir.mkdir(exist_ok=True) + with open(output_dir.joinpath("constraints.txt"), "w") as fp: + for k, v in package_versions.items(): + fp.write(f"{k}=={v}\n") diff --git a/utils/python_utils.py b/utils/python_utils.py index ca8a1d0965..cadaa9d48e 100644 --- a/utils/python_utils.py +++ b/utils/python_utils.py @@ -1,6 +1,9 @@ -import argparse +import warnings +from pathlib import Path import subprocess +from typing import Optional, List + DEFAULT_PYTHON_VERSION = "3.11" PYTHON_VERSION_MAP = { @@ -14,6 +17,7 @@ "pytorch_url": "cp311", }, } +REPO_DIR = Path(__file__).parent.parent def create_conda_env(pyver: str, name: str): @@ -21,7 +25,45 @@ def create_conda_env(pyver: str, name: str): subprocess.check_call(command) +def pip_install_requirements(requirements_txt="requirements.txt", + continue_on_fail=False, + no_build_isolation=False, + extra_args: Optional[List[str]]=None): + import sys + constraints_file = REPO_DIR.joinpath("build", "constraints.txt") + if not constraints_file.exists(): + warnings.warn("The build/constrants.txt file is not found. " + "Please consider rerunning the install.py script to generate it." + "It is recommended to install with the build/constrants.txt file " + "to prevent unexpected version change of numpy or torch.") + constraints_parameters = [] + else: + constraints_parameters = ["-c", str(constraints_file.resolve())] + if no_build_isolation: + constraints_parameters.append("--no-build-isolation") + if extra_args and isinstance(extra_args, list): + constraints_parameters.extend(extra_args) + if not continue_on_fail: + subprocess.check_call( + [sys.executable, "-m", "pip", "install", "-r", requirements_txt] + constraints_parameters, + ) + return True, None + try: + subprocess.run( + [sys.executable, "-m", "pip", "install", "-r", requirements_txt] + constraints_parameters, + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + ) + except subprocess.CalledProcessError as e: + return (False, e.output) + except Exception as e: + return (False, e) + return True, None + + if __name__ == "__main__": + import argparse parser = argparse.ArgumentParser() parser.add_argument( "--pyver",