From d2ad592af46e75413c97c60c7a4b0c87238594bf Mon Sep 17 00:00:00 2001 From: youkaichao Date: Sun, 22 Sep 2024 12:47:54 -0700 Subject: [PATCH] [build] enable existing pytorch (for GH200, aarch64, nightly) (#8713) --- docs/source/getting_started/installation.rst | 23 ++++++++++++++++++++ requirements-common.txt | 2 +- use_existing_torch.py | 18 +++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 use_existing_torch.py diff --git a/docs/source/getting_started/installation.rst b/docs/source/getting_started/installation.rst index 0322503a89a56..afae6e6556021 100644 --- a/docs/source/getting_started/installation.rst +++ b/docs/source/getting_started/installation.rst @@ -72,6 +72,29 @@ You can also build and install vLLM from source: $ cd vllm $ pip install -e . # This may take 5-10 minutes. +.. note:: + + This will uninstall existing PyTorch, and install the version required by vLLM. If you want to use an existing PyTorch installation, there need to be some changes: + + .. code-block:: console + + $ git clone https://github.com/vllm-project/vllm.git + $ cd vllm + $ python use_existing_torch.py + $ pip install -r requirements-build.txt + $ pip install -e . --no-build-isolation + + The differences are: + + - ``python use_existing_torch.py``: This script will remove all the PyTorch versions in the requirements files, so that the existing PyTorch installation will be used. + - ``pip install -r requirements-build.txt``: You need to manually install the requirements for building vLLM. + - ``pip install -e . --no-build-isolation``: You need to disable build isolation, so that the build system can use the existing PyTorch installation. + + This is especially useful when the PyTorch dependency cannot be easily installed via pip, e.g.: + + - build vLLM with PyTorch nightly or a custom PyTorch build. + - build vLLM with aarch64 and cuda (GH200), where the PyTorch wheels are not available on PyPI. Currently, only PyTorch nightly has wheels for aarch64 with CUDA. You can run ``pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu124`` to install PyTorch nightly, and then build vLLM on top of it. + .. note:: vLLM can fully run only on Linux, but you can still build it on other systems (for example, macOS). This build is only for development purposes, allowing for imports and a more convenient dev environment. The binaries will not be compiled and not work on non-Linux systems. You can create such a build with the following commands: diff --git a/requirements-common.txt b/requirements-common.txt index ad53395307ec5..5c617c43829bb 100644 --- a/requirements-common.txt +++ b/requirements-common.txt @@ -18,7 +18,7 @@ prometheus_client >= 0.18.0 prometheus-fastapi-instrumentator >= 7.0.0 tiktoken >= 0.6.0 # Required for DBRX tokenizer lm-format-enforcer == 0.10.6 -outlines >= 0.0.43, < 0.1 # Requires torch >= 2.1.0 +outlines >= 0.0.43, < 0.1 typing_extensions >= 4.10 filelock >= 3.10.4 # filelock starts to support `mode` argument from 3.10.4 partial-json-parser # used for parsing partial JSON outputs diff --git a/use_existing_torch.py b/use_existing_torch.py new file mode 100644 index 0000000000000..e11746459908b --- /dev/null +++ b/use_existing_torch.py @@ -0,0 +1,18 @@ +import glob + +requires_files = glob.glob('requirements*.txt') +requires_files += ["pyproject.toml"] +for file in requires_files: + print(f">>> cleaning {file}") + with open(file, 'r') as f: + lines = f.readlines() + if "torch" in "".join(lines).lower(): + print("removed:") + with open(file, 'w') as f: + for line in lines: + if 'torch' not in line.lower(): + f.write(line) + else: + print(line.strip()) + print(f"<<< done cleaning {file}") + print()