installation.rst 9.9 KB
Newer Older
Zhuohan Li's avatar
Zhuohan Li committed
1
2
.. _installation:

3
============
Woosuk Kwon's avatar
Woosuk Kwon committed
4
5
6
Installation
============

7
vLLM is a Python library that also contains pre-compiled C++ and CUDA (12.1) binaries.
8
9

Requirements
10
===========================
11
12

* OS: Linux
13
* Python: 3.8 -- 3.12
14
* GPU: compute capability 7.0 or higher (e.g., V100, T4, RTX20xx, A100, L4, H100, etc.)
15

16
Install released versions
17
===========================
18

Woosuk Kwon's avatar
Woosuk Kwon committed
19
You can install vLLM using pip:
20
21
22

.. code-block:: console

23
    $ # (Recommended) Create a new conda environment.
24
    $ conda create -n myenv python=3.10 -y
25
26
    $ conda activate myenv

27
    $ # Install vLLM with CUDA 12.1.
28
    $ pip install vllm
29

30
31
32
33
.. note::

    Although we recommend using ``conda`` to create and manage Python environments, it is highly recommended to use ``pip`` to install vLLM. This is because ``pip`` can install ``torch`` with separate library packages like ``NCCL``, while ``conda`` installs ``torch`` with statically linked ``NCCL``. This can cause issues when vLLM tries to use ``NCCL``. See `this issue <https://github.com/vllm-project/vllm/issues/8420>`_ for more details.

34
35
.. note::

36
37
    As of now, vLLM's binaries are compiled with CUDA 12.1 and public PyTorch release versions by default.
    We also provide vLLM binaries compiled with CUDA 11.8 and public PyTorch release versions:
38
39
40
41

    .. code-block:: console

        $ # Install vLLM with CUDA 11.8.
42
        $ export VLLM_VERSION=0.6.1.post1
43
        $ export PYTHON_VERSION=310
44
        $ pip install https://github.com/vllm-project/vllm/releases/download/v${VLLM_VERSION}/vllm-${VLLM_VERSION}+cu118-cp${PYTHON_VERSION}-cp${PYTHON_VERSION}-manylinux1_x86_64.whl --extra-index-url https://download.pytorch.org/whl/cu118
45

46
    In order to be performant, vLLM has to compile many cuda kernels. The compilation unfortunately introduces binary incompatibility with other CUDA versions and PyTorch versions, even for the same PyTorch version with different building configurations.
47

48
    Therefore, it is recommended to install vLLM with a **fresh new** conda environment. If either you have a different CUDA version or you want to use an existing PyTorch installation, you need to build vLLM from source. See below for instructions.
49

50
51
52

.. _install-the-latest-code:

53
Install the latest code
54
=========================
55

56
LLM inference is a fast-evolving field, and the latest code may contain bug fixes, performance improvements, and new features that are not released yet. To allow users to try the latest code without waiting for the next release, vLLM provides wheels for Linux running on x86 platform with cuda 12 for every commit since v0.5.3. You can download and install the latest one with the following command:
57

58
.. code-block:: console
59

60
    $ pip install https://vllm-wheels.s3.us-west-2.amazonaws.com/nightly/vllm-1.0.0.dev-cp38-abi3-manylinux1_x86_64.whl
youkaichao's avatar
youkaichao committed
61

62
If you want to access the wheels for previous commits, you can specify the commit hash in the URL:
youkaichao's avatar
youkaichao committed
63

64
65
66
67
68
69
70
71
72
73
74
75
76
.. code-block:: console

    $ export VLLM_COMMIT=33f460b17a54acb3b6cc0b03f4a17876cff5eafd # use full commit hash from the main branch
    $ pip install https://vllm-wheels.s3.us-west-2.amazonaws.com/${VLLM_COMMIT}/vllm-1.0.0.dev-cp38-abi3-manylinux1_x86_64.whl

Note that the wheels are built with Python 3.8 abi (see `PEP 425 <https://peps.python.org/pep-0425/>`_ for more details about abi), so **they are compatible with Python 3.8 and later**. The version string in the wheel file name (``1.0.0.dev``) is just a placeholder to have a unified URL for the wheels. The actual versions of wheels are contained in the wheel metadata.

Another way to access the latest code is to use the docker images:

.. code-block:: console

    $ export VLLM_COMMIT=33f460b17a54acb3b6cc0b03f4a17876cff5eafd # use full commit hash from the main branch
    $ docker pull public.ecr.aws/q9t5s3a7/vllm-ci-test-repo:${VLLM_COMMIT}
youkaichao's avatar
youkaichao committed
77

78
These docker images are used for CI and testing only, and they are not intended for production use. They will be expired after several days.
youkaichao's avatar
youkaichao committed
79

80
Latest code can contain bugs and may not be stable. Please use it with caution.
81

82
83
84
85
86
.. _build_from_source:

Build from source
==================

87
88
.. _python-only-build:

89
90
Python-only build (without compilation)
----------------------------------------
91

92
If you only need to change Python code, you can simply build vLLM without compilation.
93

94
The first step is to install the latest vLLM wheel:
95
96
97

.. code-block:: console

98
99
100
    pip install https://vllm-wheels.s3.us-west-2.amazonaws.com/nightly/vllm-1.0.0.dev-cp38-abi3-manylinux1_x86_64.whl

You can find more information about vLLM's wheels `above <#install-the-latest-code>`_.
101

