"docs/vscode:/vscode.git/clone" did not exist on "a5bba7d234b4e0d82e6a64de82a8497760ed44cf"
gpu.cuda.inc.md 14.3 KB
Newer Older
1
# --8<-- [start:installation]
2

3
vLLM contains pre-compiled C++ and CUDA (12.8) binaries.
4

5
6
# --8<-- [end:installation]
# --8<-- [start:requirements]
7
8
9

- GPU: compute capability 7.0 or higher (e.g., V100, T4, RTX20xx, A100, L4, H100, etc.)

10
11
# --8<-- [end:requirements]
# --8<-- [start:set-up-using-python]
12

13
!!! note
14
    PyTorch installed via `conda` will statically link `NCCL` library, which can cause issues when vLLM tries to use `NCCL`. See <https://github.com/vllm-project/vllm/issues/8420> for more details.
15
16
17

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.

18
Therefore, it is recommended to install vLLM with a **fresh new** 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][build-from-source] for more details.
19

20
21
# --8<-- [end:set-up-using-python]
# --8<-- [start:pre-built-wheels]
22

23
```bash
24
uv pip install vllm --torch-backend=auto
25
26
```

27
28
29
30
31
32
??? console "pip"
    ```bash
    # Install vLLM with CUDA 12.8.
    pip install vllm --extra-index-url https://download.pytorch.org/whl/cu128
    ```

