Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fb32f9d

Browse filesBrowse files
committed
docs: Update README
1 parent 43e006a commit fb32f9d
Copy full SHA for fb32f9d

File tree

Expand file treeCollapse file tree

1 file changed

+53
-30
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+53
-30
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+53-30Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,74 +25,80 @@ Documentation is available at [https://llama-cpp-python.readthedocs.io/en/latest
2525

2626
## Installation
2727

28-
Install from PyPI (requires a c compiler):
28+
`llama-cpp-python` can be installed directly from PyPI as a source distribution by running:
2929

3030
```bash
3131
pip install llama-cpp-python
3232
```
3333

34-
The above command will attempt to install the package and build `llama.cpp` from source.
35-
This is the recommended installation method as it ensures that `llama.cpp` is built with the available optimizations for your system.
34+
This will build `llama.cpp` from source using cmake and your system's c compiler (required) and install the library alongside this python package.
3635

37-
If you have previously installed `llama-cpp-python` through pip and want to upgrade your version or rebuild the package with different compiler options, please add the following flags to ensure that the package is rebuilt correctly:
36+
If you run into issues during installation add the `--verbose` flag to the `pip install` command to see the full cmake build log.
37+
38+
39+
### Installation with Specific Hardware Acceleration (BLAS, CUDA, Metal, etc)
40+
41+
The default pip install behaviour is to build `llama.cpp` for CPU only on Linux and Windows and use Metal on MacOS.
42+
43+
`llama.cpp` supports a number of hardware acceleration backends depending including OpenBLAS, cuBLAS, CLBlast, HIPBLAS, and Metal.
44+
See the [llama.cpp README](https://github.com/ggerganov/llama.cpp#build) for a full list of supported backends.
45+
46+
All of these backends are supported by `llama-cpp-python` and can be enabled by setting the `CMAKE_ARGS` environment variable before installing.
47+
48+
On Linux and Mac you set the `CMAKE_ARGS` like this:
3849

3950
```bash
40-
pip install llama-cpp-python --force-reinstall --upgrade --no-cache-dir
51+
CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" pip install llama-cpp-python
4152
```
4253

43-
Note: If you are using Apple Silicon (M1) Mac, make sure you have installed a version of Python that supports arm64 architecture. For example:
44-
```
45-
wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
46-
bash Miniforge3-MacOSX-arm64.sh
47-
```
48-
Otherwise, while installing it will build the llama.cpp x86 version which will be 10x slower on Apple Silicon (M1) Mac.
54+
On Windows you can set the `CMAKE_ARGS` like this:
4955

50-
### Installation with Hardware Acceleration
56+
```ps
57+
$env:CMAKE_ARGS = "-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS"
58+
pip install llama-cpp-python
59+
```
5160

52-
`llama.cpp` supports multiple BLAS backends for faster processing.
61+
#### OpenBLAS
5362

5463
To install with OpenBLAS, set the `LLAMA_BLAS and LLAMA_BLAS_VENDOR` environment variables before installing:
5564

5665
```bash
5766
CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" pip install llama-cpp-python
5867
```
5968

69+
#### cuBLAS
70+
6071
To install with cuBLAS, set the `LLAMA_CUBLAS=1` environment variable before installing:
6172

6273
```bash
6374
CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python
6475
```
6576

66-
To install with CLBlast, set the `LLAMA_CLBLAST=1` environment variable before installing:
67-
68-
```bash
69-
CMAKE_ARGS="-DLLAMA_CLBLAST=on" pip install llama-cpp-python
70-
```
77+
#### Metal
7178

7279
To install with Metal (MPS), set the `LLAMA_METAL=on` environment variable before installing:
7380

7481
```bash
7582
CMAKE_ARGS="-DLLAMA_METAL=on" pip install llama-cpp-python
7683
```
7784

78-
To install with hipBLAS / ROCm support for AMD cards, set the `LLAMA_HIPBLAS=on` environment variable before installing:
85+
#### CLBlast
86+
87+
To install with CLBlast, set the `LLAMA_CLBLAST=1` environment variable before installing:
7988

8089
```bash
81-
CMAKE_ARGS="-DLLAMA_HIPBLAS=on" pip install llama-cpp-python
90+
CMAKE_ARGS="-DLLAMA_CLBLAST=on" pip install llama-cpp-python
8291
```
8392

84-
#### Windows remarks
93+
#### hipBLAS
8594

86-
To set the variables `CMAKE_ARGS`in PowerShell, follow the next steps (Example using, OpenBLAS):
95+
To install with hipBLAS / ROCm support for AMD cards, set the `LLAMA_HIPBLAS=on` environment variable before installing:
8796

88-
```ps
89-
$env:CMAKE_ARGS = "-DLLAMA_OPENBLAS=on"
97+
```bash
98+
CMAKE_ARGS="-DLLAMA_HIPBLAS=on" pip install llama-cpp-python
9099
```
91100

92-
Then, call `pip` after setting the variables:
93-
```
94-
pip install llama-cpp-python
95-
```
101+
### Windows Notes
96102

97103
If you run into issues where it complains it can't find `'nmake'` `'?'` or CMAKE_C_COMPILER, you can extract w64devkit as [mentioned in llama.cpp repo](https://github.com/ggerganov/llama.cpp#openblas) and add those manually to CMAKE_ARGS before running `pip` install:
98104
```ps
@@ -102,10 +108,27 @@ $env:CMAKE_ARGS = "-DLLAMA_OPENBLAS=on -DCMAKE_C_COMPILER=C:/w64devkit/bin/gcc.e
102108

103109
See the above instructions and set `CMAKE_ARGS` to the BLAS backend you want to use.
104110

105-
#### MacOS remarks
111+
### MacOS Notes
112+
113+
Note: If you are using Apple Silicon (M1) Mac, make sure you have installed a version of Python that supports arm64 architecture. For example:
114+
```
115+
wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
116+
bash Miniforge3-MacOSX-arm64.sh
117+
```
118+
Otherwise, while installing it will build the llama.cpp x86 version which will be 10x slower on Apple Silicon (M1) Mac.
106119

107120
Detailed MacOS Metal GPU install documentation is available at [docs/install/macos.md](https://llama-cpp-python.readthedocs.io/en/latest/install/macos/)
108121

122+
### Upgrading and Reinstalling
123+
124+
To upgrade or rebuild `llama-cpp-python` add the following flags to ensure that the package is rebuilt correctly:
125+
126+
```bash
127+
pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir
128+
```
129+
130+
This will ensure that all source files are re-built with the most recently set `CMAKE_ARGS` flags.
131+
109132
## High-level API
110133

111134
[API Reference](https://llama-cpp-python.readthedocs.io/en/latest/api-reference/#high-level-api)
@@ -386,7 +409,7 @@ Using pre-built binaries would require disabling these optimizations or supporti
386409
That being said there are some pre-built binaries available through the Releases as well as some community provided wheels.
387410

388411
In the future, I would like to provide pre-built binaries and wheels for common platforms and I'm happy to accept any useful contributions in this area.
389-
This is currently being tracked in #741
412+
This is currently being tracked in [#741](https://github.com/abetlen/llama-cpp-python/issues/741)
390413

391414
### How does this compare to other Python bindings of `llama.cpp`?
392415

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.