nonpytorchcuda.mdx 1.76 KB
Newer Older
Titus's avatar
Titus committed
1
# How to use a CUDA version that is different from PyTorch
2

Titus's avatar
Titus committed
3
Some features of `bitsandbytes` may need a newer CUDA version than regularly supported by PyTorch binaries from conda / pip. In that case you can use the following instructions to load a precompiled `bitsandbytes` binary that works for you.
4
5
6
7
8
9
10
11
12
13
14

## Installing or determining the CUDA installation

Determine the path of the CUDA version that you want to use. Common paths paths are:
```bash
/usr/local/cuda
/usr/local/cuda-XX.X
```

where XX.X is the CUDA version number.

Titus's avatar
Titus committed
15
You can also install CUDA version that you need locally with a script provided by `bitsandbytes` as follows:
16
17

```bash
Titus von Koeller's avatar
Titus von Koeller committed
18
wget https://raw.githubusercontent.com/TimDettmers/bitsandbytes/main/install_cuda.sh
19
20
# Syntax cuda_install CUDA_VERSION INSTALL_PREFIX EXPORT_TO_BASH
#   CUDA_VERSION in {110, 111, 112, 113, 114, 115, 116, 117, 118, 120, 121, 122}
21
#   EXPORT_TO_BASH in {0, 1} with 0=False and 1=True
22
23

# For example, the following installs CUDA 11.7 to ~/local/cuda-11.7 and exports the path to your .bashrc
24
25

bash cuda_install.sh 117 ~/local 1
26
27
```

Titus's avatar
Titus committed
28
## Setting the environmental variables `BNB_CUDA_VERSION`, and `LD_LIBRARY_PATH`
29
30
31
32

To manually override the PyTorch installed CUDA version you need to set to variable, like so:

```bash
33
export BNB_CUDA_VERSION=<VERSION>
34
35
36
37
38
39
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<PATH>
```

For example, to use the local install path from above:

```bash
40
export BNB_CUDA_VERSION=117
41
42
43
44
45
46
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/tim/local/cuda-11.7
```

It is best to add these lines to the `.bashrc` file to make them permanent.

If you now launch bitsandbytes with these environmental variables the PyTorch CUDA version will be overridden by the new CUDA version and a different bitsandbytes library is loaded (in this case version 117).