Skip to content

Commit

Permalink
Refactoring dependencies for installing TorchServe (#2247)
Browse files Browse the repository at this point in the history
* Refactoring dependencies

* remove redundancy

* Fix failures in CI

* ci failure

* testing CI GPU

* testing CI GPU

* testing CI GPU

* testing CI GPU

* GPU added

* code cleanup

* code cleanup

* review comments

* review comments

* review comments

* renamed gpu.txt to common_gpu.txt
  • Loading branch information
agunapal authored Apr 25, 2023
1 parent 4e08fd1 commit d6e072a
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 26 deletions.
2 changes: 0 additions & 2 deletions requirements/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ captum
packaging
numpy; sys_platform != 'win32'
numpy==1.19.3; sys_platform == 'win32' #see https://tinyurl.com/y3dm3h86
nvgpu; sys_platform != 'win32'
nvgpu==0.8.0; sys_platform == 'win32'
pynvml==11.4.1
pyyaml
2 changes: 2 additions & 0 deletions requirements/common_gpu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nvgpu; sys_platform != 'win32'
nvgpu==0.8.0; sys_platform == 'win32'
1 change: 0 additions & 1 deletion requirements/production.txt

This file was deleted.

3 changes: 0 additions & 3 deletions requirements/torch_cu117_linux.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
--extra-index-url https://download.pytorch.org/whl/cu117
cython
wheel
pillow==9.3.0
torch==2.0.0+cu117; sys_platform == 'linux'
torchvision==0.15.1+cu117; sys_platform == 'linux'
torchtext==0.15.1; sys_platform == 'linux'
Expand Down
3 changes: 0 additions & 3 deletions requirements/torch_cu118_linux.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
--extra-index-url https://download.pytorch.org/whl/cu118
cython
wheel
pillow==9.3.0
torch==2.0.0+cu118; sys_platform == 'linux'
torchvision==0.15.1+cu118; sys_platform == 'linux'
torchtext==0.15.1; sys_platform == 'linux'
Expand Down
3 changes: 0 additions & 3 deletions requirements/torch_cu118_windows.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
--extra-index-url https://download.pytorch.org/whl/cu118
cython
wheel
pillow==9.3.0
torch==2.0.0+cu118; sys_platform == 'linux'
torchvision==0.15.1+cu118; sys_platform == 'linux'
torchtext==0.15.1; sys_platform == 'linux'
Expand Down
3 changes: 0 additions & 3 deletions requirements/torch_linux.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
--extra-index-url https://download.pytorch.org/whl/cpu
cython
wheel
pillow==9.3.0
torch==2.0.0+cpu; sys_platform == 'linux'
torchvision==0.15.1+cpu; sys_platform == 'linux'
torchtext==0.15.1; sys_platform == 'linux'
Expand Down
2 changes: 0 additions & 2 deletions requirements/torch_windows.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pip install torch torchvision torchaudio
wheel
torch==2.0.0; sys_platform == 'win32'
torchvision==0.15.1; sys_platform == 'win32'
torchtext==0.15.1; sys_platform == 'win32'
torchaudio==2.0.1; sys_platform == 'win32'
pillow==9.3.0
21 changes: 13 additions & 8 deletions ts_scripts/install_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,22 @@ def install_python_packages(self, cuda_version, requirements_file_path, nightly)
# as it may reinstall the packages with different versions
os.system("conda install -y conda-build")

self.install_torch_packages(cuda_version)
os.system(f"{sys.executable} -m pip install -U pip setuptools")
# developer.txt also installs packages from common.txt
os.system(f"{sys.executable} -m pip install -U -r {requirements_file_path}")
# If conda is available install conda-build package

# TODO: This will run 2 installations for torch but to make this cleaner we should first refactor all of our requirements.txt into just 2 files
# And then make torch an optional dependency for the common.txt
# Install dependencies for GPU
if not isinstance(cuda_version, type(None)):
gpu_requirements_file = os.path.join("requirements", "common_gpu.txt")
os.system(f"{sys.executable} -m pip install -U -r {gpu_requirements_file}")

# Install PyTorch packages
if nightly:
os.system(
f"pip3 install numpy --pre torch[dynamo] torchvision torchtext torchaudio --force-reinstall --extra-index-url https://download.pytorch.org/whl/nightly/{cuda_version}"
f"pip3 install numpy --pre torch torchvision torchtext torchaudio --force-reinstall --extra-index-url https://download.pytorch.org/whl/nightly/{cuda_version}"
)
else:
self.install_torch_packages(cuda_version)

def install_node_packages(self):
os.system(
Expand Down Expand Up @@ -175,9 +179,10 @@ def install_dependencies(cuda_version=None, nightly=False):

# Sequence of installation to be maintained
system.install_java()
requirements_file_path = "requirements/" + (
"production.txt" if args.environment == "prod" else "developer.txt"
)

requirements_file = "common.txt" if args.environment == "prod" else "developer.txt"
requirements_file_path = os.path.join("requirements", requirements_file)

system.install_python_packages(cuda_version, requirements_file_path, nightly)


Expand Down
3 changes: 2 additions & 1 deletion ts_scripts/sanity_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import sys
from pathlib import Path

import nvgpu
import torch

from ts_scripts import marsgen as mg
Expand Down Expand Up @@ -38,6 +37,8 @@ def validate_model_on_gpu():
# Assumption is -
# 1. GPUs on test setup are only utlizied by torchserve
# 2. Models are successfully UNregistered between subsequent calls
import nvgpu

model_loaded = False
for info in nvgpu.gpu_info():
if info["mem_used"] > 0 and info["mem_used_percent"] > 0.0:
Expand Down

0 comments on commit d6e072a

Please sign in to comment.