Skip to content

Distribute and run LLMs with a single file.

Clarify install/gpu docs/behavior per feedback

Justine Tunney3e8aa78d6677
diff --git a/README.md b/README.md
index 54af00fc..053887fb 100644
--- a/README.md
+++ b/README.md
@@ -265,8 +265,8 @@ when running the above command.
## Gotchas
-On macOS with Apple Silicon you need to have Xcode installed for
-llamafile to be able to bootstrap itself.
+On macOS with Apple Silicon you need to have Xcode Command Line Tools
+installed for llamafile to be able to bootstrap itself.
If you use zsh and have trouble running llamafile, try saying `sh -c
./llamafile`. This is due to a bug that was fixed in zsh 5.9+. The same
@@ -337,20 +337,32 @@ llamafile supports the following CPUs:
## GPU support
-On Apple Silicon, everything should just work if Xcode is installed.
+On Apple Silicon running MacOS, your Metal GPU should just work if the
+Xcode Command Line Tools are installed.
On Windows, GPU should just work so long as (1) you're using our release
-binaries, and (2) you pass the `-ngl 35` flag. You also need an NVIDIA
-graphics card that supports CUDA. There's no support yet for AMD GPUs.
-You can also use CUDA via WSL by enabling [Nvidia CUDA on WSL](https://learn.microsoft.com/en-us/windows/ai/directml/gpu-cuda-in-wsl)
-and running your llamafiles inside of WSL. This will also allow you to use
-llamafiles greater than 4GB on Windows. NOTE: If you have two different GPUs(integrated AMD, and dedicated NVIDIA like a laptop) then you need to add -ngl 35 --gpu NVIDIA
+binaries, and (2) you pass the `-ngl 35` flag. If you only have the
+graphics card drivers installed, then llamafile will use tinyBLAS as its
+math kernel library, which goes slower for batch processing tasks, e.g.
+summarization. In order to get full performance, NVIDIA GPU owners need
+to install both the CUDA SDK and MSVC; whereas, AMD GPU owners need to
+install the ROCm SDK. If llamafile detects the presence of an SDK, then
+it'll compile a native module just for your system that uses either the
+cuBLAS or hipBLAS library. You can also use CUDA via WSL by enabling
+[Nvidia CUDA on
+WSL](https://learn.microsoft.com/en-us/windows/ai/directml/gpu-cuda-in-wsl)
+and running your llamafiles inside of WSL. Using WSL has the added
+benefit of letting you run llamafiles greater than 4GB on Windows.
On Linux, Nvidia cuBLAS GPU support will be compiled on the fly if (1)
you have the `cc` compiler installed, (2) you pass the `-ngl 35` flag to
enable GPU, and (3) the CUDA developer toolkit is installed on your
machine and the `nvcc` compiler is on your path.
+If you have both an AMD GPU *and* an NVIDIA GPU in your machine, then
+you may need to qualify which one you want used, by passing either
+`--gpu amd` or `--gpu nvidia`.
+
In the event that GPU support couldn't be compiled and dynamically
linked on the fly for any reason, llamafile will fall back to CPU
inference.
diff --git a/llamafile/gpu.c b/llamafile/gpu.c
index f941fd94..2a1bfb5e 100644
--- a/llamafile/gpu.c
+++ b/llamafile/gpu.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <limits.h>
#include "llama.cpp/ggml-cuda.h"
+#include "llamafile/log.h"
#include "llama.cpp/ggml-metal.h"
bool FLAG_nogpu;
@@ -61,17 +62,27 @@ bool llamafile_gpu_supported(void) {
* Figures out the GPU story after config is loaded.
*/
int llamafile_gpu_layers(int n_gpu_layers) {
- if (n_gpu_layers > 0) {
- if (!llamafile_gpu_supported()) {
- fprintf(stderr, "fatal error: --n-gpu-layers %d was passed but no gpus were found\n",
- n_gpu_layers);
- exit(1);
- }
- } else if (n_gpu_layers == -1 && ggml_metal_supported()) {
+
+ // if user explicitly passed `--gpu KIND` but didn't specify `-ngl
+ // LAYERS` then assume the user wants their model fully offloaded.
+ if (n_gpu_layers == -1 && FLAG_gpu > 0) {
+ n_gpu_layers = INT_MAX;
+ }
+
+ // Apple Metal is safe enough to enable by default.
+ if (n_gpu_layers == -1 && ggml_metal_supported()) {
n_gpu_layers = 1;
- } else {
+ }
+
+ // make the -ngl flag not break example code when it's impossible
+ // if you want it to be an error just pass --gpu apple/amd/nvidia
+ if (n_gpu_layers > 0 && !llamafile_gpu_supported()) {
+ tinylogf("warning: --n-gpu-layers %d was passed but no GPUs were found;"
+ " falling back to CPU inference\n", n_gpu_layers);
FLAG_gpu = LLAMAFILE_GPU_DISABLE;
+ n_gpu_layers = 0;
}
+
return n_gpu_layers;
}