33
34
We recommend leveraging `uv` to [automatically select the appropriate PyTorch index at runtime](https://docs.astral.sh/uv/guides/integration/pytorch/#automatic-backend-selection) by inspecting the installed CUDA driver version via `--torch-backend=auto` (or `UV_TORCH_BACKEND=auto`). To select a specific backend (e.g., `cu126`), set `--torch-backend=cu126` (or `UV_TORCH_BACKEND=cu126`). If this doesn't work, try running `uv self update` to update `uv` first.

35
36
!!! note
    NVIDIA Blackwell GPUs (B200, GB200) require a minimum of CUDA 12.8, so make sure you are installing PyTorch wheels with at least that version. PyTorch itself offers a [dedicated interface](https://pytorch.org/get-started/locally/) to determine the appropriate pip command to run for a given target configuration.
37
38

As of now, vLLM's binaries are compiled with CUDA 12.8 and public PyTorch release versions by default. We also provide vLLM binaries compiled with CUDA 12.6, 11.8, and public PyTorch release versions:
39

40
```bash
41
42
43
44
# Install vLLM with a specific CUDA version (e.g., 11.8 or 12.6).
export VLLM_VERSION=$(curl -s https://api.github.com/repos/vllm-project/vllm/releases/latest | jq -r .tag_name | sed 's/^v//')
export CUDA_VERSION=118 # or 126
uv pip install https://github.com/vllm-project/vllm/releases/download/v${VLLM_VERSION}/vllm-${VLLM_VERSION}+cu${CUDA_VERSION}-cp38-abi3-manylinux1_x86_64.whl --extra-index-url https://download.pytorch.org/whl/cu${CUDA_VERSION}
45
46
```

47
[](){ #install-the-latest-code }
48

49
#### Install the latest code
50

51
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 an x86 platform with CUDA 12 for every commit since `v0.5.3`.
52

53
```bash
Reid's avatar
Reid committed
54
55
56
uv pip install -U vllm \
    --torch-backend=auto \
    --extra-index-url https://wheels.vllm.ai/nightly
57
58
```

59
60
61
62
63
64
??? console "pip"
    ```bash
    pip install -U vllm \
        --pre \
        --extra-index-url https://wheels.vllm.ai/nightly
    ```
65

66
    `--pre` is required for `pip` to consider pre-released versions.
67

68
##### Install specific revisions
69

70
71
If you want to access the wheels for previous commits (e.g. to bisect the behavior change, performance regression), you can specify the commit hash in the URL:

72
```bash
73
export VLLM_COMMIT=72d9c316d3f6ede485146fe5aabd4e61dbc59069 # use full commit hash from the main branch
Reid's avatar
Reid committed
74
75
76
uv pip install vllm \
    --torch-backend=auto \
    --extra-index-url https://wheels.vllm.ai/${VLLM_COMMIT}
77
78
79
80
```

The `uv` approach works for vLLM `v0.6.6` and later and offers an easy-to-remember command. A unique feature of `uv` is that packages in `--extra-index-url` have [higher priority than the default index](https://docs.astral.sh/uv/pip/compatibility/#packages-that-exist-on-multiple-indexes). If the latest public release is `v0.6.6.post1`, `uv`'s behavior allows installing a commit before `v0.6.6.post1` by specifying the `--extra-index-url`. In contrast, `pip` combines packages from `--extra-index-url` and the default index, choosing only the latest version, which makes it difficult to install a development version prior to the released version.

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
??? note "pip"
    If you want to access the wheels for previous commits (e.g. to bisect the behavior change,
    performance regression), due to the limitation of `pip`, you have to specify the full URL of the
    wheel file by embedding the commit hash in the URL:

    ```bash
    export VLLM_COMMIT=33f460b17a54acb3b6cc0b03f4a17876cff5eafd # use full commit hash from the main branch
    pip install https://wheels.vllm.ai/${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 (the wheels listed in the extra index url have correct versions). Although we
    don't support Python 3.8 any more (because PyTorch 2.5 dropped support for Python 3.8), the
    wheels are still built with Python 3.8 ABI to keep the same wheel name as before.

99
100
# --8<-- [end:pre-built-wheels]
# --8<-- [start:build-wheel-from-source]
101

102
#### Set up using Python-only build (without compilation)
103

104
If you only need to change Python code, you can build and install vLLM without compilation. Using `uv pip`'s [`--editable` flag](https://docs.astral.sh/uv/pip/packages/#editable-packages), changes you make to the code will be reflected when you run vLLM:
105

106
```bash
107
108
git clone https://github.com/vllm-project/vllm.git
cd vllm
109
VLLM_USE_PRECOMPILED=1 uv pip install --editable .
110
111
```

112
This command will do the following:
David Xia's avatar
David Xia committed
113

114
1. Look for the current branch in your vLLM clone.
David Xia's avatar
David Xia committed
115
116
117
1. Identify the corresponding base commit in the main branch.
1. Download the pre-built wheel of the base commit.
1. Use its compiled libraries in the installation.
118

119
120
121
!!! note
    1. If you change C++ or kernel code, you cannot use Python-only build; otherwise you will see an import error about library not found or undefined symbol.
    2. If you rebase your dev branch, it is recommended to uninstall vllm and re-run the above command to make sure your libraries are up to date.
122
123

In case you see an error about wheel not found when running the above command, it might be because the commit you based on in the main branch was just merged and the wheel is being built. In this case, you can wait for around an hour to try again, or manually assign the previous commit in the installation using the `VLLM_PRECOMPILED_WHEEL_LOCATION` environment variable.
124

125
```bash
126
127
export VLLM_COMMIT=72d9c316d3f6ede485146fe5aabd4e61dbc59069 # use full commit hash from the main branch
export VLLM_PRECOMPILED_WHEEL_LOCATION=https://wheels.vllm.ai/${VLLM_COMMIT}/vllm-1.0.0.dev-cp38-abi3-manylinux1_x86_64.whl
128
uv pip install --editable .
129
130
```

131
You can find more information about vLLM's wheels in [install-the-latest-code][install-the-latest-code].
132

133
134
135
!!! 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 [install-the-latest-code][install-the-latest-code] for instructions on how to install a specified wheel.
136

137
#### Full build (with compilation)
138
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
```bash
142
143
git clone https://github.com/vllm-project/vllm.git
cd vllm
144
uv pip install -e .
145
146
```

147
148
!!! tip
    Building from source requires a lot of compilation. If you are building from source repeatedly, it's more efficient to cache the compilation results.
149

150
151
    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.
152

153
    When using `ccache` with `pip install -e .`, you should run `CCACHE_NOHASHDIR="true" pip install --no-build-isolation -e .`. This is because `pip` creates a new folder with a random name for each build, preventing `ccache` from recognizing that the same files are being built.
154

155
156
    [sccache](https://github.com/mozilla/sccache) works similarly to `ccache`, but has the capability to utilize caching in remote storage environments.
    The following environment variables can be set to configure the vLLM `sccache` remote: `SCCACHE_BUCKET=vllm-build-sccache SCCACHE_REGION=us-west-2 SCCACHE_S3_NO_CREDENTIALS=1`. We also recommend setting `SCCACHE_IDLE_TIMEOUT=0`.
157

158
!!! note "Faster Kernel Development"
159
    For frequent C++/CUDA kernel changes, after the initial `uv pip install -e .` setup, consider using the [Incremental Compilation Workflow](../../contributing/incremental_build.md) for significantly faster rebuilds of only the modified kernel code.
160

161
##### Use an existing PyTorch installation
162

163
There are scenarios where the PyTorch dependency cannot be easily installed with `uv`, e.g.:
164
165

- Building vLLM with PyTorch nightly or a custom PyTorch build.
166
- 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 `uv pip install --index-url https://download.pytorch.org/whl/nightly/cu128 torch torchvision torchaudio` to [install PyTorch nightly](https://pytorch.org/get-started/locally/) and then build vLLM on top of it.
167

168
169
170
171
172
173
174
175
176
177
178
179
180
To build vLLM using an existing PyTorch installation:

```bash
# install PyTorch first, either from PyPI or from source
git clone https://github.com/vllm-project/vllm.git
cd vllm
python use_existing_torch.py
uv pip install -r requirements/build.txt
uv pip install --no-build-isolation -e .
```

Alternatively: if you are exclusively using `uv` to create and manage virtual environments, it has [a unique mechanism](https://docs.astral.sh/uv/concepts/projects/config/#disabling-build-isolation)
for disabling build isolation for specific packages. vLLM can leverage this mechanism to specify `torch` as the package to disable build isolation for:
181

182
```bash
183
# install PyTorch first, either from PyPI or from source
184
185
git clone https://github.com/vllm-project/vllm.git
cd vllm
186
187
# pip install -e . does not work directly, only uv can do this
uv pip install -e .
188
189
```

190
##### Use the local cutlass for compilation
191
192
193
194

Currently, before starting the build process, vLLM fetches cutlass code from GitHub. However, there may be scenarios where you want to use a local version of cutlass instead.
To achieve this, you can set the environment variable VLLM_CUTLASS_SRC_DIR to point to your local cutlass directory.

195
```bash
196
197
git clone https://github.com/vllm-project/vllm.git
cd vllm
198
VLLM_CUTLASS_SRC_DIR=/path/to/cutlass uv pip install -e .
199
200
```

201
##### Troubleshooting
202
203
204
205

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:

206
```bash
207
export MAX_JOBS=6
208
uv pip install -e .
209
210
211
212
213
214
215
```

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.

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

216
```bash
217
# Use `--ipc=host` to make sure the shared memory is large enough.
Reid's avatar
Reid committed
218
219
220
221
222
docker run \
    --gpus all \
    -it \
    --rm \
    --ipc=host nvcr.io/nvidia/pytorch:23.10-py3
223
224
225
226
```

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.:

227
```bash
228
229
export CUDA_HOME=/usr/local/cuda
export PATH="${CUDA_HOME}/bin:$PATH"
230
231
232
233
```

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

234
```bash
235
236
nvcc --version # verify that nvcc is in your PATH
${CUDA_HOME}/bin/nvcc --version # verify that nvcc is in your CUDA_HOME
237
238
```

239
#### Unsupported OS build
240
241
242
243
244

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.

Simply disable the `VLLM_TARGET_DEVICE` environment variable before installing:

245
```bash
246
export VLLM_TARGET_DEVICE=empty
247
uv pip install -e .
248
```
249

250
251
# --8<-- [end:build-wheel-from-source]
# --8<-- [start:pre-built-images]
252

253
See [deployment-docker-pre-built-image][deployment-docker-pre-built-image] for instructions on using the official Docker image.
254
255
256

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

257
```bash
258
259
260
261
262
263
264
265
export VLLM_COMMIT=33f460b17a54acb3b6cc0b03f4a17876cff5eafd # use full commit hash from the main branch
docker pull public.ecr.aws/q9t5s3a7/vllm-ci-postmerge-repo:${VLLM_COMMIT}
```

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.

The latest code can contain bugs and may not be stable. Please use it with caution.

266
267
# --8<-- [end:pre-built-images]
# --8<-- [start:build-image-from-source]
268

269
See [deployment-docker-build-image-from-source][deployment-docker-build-image-from-source] for instructions on building the Docker image.
270

271
272
# --8<-- [end:build-image-from-source]
# --8<-- [start:supported-features]
273

274
See [feature-x-hardware][feature-x-hardware] compatibility matrix for feature support information.
275
276

# --8<-- [end:supported-features]