102
After verifying that the installation is successful, you can use `the following script <https://github.com/vllm-project/vllm/blob/main/python_only_dev.py>`_:
103
104
105
106
107
108
109

.. code-block:: console

    $ git clone https://github.com/vllm-project/vllm.git
    $ cd vllm
    $ python python_only_dev.py

110
The script will:
111

112
113
114
115
* Find the installed vLLM package in the current environment.
* Copy built files to the current directory.
* Rename the installed vLLM package.
* Symbolically link the current directory to the installed vLLM package.
116

117
Now, you can edit the Python code in the current directory, and the changes will be reflected when you run vLLM.
118

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
Once you have finished editing or want to install another vLLM wheel, you should exit the development environment using `the same script <https://github.com/vllm-project/vllm/blob/main/python_only_dev.py>`_ with the ``--quit-dev``(or ``-q`` for short) flag:

.. code-block:: console

    $ python python_only_dev.py --quit-dev

The script with ``--quit-dev`` flag will:

* Remove the symbolic link from the current directory to the vLLM package.
* Restore the original vLLM package from the backup.

If you update the vLLM wheel and want to rebuild from the source and make further edits, you will need to start `all above <#python-only-build>`_ over again.

.. note::

    There is a possibility that your source code may have a different commit ID compared to the latest vLLM wheel, which could potentially lead to unknown errors.
    It is recommended to use the same commit ID for the source code as the vLLM wheel you have installed. Please refer to `the above section <#install-the-latest-code>`_ for instructions on how to install a specified wheel.
136

137
138
Full build (with compilation)
---------------------------------
Woosuk Kwon's avatar
Woosuk Kwon committed
139

140
If you want to modify C++ or CUDA code, you'll need to build vLLM from source. This can take several minutes: 
141

Woosuk Kwon's avatar
Woosuk Kwon committed
142
143
.. code-block:: console

144
    $ git clone https://github.com/vllm-project/vllm.git
Woosuk Kwon's avatar
Woosuk Kwon committed
145
    $ cd vllm
146
    $ pip install -e .
147

148
.. tip::
149

150
151
152
    Building from source requires a lot of compilation. If you are building from source repeatedly, it's more efficient to cache the compilation results.
    For example, you can install `ccache <https://github.com/ccache/ccache>`_ using ``conda install ccache`` or ``apt install ccache`` . 
    As long as ``which ccache`` command can find the ``ccache`` binary, it will be used automatically by the build system. After the first build, subsequent builds will be much faster.
153
154


155
156
157
Use an existing PyTorch installation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There are scenarios where the PyTorch dependency cannot be easily installed via pip, e.g.:
158

159
160
* Building vLLM with PyTorch nightly or a custom PyTorch build.
* Building vLLM with aarch64 and CUDA (GH200), where the PyTorch wheels are not available on PyPI. Currently, only the 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 <https://pytorch.org/get-started/locally/>`_, and then build vLLM on top of it.
161

162
To build vLLM using an existing PyTorch installation:
163

164
165
166
167
168
169
170
.. 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
171
172


173
174
Troubleshooting
~~~~~~~~~~~~~~~~~
175

176
177
To avoid your system being overloaded, you can limit the number of compilation jobs
to be run simultaneously, via the environment variable ``MAX_JOBS``. For example:
178

179
.. code-block:: console
180

181
182
    $ export MAX_JOBS=6
    $ pip install -e .
183

184
185
This is especially useful when you are building on less powerful machines. For example, when you use WSL it only `assigns 50% of the total memory by default <https://learn.microsoft.com/en-us/windows/wsl/wsl-config#main-wsl-settings>`_, so using ``export MAX_JOBS=1`` can avoid compiling multiple files simultaneously and running out of memory. 
A side effect is a much slower build process. 
186

187
Additionally, if you have trouble building vLLM, we recommend using the NVIDIA PyTorch Docker image.
188

189
.. code-block:: console
190

191
192
    $ # Use `--ipc=host` to make sure the shared memory is large enough.
    $ docker run --gpus all -it --rm --ipc=host nvcr.io/nvidia/pytorch:23.10-py3
193

194
If you don't want to use docker, it is recommended to have a full installation of CUDA Toolkit. You can download and install it from `the official website <https://developer.nvidia.com/cuda-toolkit-archive>`_. After installation, set the environment variable ``CUDA_HOME`` to the installation path of CUDA Toolkit, and make sure that the ``nvcc`` compiler is in your ``PATH``, e.g.:
195

196
.. code-block:: console
197

198
199
    $ export CUDA_HOME=/usr/local/cuda
    $ export PATH="${CUDA_HOME}/bin:$PATH"
200

201
Here is a sanity check to verify that the CUDA Toolkit is correctly installed:
202

203
.. code-block:: console
204

205
206
    $ nvcc --version # verify that nvcc is in your PATH
    $ ${CUDA_HOME}/bin/nvcc --version # verify that nvcc is in your CUDA_HOME
207

208

209
210
Unsupported OS build
----------------------
211

212
vLLM can fully run only on Linux but for development purposes, you can still build it on other systems (for example, macOS), allowing for imports and a more convenient development environment. The binaries will not be compiled and won't work on non-Linux systems. 
213

214
Simply disable the ``VLLM_TARGET_DEVICE`` environment variable before installing:
215

216
.. code-block:: console
217

218
219
    $ export VLLM_TARGET_DEVICE=empty
    $ pip install -e .