"vscode:/vscode.git/clone" did not exist on "648c970ecc19df3a51e52e7c7eb53d980d849da1"
installation.mdx 16.5 KB
Newer Older
1
# Installation Guide
Titus's avatar
Titus committed
2

3
Welcome to the installation guide for the `bitsandbytes` library! This document provides step-by-step instructions to install `bitsandbytes` across various platforms and hardware configurations. The library primarily supports CUDA-based GPUs, but the team is actively working on enabling support for additional backends like AMD ROCm, Intel, and Apple Silicon.
jiqing-feng's avatar
jiqing-feng committed
4

5
6
> [!TIP]
> For a high-level overview of backend support and compatibility, see the [Multi-backend Support](#multi-backend) section.
Younes Belkada's avatar
Younes Belkada committed
7

8
## Table of Contents
9

10
11
12
13
14
15
16
17
18
- [CUDA](#cuda)
  - [Installation via PyPI](#cuda-pip)
  - [Compile from Source](#cuda-compile)
- [Multi-backend Support (Alpha Release)](#multi-backend)
  - [Supported Backends](#multi-backend-supported-backends)
  - [Pre-requisites](#multi-backend-pre-requisites)
  - [Installation](#multi-backend-pip)
  - [Compile from Source](#multi-backend-compile)
- [PyTorch CUDA Versions](#pytorch-cuda-versions)
19

20
## CUDA[[cuda]]
Younes Belkada's avatar
Younes Belkada committed
21

22
`bitsandbytes` is currently only supported on CUDA GPUs for CUDA versions **11.0 - 12.8**. However, there's an ongoing multi-backend effort under development, which is currently in alpha. If you're interested in providing feedback or testing, check out [the multi-backend section below](#multi-backend).
Titus's avatar
Titus committed
23

24
25
### Supported CUDA Configurations[[cuda-pip]]

26
The latest version of the distributed `bitsandbytes` package is built with the following configurations:
27

28
| **OS**      | **CUDA Toolkit** | **Host Compiler**         |
29
|-------------|------------------|----------------------|
30
| **Linux**   | 11.8 - 12.3      | GCC 11.4             |
31
|             | 12.4 - 12.8      | GCC 13.2             |
32
| **Windows** | 11.8 - 12.8      | MSVC 19.42+ (VS2022) |
33

34
For CUDA systems, ensure your hardware meets the following requirements:
35

36
37
38
39
40
| **Feature**                     | **Minimum Hardware Requirement**                              |
|---------------------------------|---------------------------------------------------------------|
| LLM.int8()                      | NVIDIA Turing (RTX 20 series, T4) or newer GPUs               |
| 8-bit optimizers/quantization   | NVIDIA Maxwell (GTX 900 series, TITAN X, M40) or newer GPUs * |
| NF4/FP4 quantization            | NVIDIA Maxwell (GTX 900 series, TITAN X, M40) or newer GPUs * |
Titus's avatar
Titus committed
41

Steven Liu's avatar
Steven Liu committed
42
> [!WARNING]
43
44
45
> `bitsandbytes >= 0.45.0` no longer supports Kepler GPUs.
>
> Support for Maxwell GPUs is deprecated and will be removed in a future release. For the best results, a Turing generation device or newer is recommended.
Younes Belkada's avatar
Younes Belkada committed
46
47
48
49
50

```bash
pip install bitsandbytes
```

51
52
53
54
55
56
57
58
59
### `pip install` pre-built wheel from latest `main` commit

If you would like to use new feature even before they are officially released and help us test them, feel free to install the wheel directly from our CI (*the wheel links will remain stable!*):

<hfoptions id="OS">
<hfoption id="Linux">

```
# Note, if you don't want to reinstall BNBs dependencies, append the `--no-deps` flag!
60
61
62
63
64
65

# x86_64 (most users)
pip install --force-reinstall https://github.com/bitsandbytes-foundation/bitsandbytes/releases/download/continuous-release_main/bitsandbytes-1.33.7.preview-py3-none-manylinux_2_24_x86_64.whl

# ARM/aarch64
pip install --force-reinstall https://github.com/bitsandbytes-foundation/bitsandbytes/releases/download/continuous-release_main/bitsandbytes-1.33.7.preview-py3-none-manylinux_2_24_aarch64.whl
66
67
68
69
70
71
72
```

</hfoption>
<hfoption id="Windows">

```
# Note, if you don't want to reinstall BNBs dependencies, append the `--no-deps` flag!
73
pip install --force-reinstall https://github.com/bitsandbytes-foundation/bitsandbytes/releases/download/continuous-release_main/bitsandbytes-1.33.7.preview-py3-none-win_amd64.whl
74
75
76
77
78
79
80
81
```
</hfoption>
</hfoptions>

### Compile from source[[cuda-compile]]

> [!TIP]
> Don't hesitate to compile from source! The process is pretty straight forward and resilient. This might be needed for older CUDA versions or other less common configurations, which we don't support out of the box due to package size.
82

83
For Linux and Windows systems, compiling from source allows you to customize the build configurations. See below for detailed platform-specific instructions (see the `CMakeLists.txt` if you want to check the specifics and explore some additional options):
84
85
86
87

<hfoptions id="source">
<hfoption id="Linux">

88
To compile from source, you need CMake >= **3.22.1** and Python >= **3.9** installed. Make sure you have a compiler installed to compile C++ (`gcc`, `make`, headers, etc.).
89
90

For example, to install a compiler and CMake on Ubuntu:
Younes Belkada's avatar
Younes Belkada committed
91

Steven Liu's avatar
Steven Liu committed
92
93
94
95
```bash
apt-get install -y build-essential cmake
```

96
You should also install CUDA Toolkit by following the [NVIDIA CUDA Installation Guide for Linux](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html) guide from NVIDIA. The current minimum supported CUDA Toolkit version is **11.8**.
97

Younes Belkada's avatar
Younes Belkada committed
98
```bash
99
git clone https://github.com/bitsandbytes-foundation/bitsandbytes.git && cd bitsandbytes/
100
101
cmake -DCOMPUTE_BACKEND=cuda -S .
make
102
pip install -e .   # `-e` for "editable" install, when developing BNB (otherwise leave that out)
Younes Belkada's avatar
Younes Belkada committed
103
```
Steven Liu's avatar
Steven Liu committed
104
105
106

> [!TIP]
> If you have multiple versions of CUDA installed or installed it in a non-standard location, please refer to CMake CUDA documentation for how to configure the CUDA compiler.
Younes Belkada's avatar
Younes Belkada committed
107
108
109
110

</hfoption>
<hfoption id="Windows">

Steven Liu's avatar
Steven Liu committed
111
Windows systems require Visual Studio with C++ support as well as an installation of the CUDA SDK.
112

113
To compile from source, you need CMake >= **3.22.1** and Python >= **3.9** installed. You should also install CUDA Toolkit by following the [CUDA Installation Guide for Windows](https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html) guide from NVIDIA. The current minimum supported CUDA Toolkit version is **11.8**.
Younes Belkada's avatar
Younes Belkada committed
114
115

```bash
116
git clone https://github.com/bitsandbytes-foundation/bitsandbytes.git && cd bitsandbytes/
117
118
cmake -DCOMPUTE_BACKEND=cuda -S .
cmake --build . --config Release
119
pip install -e .   # `-e` for "editable" install, when developing BNB (otherwise leave that out)
Younes Belkada's avatar
Younes Belkada committed
120
121
```

122
Big thanks to [wkpark](https://github.com/wkpark), [Jamezo97](https://github.com/Jamezo97), [rickardp](https://github.com/rickardp), [akx](https://github.com/akx) for their amazing contributions to make bitsandbytes compatible with Windows.
Younes Belkada's avatar
Younes Belkada committed
123

Titus's avatar
Titus committed
124
</hfoption>
Younes Belkada's avatar
Younes Belkada committed
125
</hfoptions>
Steven Liu's avatar
Steven Liu committed
126

127
### PyTorch CUDA versions[[pytorch-cuda-versions]]
Steven Liu's avatar
Steven Liu committed
128
129
130
131
132
133
134
135
136
137
138

Some bitsandbytes features may need a newer CUDA version than the one currently supported by PyTorch binaries from Conda and pip. In this case, you should follow these instructions to load a precompiled bitsandbytes binary.

1. Determine the path of the CUDA version you want to use. Common paths include:

* `/usr/local/cuda`
* `/usr/local/cuda-XX.X` where `XX.X` is the CUDA version number

Then locally install the CUDA version you need with this script from bitsandbytes:

```bash
139
wget https://raw.githubusercontent.com/bitsandbytes-foundation/bitsandbytes/main/install_cuda.sh
Steven Liu's avatar
Steven Liu committed
140
# Syntax cuda_install CUDA_VERSION INSTALL_PREFIX EXPORT_TO_BASH
141
#   CUDA_VERSION in {118, 120, 121, 122, 123, 124, 125, 126, 128}
Steven Liu's avatar
Steven Liu committed
142
143
#   EXPORT_TO_BASH in {0, 1} with 0=False and 1=True

144
# For example, the following installs CUDA 12.6 to ~/local/cuda-12.6 and exports the path to your .bashrc
Steven Liu's avatar
Steven Liu committed
145

146
bash install_cuda.sh 126 ~/local 1
Steven Liu's avatar
Steven Liu committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
```

2. Set the environment variables `BNB_CUDA_VERSION` and `LD_LIBRARY_PATH` by manually overriding the CUDA version installed by PyTorch.

> [!TIP]
> It is recommended to add the following lines to the `.bashrc` file to make them permanent.

```bash
export BNB_CUDA_VERSION=<VERSION>
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<PATH>
```

For example, to use a local install path:

```bash
162
163
export BNB_CUDA_VERSION=126
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/YOUR_USERNAME/local/cuda-12.6
Steven Liu's avatar
Steven Liu committed
164
165
```

166
3. Now when you launch bitsandbytes with these environment variables, the PyTorch CUDA version is overridden by the new CUDA version (in this example, version 12.6) and a different bitsandbytes library is loaded.
jiqing-feng's avatar
jiqing-feng committed
167

168
## Multi-backend Support (Alpha Release)[[multi-backend]]
169
170

> [!TIP]
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
> This functionality is currently in preview and not yet production-ready. We very much welcome community feedback, contributions and leadership on topics like Apple Silicon as well as other less common accellerators! For more information, see [this guide on multi-backend support](./non_cuda_backends).

**Link to give us feedback** (bugs, install issues, perf results, requests, etc.)**:**

<hfoptions id="platform">
<hfoption id="ROCm">

[**Multi-backend refactor: Alpha release (AMD ROCm ONLY)**](https://github.com/bitsandbytes-foundation/bitsandbytes/discussions/1339)

</hfoption>
<hfoption id="Intel CPU+GPU">

[**Multi-backend refactor: Alpha release (INTEL ONLY)**](https://github.com/bitsandbytes-foundation/bitsandbytes/discussions/1338)

</hfoption>
<hfoption id="Apple Silicon / Metal (MPS)">
jiqing-feng's avatar
jiqing-feng committed
187

188
[**Github Discussion space on coordinating the kickoff of MPS backend development**](https://github.com/bitsandbytes-foundation/bitsandbytes/discussions/1340)
jiqing-feng's avatar
jiqing-feng committed
189

190
191
</hfoption>
</hfoptions>
192

193
### Supported Backends[[multi-backend-supported-backends]]
194

195
196
197
198
199
200
| **Backend** | **Supported Versions** | **Python versions** | **Architecture Support** | **Status** |
|-------------|------------------------|---------------------------|-------------------------|------------|
| **AMD ROCm** | 6.1+                   | 3.10+                     | minimum CDNA - `gfx90a`, RDNA - `gfx1100` | Alpha      |
| **Apple Silicon (MPS)** | WIP                        | 3.10+                     | M1/M2 chips                    | Planned    |
| **Intel CPU** | v2.4.0+ (`ipex`)         | 3.10+                     | Intel CPU | Alpha |
| **Intel GPU** | v2.4.0+ (`ipex`)         | 3.10+                     | Intel GPU | Experimental |
201
| **Ascend NPU** | 2.1.0+ (`torch_npu`)         | 3.10+                     | Ascend NPU | Experimental |
202
203
204
205
206
207
208
209
210
211

For each supported backend, follow the respective instructions below:

### Pre-requisites[[multi-backend-pre-requisites]]

To use bitsandbytes non-CUDA backends, be sure to install:

```
pip install "transformers>=4.45.1"
```
212

213
214
<hfoptions id="backend">
<hfoption id="AMD ROCm">
jiqing-feng's avatar
jiqing-feng committed
215

216
> [!WARNING]
217
> Pre-compiled binaries are only built for ROCm versions `6.1.2`/`6.2.4`/`6.3.2` and `gfx90a`, `gfx942`, `gfx1100` GPU architectures. [Find the pip install instructions here](#multi-backend-pip).
218
219
220
221
>
> Other supported versions that don't come with pre-compiled binaries [can be compiled for with these instructions](#multi-backend-compile).
>
> **Windows is not supported for the ROCm backend**; also not WSL2 to our knowledge.
jiqing-feng's avatar
jiqing-feng committed
222

223
> [!TIP]
224
> If you would like to install ROCm and PyTorch on bare metal, skip the Docker steps and refer to ROCm's official guides at [ROCm installation overview](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/tutorial/install-overview.html#rocm-install-overview) and [Installing PyTorch for ROCm](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/how-to/3rd-party/pytorch-install.html#using-wheels-package) (Step 3 of wheels build for quick installation). Special note: please make sure to get the respective ROCm-specific PyTorch wheel for the installed ROCm version, e.g. `https://download.pytorch.org/whl/nightly/rocm6.2/`!
jiqing-feng's avatar
jiqing-feng committed
225
226

```bash
227
228
229
230
# Create a docker container with latest ROCm image, which includes ROCm libraries
docker pull rocm/dev-ubuntu-22.04:6.1.2-complete
docker run -it --device=/dev/kfd --device=/dev/dri --group-add video rocm/dev-ubuntu-22.04:6.1.2-complete
apt-get update && apt-get install -y git && cd home
jiqing-feng's avatar
jiqing-feng committed
231

232
233
# Install pytorch compatible with above ROCm version
pip install torch --index-url https://download.pytorch.org/whl/rocm6.1/
234
```
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
</hfoption>
<hfoption id="Intel CPU + GPU">

Compatible hardware and functioning `import intel_extension_for_pytorch as ipex` capable environment with Python `3.10` as the minimum requirement.

Please refer to [the official Intel installations instructions](https://intel.github.io/intel-extension-for-pytorch/index.html#installation?platform=cpu&version=v2.4.0%2bcpu&os=linux%2fwsl2) for guidance on how to pip install the necessary `intel_extension_for_pytorch` dependency.

</hfoption>
<hfoption id="Apple Silicon (MPS)">

> [!TIP]
> Apple Silicon support is still a WIP. Please visit and write us in [this Github Discussion space on coordinating the kickoff of MPS backend development](https://github.com/bitsandbytes-foundation/bitsandbytes/discussions/1340) and coordinate a community-led effort to implement this backend.

</hfoption>
</hfoptions>

### Installation

You can install the pre-built wheels for each backend, or compile from source for custom configurations.

#### Pre-built Wheel Installation (recommended)[[multi-backend-pip]]

<hfoptions id="platform">
<hfoption id="Linux">

```
# Note, if you don't want to reinstall BNBs dependencies, append the `--no-deps` flag!
pip install --force-reinstall 'https://github.com/bitsandbytes-foundation/bitsandbytes/releases/download/continuous-release_multi-backend-refactor/bitsandbytes-0.44.1.dev0-py3-none-manylinux_2_24_x86_64.whl'
```

</hfoption>
<hfoption id="Windows">

```
# Note, if you don't want to reinstall BNBs dependencies, append the `--no-deps` flag!
pip install --force-reinstall 'https://github.com/bitsandbytes-foundation/bitsandbytes/releases/download/continuous-release_multi-backend-refactor/bitsandbytes-0.44.1.dev0-py3-none-win_amd64.whl'
```

274
275
276
277
278
279
280
</hfoption>
<hfoption id="Ascend NPU">

Compatible hardware and functioning `import torch_npu` capable environment with Python `3.10` as the minimum requirement.

Please refer to [the official Ascend installations instructions](https://www.hiascend.com/document/detail/zh/Pytorch/60RC3/configandinstg/instg/insg_0001.html) for guidance on how to pip install the necessary `torch_npu` dependency.

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
</hfoption>
<hfoption id="Mac">

> [!WARNING]
> bitsandbytes does not yet support Apple Silicon / Metal with a dedicated backend. However, the build infrastructure is in place and the below pip install will eventually provide Apple Silicon support as it becomes available on the `multi-backend-refactor` branch based on community contributions.

```
# Note, if you don't want to reinstall BNBs dependencies, append the `--no-deps` flag!
pip install --force-reinstall 'https://github.com/bitsandbytes-foundation/bitsandbytes/releases/download/continuous-release_multi-backend-refactor/bitsandbytes-0.44.1.dev0-py3-none-macosx_13_1_arm64.whl'
```

</hfoption>
</hfoptions>

#### Compile from Source[[multi-backend-compile]]

<hfoptions id="backend">
<hfoption id="AMD ROCm">

#### AMD GPU

bitsandbytes is fully supported from ROCm 6.1 onwards (currently in alpha release).

```bash
305
# Install bitsandbytes from source
306
# Clone bitsandbytes repo, ROCm backend is currently enabled on multi-backend-refactor branch
307
git clone -b multi-backend-refactor https://github.com/bitsandbytes-foundation/bitsandbytes.git && cd bitsandbytes/
jiqing-feng's avatar
jiqing-feng committed
308

309
310
311
# Compile & install
apt-get install -y build-essential cmake  # install build tools dependencies, unless present
cmake -DCOMPUTE_BACKEND=hip -S .  # Use -DBNB_ROCM_ARCH="gfx90a;gfx942" to target specific gpu arch
jiqing-feng's avatar
jiqing-feng committed
312
make
313
pip install -e .   # `-e` for "editable" install, when developing BNB (otherwise leave that out)
jiqing-feng's avatar
jiqing-feng committed
314
315
316
```

</hfoption>
317
<hfoption id="Intel CPU + GPU">
jiqing-feng's avatar
jiqing-feng committed
318

319
#### Intel CPU + XPU
jiqing-feng's avatar
jiqing-feng committed
320

321
> [!TIP]
322
> Intel CPU/XPU backend only supports building from source; for now, please follow the instructions below.
jiqing-feng's avatar
jiqing-feng committed
323

324
It does not need compile CPP codes, all required ops are in [intel_extension_for_pytorch](https://pytorch-extension.intel.com/), please follow the instruction to install ipex.
325

326
The below commands are for Linux. For installing on Windows, please adapt the below commands according to the same pattern as described [the section above on compiling from source under the Windows tab](#cuda-compile).
327
328
329

```
pip install intel_extension_for_pytorch
330
git clone --depth 1 -b multi-backend-refactor https://github.com/bitsandbytes-foundation/bitsandbytes.git && cd bitsandbytes/
331
pip install -e .   # `-e` for "editable" install, when developing BNB (otherwise leave that out)
jiqing-feng's avatar
jiqing-feng committed
332
333
```

334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
</hfoption>
<hfoption id="Ascend NPU">

#### Ascend NPU

> [!TIP]
> Ascend NPU backend only supports building from source; for now, please follow the instructions below.


```
# Install bitsandbytes from source
# Clone bitsandbytes repo, Ascend NPU backend is currently enabled on multi-backend-refactor branch
git clone -b multi-backend-refactor https://github.com/bitsandbytes-foundation/bitsandbytes.git && cd bitsandbytes/

# Compile & install
apt-get install -y build-essential cmake  # install build tools dependencies, unless present
cmake -DCOMPUTE_BACKEND=npu -S .
make
pip install -e .   # `-e` for "editable" install, when developing BNB (otherwise leave that out)
```


356
357
358
</hfoption>
<hfoption id="Apple Silicon (MPS)">

359
360
#### Apple Silicon

361
362
WIP

jiqing-feng's avatar
jiqing-feng committed
363
364
</hfoption>
</hfoptions>