2023-06-27 17:46:46 +00:00
# Development
2023-07-07 16:59:24 +00:00
Install required tools:
2023-06-27 17:46:46 +00:00
2023-09-12 15:04:35 +00:00
- cmake version 3.24 or higher
2024-03-07 15:39:49 +00:00
- go version 1.22 or higher
2023-09-12 15:04:35 +00:00
- gcc version 11.4.0 or higher
2024-05-23 21:24:07 +00:00
### MacOS
2023-10-01 18:51:01 +00:00
```bash
2023-08-30 20:35:03 +00:00
brew install go cmake gcc
2023-06-27 17:46:46 +00:00
```
2023-12-22 16:47:18 +00:00
Optionally enable debugging and more verbose logging:
```bash
2024-01-18 18:52:01 +00:00
# At build time
2023-12-22 16:47:18 +00:00
export CGO_CFLAGS="-g"
2024-01-18 18:52:01 +00:00
# At runtime
export OLLAMA_DEBUG=1
2023-12-22 16:47:18 +00:00
```
Get the required libraries and build the native LLM code:
2023-07-21 20:36:36 +00:00
2023-10-01 18:51:01 +00:00
```bash
2024-04-09 22:57:45 +00:00
go generate ./...
2023-07-21 20:36:36 +00:00
```
2024-04-09 22:57:45 +00:00
Then build ollama:
2023-06-27 17:46:46 +00:00
2023-10-01 18:51:01 +00:00
```bash
2024-04-09 22:57:45 +00:00
go build .
2023-06-27 17:46:46 +00:00
```
2024-04-09 22:57:45 +00:00
Now you can run `ollama` :
2023-06-27 17:46:46 +00:00
2023-10-01 18:51:01 +00:00
```bash
2024-04-09 22:57:45 +00:00
./ollama
2023-06-27 17:46:46 +00:00
```
2023-09-12 15:04:35 +00:00
2023-12-24 17:02:18 +00:00
### Linux
2023-09-12 15:04:35 +00:00
2023-12-24 17:02:18 +00:00
#### Linux CUDA (NVIDIA)
2023-12-14 01:26:47 +00:00
2024-03-07 15:39:49 +00:00
_Your operating system distribution may already have packages for NVIDIA CUDA. Distro packages are often preferable, but instructions are distro-specific. Please consult distro-specific docs for dependencies if available!_
2023-12-14 01:26:47 +00:00
2024-01-18 17:44:44 +00:00
Install `cmake` and `golang` as well as [NVIDIA CUDA ](https://developer.nvidia.com/cuda-downloads )
2024-03-07 15:39:49 +00:00
development and runtime packages.
2024-01-18 17:44:44 +00:00
Typically the build scripts will auto-detect CUDA, however, if your Linux distro
or installation approach uses unusual paths, you can specify the location by
specifying an environment variable `CUDA_LIB_DIR` to the location of the shared
2024-03-07 15:39:49 +00:00
libraries, and `CUDACXX` to the location of the nvcc compiler. You can customize
2024-05-01 19:39:11 +00:00
a set of target CUDA architectures by setting `CMAKE_CUDA_ARCHITECTURES` (e.g. "50;60;70")
2024-01-18 17:44:44 +00:00
2024-04-09 22:57:45 +00:00
Then generate dependencies:
```
go generate ./...
```
2023-12-14 01:26:47 +00:00
Then build the binary:
2023-12-24 17:02:18 +00:00
2023-12-14 01:26:47 +00:00
```
2024-04-09 22:57:45 +00:00
go build .
2023-12-14 01:26:47 +00:00
```
2023-12-24 17:02:18 +00:00
#### Linux ROCm (AMD)
2024-03-07 15:39:49 +00:00
_Your operating system distribution may already have packages for AMD ROCm and CLBlast. Distro packages are often preferable, but instructions are distro-specific. Please consult distro-specific docs for dependencies if available!_
2023-12-14 01:26:47 +00:00
2024-03-25 20:32:44 +00:00
Install [CLBlast ](https://github.com/CNugteren/CLBlast/blob/master/doc/installation.md ) and [ROCm ](https://rocm.docs.amd.com/en/latest/ ) development packages first, as well as `cmake` and `golang` .
2024-01-18 17:44:44 +00:00
Typically the build scripts will auto-detect ROCm, however, if your Linux distro
or installation approach uses unusual paths, you can specify the location by
specifying an environment variable `ROCM_PATH` to the location of the ROCm
install (typically `/opt/rocm` ), and `CLBlast_DIR` to the location of the
2024-03-07 15:39:49 +00:00
CLBlast install (typically `/usr/lib/cmake/CLBlast` ). You can also customize
2024-01-21 20:57:13 +00:00
the AMD GPU targets by setting AMDGPU_TARGETS (e.g. `AMDGPU_TARGETS="gfx1101;gfx1102"` )
2023-12-24 17:02:18 +00:00
2024-04-09 22:57:45 +00:00
```
go generate ./...
```
2023-12-14 01:26:47 +00:00
Then build the binary:
2023-12-24 17:02:18 +00:00
2023-12-14 01:26:47 +00:00
```
2024-04-09 22:57:45 +00:00
go build .
2023-12-14 01:26:47 +00:00
```
2024-03-07 15:39:49 +00:00
ROCm requires elevated privileges to access the GPU at runtime. On most distros you can add your user account to the `render` group, or run as root.
2023-12-14 01:26:47 +00:00
2024-01-07 23:48:05 +00:00
#### Advanced CPU Settings
2024-04-09 22:57:45 +00:00
By default, running `go generate ./...` will compile a few different variations
2024-01-07 23:48:05 +00:00
of the LLM library based on common CPU families and vector math capabilities,
including a lowest-common-denominator which should run on almost any 64 bit CPU
2024-03-07 15:39:49 +00:00
somewhat slowly. At runtime, Ollama will auto-detect the optimal variation to
load. If you would like to build a CPU-based build customized for your
2024-01-07 23:48:05 +00:00
processor, you can set `OLLAMA_CUSTOM_CPU_DEFS` to the llama.cpp flags you would
2024-03-07 15:39:49 +00:00
like to use. For example, to compile an optimized binary for an Intel i9-9880H,
2024-01-07 23:48:05 +00:00
you might use:
```
2024-04-09 22:57:45 +00:00
OLLAMA_CUSTOM_CPU_DEFS="-DLLAMA_AVX=on -DLLAMA_AVX2=on -DLLAMA_F16C=on -DLLAMA_FMA=on" go generate ./...
go build .
2024-01-07 23:48:05 +00:00
```
2023-12-24 17:02:18 +00:00
#### Containerized Linux Build
2024-03-07 15:39:49 +00:00
If you have Docker available, you can build linux binaries with `./scripts/build_linux.sh` which has the CUDA and ROCm dependencies included. The resulting binary is placed in `./dist`
2023-12-24 17:02:18 +00:00
### Windows
Note: The windows build for Ollama is still under development.
Install required tools:
2024-03-26 20:23:16 +00:00
- MSVC toolchain - C/C++ and cmake as minimal requirements
- Go version 1.22 or higher
2023-12-24 17:02:18 +00:00
- MinGW (pick one variant) with GCC.
2024-03-26 20:23:16 +00:00
- [MinGW-w64 ](https://www.mingw-w64.org/ )
- [MSYS2 ](https://www.msys2.org/ )
2023-12-24 17:02:18 +00:00
```powershell
$env:CGO_ENABLED="1"
2024-04-09 22:57:45 +00:00
go generate ./...
go build .
2023-12-24 17:02:18 +00:00
```
#### Windows CUDA (NVIDIA)
2024-03-26 20:23:16 +00:00
In addition to the common Windows development tools described above, install CUDA after installing MSVC.
2023-12-14 01:26:47 +00:00
2023-12-24 17:02:18 +00:00
- [NVIDIA CUDA ](https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html )
2024-03-09 19:29:45 +00:00
#### Windows ROCm (AMD Radeon)
2024-03-26 20:23:16 +00:00
In addition to the common Windows development tools described above, install AMDs HIP package after installing MSVC.
2024-03-09 19:29:45 +00:00
2024-03-25 20:32:44 +00:00
- [AMD HIP ](https://www.amd.com/en/developer/resources/rocm-hub/hip-sdk.html )
2024-03-26 20:23:16 +00:00
- [Strawberry Perl ](https://strawberryperl.com/ )
2024-05-01 19:39:11 +00:00
Lastly, add `ninja.exe` included with MSVC to the system path (e.g. `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja` ).