Skip to content

Commit

Permalink
Fix pip install requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzhao9 committed Jun 19, 2024
1 parent 9f80f30 commit 1db74ee
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 78 deletions.
18 changes: 2 additions & 16 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,11 @@

from userbenchmark import list_userbenchmarks
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 @@ -87,7 +73,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 Down
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
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
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()
7 changes: 1 addition & 6 deletions torchbenchmark/models/hf_T5_base/install.py
Original file line number Diff line number Diff line change
@@ -1,12 +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()
Expand Down
7 changes: 1 addition & 6 deletions torchbenchmark/models/hf_T5_large/install.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
6 changes: 1 addition & 5 deletions torchbenchmark/models/hf_Whisper/install.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
13 changes: 2 additions & 11 deletions torchbenchmark/util/framework/gnn/__init__.py
Original file line number Diff line number Diff line change
@@ -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"))
32 changes: 31 additions & 1 deletion utils/python_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import warnings
from pathlib import Path
import subprocess

DEFAULT_PYTHON_VERSION = "3.11"
Expand All @@ -14,14 +15,43 @@
"pytorch_url": "cp311",
},
}
REPO_DIR = Path(__file__).parent.parent


def create_conda_env(pyver: str, name: str):
command = ["conda", "create", "-n", name, "-y", f"python={pyver}"]
subprocess.check_call(command)


def pip_install_requirements(requirements_txt="requirements.txt", continue_on_fail=False):
import sys
constraints_file = REPO_DIR.joinpath("build", "contraints.txt")
if not constraints_file.exists():
warnings.warn("contraints.txt could not be found, please rerun install.py.")
constraints_parameters = []
else:
constraints_parameters = ["-c", str(constraints_file.resolve())]
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",
Expand Down

0 comments on commit 1db74ee

Please sign in to comment.