Skip to content

Commit

Permalink
Move Torch-TRT install to file (#2092)
Browse files Browse the repository at this point in the history
Summary:
- Add custom installer support for userbenchmark testing
- Add support for installing Torch-TRT outside of main container installs for nightly runs
- Add necessary hooks and subprocess commands in code

Pull Request resolved: #2092

Reviewed By: aaronenyeshi

Differential Revision: D52266771

Pulled By: xuzhao9

fbshipit-source-id: 369009a5bd1d5681a8aa7f72f736592da952ffda
  • Loading branch information
gs-olive authored and facebook-github-bot committed Dec 18, 2023
1 parent b599ae4 commit 11376ae
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 28 deletions.
10 changes: 10 additions & 0 deletions .github/scripts/userbenchmark/schedule-benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import sys
import os
import subprocess
from pathlib import Path

Expand All @@ -25,6 +26,15 @@ def __exit__(self, exc_type, exc_value, traceback):

def run_userbenchmark(ub_name, dryrun=True):
workdir = REPO_ROOT

# Check if userbenchmark has an installer
candidate_installer_path = os.path.join(workdir, "userbenchmark", ub_name, "install.py")
if os.path.exists(candidate_installer_path):
install_command = [sys.executable, "install.py"]
print(f"Running user benchmark installer: {command}")
if not dryrun:
subprocess.check_call(install_command, cwd=Path(candidate_installer_path).parent.resolve())

command = [sys.executable, "run_benchmark.py", ub_name]
print(f"Running user benchmark command: {command}")
if not dryrun:
Expand Down
44 changes: 44 additions & 0 deletions userbenchmark/torch_trt/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import subprocess

import torch


def install_torch_tensorrt():
# Install Torch-TensorRT with validation
uninstall_torchtrt_cmd = ["pip", "uninstall", "-y", "torch_tensorrt"]
subprocess.check_call(uninstall_torchtrt_cmd)

if torch.version.cuda.startswith("12"):
cuda_index_modifier = "cu121"
elif torch.version.cuda.startswith("11"):
cuda_index_modifier = "cu118"
else:
raise AssertionError(
f"Detected Torch-TRT unsupported CUDA version {torch.version.cuda}"
)

pytorch_nightly_url = (
f"https://download.pytorch.org/whl/nightly/{cuda_index_modifier}"
)
install_torchtrt_cmd = [
"pip",
"install",
"--pre",
"--no-cache-dir",
"torch_tensorrt",
"--extra-index-url",
pytorch_nightly_url,
]
validate_torchtrt_cmd = ["python", "-c", "'import torch_tensorrt'"]

# Install and validate Torch-TensorRT
try:
subprocess.check_call(install_torchtrt_cmd)
subprocess.check_call(validate_torchtrt_cmd)
except subprocess.CalledProcessError:
subprocess.check_call(uninstall_torchtrt_cmd)
print("Failed to install torch-tensorrt, skipping install")


if __name__ == "__main__":
install_torch_tensorrt()
28 changes: 0 additions & 28 deletions utils/cuda_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,6 @@ def install_pytorch_nightly(cuda_version: str, env, dryrun=False):
else:
subprocess.check_call(install_torch_cmd, env=env)

# Install Torch-TensorRT with validation
uninstall_torchtrt_cmd = ["pip", "uninstall", "-y", "torch_tensorrt"]
if dryrun:
print(f"Uninstall torch-tensorrt: {uninstall_torchtrt_cmd}")
else:
subprocess.check_call(uninstall_torchtrt_cmd)

install_torchtrt_cmd = [
"pip",
"install",
"--pre",
"--no-cache-dir",
"torch_tensorrt",
"--extra-index-url",
pytorch_nightly_url,
]
validate_torchtrt_cmd = ["python", "-c", "'import torch_tensorrt'"]
if dryrun:
print(f"Install torch-tensorrt nightly: {install_torchtrt_cmd}")
print(f"Validate torch-tensorrt nightly install: {validate_torchtrt_cmd}")
else:
try:
subprocess.check_call(install_torchtrt_cmd, env=env)
subprocess.check_call(validate_torchtrt_cmd, env=env)
except subprocess.CalledProcessError:
subprocess.check_call(uninstall_torchtrt_cmd, env=env)
print(f"Failed to install torch-tensorrt, skipping install")

def install_torch_deps(cuda_version: str):
# install magma
magma_pkg = CUDA_VERSION_MAP[cuda_version]["magma_version"]
Expand Down

0 comments on commit 11376ae

Please sign in to comment.