Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add package contraints to torchbench #2318

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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}")
5 changes: 1 addition & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions torchbenchmark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions torchbenchmark/canary_models/DALLE2_pytorch/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import patch
import subprocess
import sys
from utils.python_utils import pip_install_requirements

def patch_dalle2():
import dalle2_pytorch
Expand All @@ -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
Expand All @@ -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()
2 changes: 0 additions & 2 deletions torchbenchmark/canary_models/codellama/install.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

import subprocess
import sys
import os
from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model

Expand Down
7 changes: 1 addition & 6 deletions torchbenchmark/canary_models/fambench_dlrm/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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()
6 changes: 2 additions & 4 deletions torchbenchmark/canary_models/fambench_xlmr/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand Down
11 changes: 2 additions & 9 deletions torchbenchmark/canary_models/gat/install.py
Original file line number Diff line number Diff line change
@@ -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"])
6 changes: 1 addition & 5 deletions torchbenchmark/canary_models/hf_MPT_7b_instruct/install.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 1 addition & 3 deletions torchbenchmark/canary_models/hf_Yi/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 1 addition & 4 deletions torchbenchmark/canary_models/hf_mixtral/install.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 1 addition & 3 deletions torchbenchmark/canary_models/phi_1_5/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 1 addition & 5 deletions torchbenchmark/canary_models/phi_2/install.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
9 changes: 1 addition & 8 deletions torchbenchmark/canary_models/sage/install.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 1 addition & 9 deletions torchbenchmark/canary_models/torchrec_dlrm/install.py
Original file line number Diff line number Diff line change
@@ -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()
7 changes: 2 additions & 5 deletions torchbenchmark/models/Background_Matting/install.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
5 changes: 1 addition & 4 deletions torchbenchmark/models/Background_Matting/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 1 addition & 5 deletions torchbenchmark/models/LearningToPaint/install.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 1 addition & 7 deletions torchbenchmark/models/Super_SloMo/install.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
7 changes: 1 addition & 6 deletions torchbenchmark/models/dcgan/install.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
15 changes: 1 addition & 14 deletions torchbenchmark/models/demucs/install.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 1 addition & 5 deletions torchbenchmark/models/dlrm/install.py
Original file line number Diff line number Diff line change
@@ -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()
Loading
Loading