development.md 4.45 KB
Newer Older
Bruce MacDonald's avatar
Bruce MacDonald committed
1
2
# Development

Jeffrey Morgan's avatar
Jeffrey Morgan committed
3
Install required tools:
Bruce MacDonald's avatar
Bruce MacDonald committed
4

5
- cmake version 3.24 or higher
6
- go version 1.22 or higher
7
8
- gcc version 11.4.0 or higher

9
```bash
10
brew install go cmake gcc
Bruce MacDonald's avatar
Bruce MacDonald committed
11
12
```

13
14
15
Optionally enable debugging and more verbose logging:

```bash
16
# At build time
17
export CGO_CFLAGS="-g"
18
19
20

# At runtime
export OLLAMA_DEBUG=1
21
22
23
```

Get the required libraries and build the native LLM code:
24

25
```bash
26
go generate ./...
27
28
```

29
Then build ollama:
Bruce MacDonald's avatar
Bruce MacDonald committed
30

31
```bash
32
go build .
Bruce MacDonald's avatar
Bruce MacDonald committed
33
34
```

35
Now you can run `ollama`:
Bruce MacDonald's avatar
Bruce MacDonald committed
36

37
```bash
38
./ollama
Bruce MacDonald's avatar
Bruce MacDonald committed
39
```
40

41
### Linux
42

43
#### Linux CUDA (NVIDIA)
44

45
_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!_
46

47
Install `cmake` and `golang` as well as [NVIDIA CUDA](https://developer.nvidia.com/cuda-downloads)
48
development and runtime packages.
49
50
51
52

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
53
libraries, and `CUDACXX` to the location of the nvcc compiler. You can customize
54
set set of target CUDA architectues by setting `CMAKE_CUDA_ARCHITECTURES` (e.g. "50;60;70")
55

56
57
58
59
60
61
Then generate dependencies:

```
go generate ./...
```

62
Then build the binary:
63

64
```
65
go build .
66
67
```

68
69
#### Linux ROCm (AMD)

70
_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!_
71

72
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`.
73
74
75
76
77

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
78
CLBlast install (typically `/usr/lib/cmake/CLBlast`). You can also customize
79
the AMD GPU targets by setting AMDGPU_TARGETS (e.g. `AMDGPU_TARGETS="gfx1101;gfx1102"`)
80

81
82
83
84
```
go generate ./...
```

85
Then build the binary:
86

87
```
88
go build .
89
90
```

91
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.
92

93
94
#### Advanced CPU Settings

95
By default, running `go generate ./...` will compile a few different variations
96
97
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
98
99
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
100
processor, you can set `OLLAMA_CUSTOM_CPU_DEFS` to the llama.cpp flags you would
101
like to use. For example, to compile an optimized binary for an Intel i9-9880H,
102
103
104
you might use:

```
105
106
OLLAMA_CUSTOM_CPU_DEFS="-DLLAMA_AVX=on -DLLAMA_AVX2=on -DLLAMA_F16C=on -DLLAMA_FMA=on" go generate ./...
go build .
107
108
```

109
110
#### Containerized Linux Build

111
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`
112
113
114
115
116
117
118

### Windows

Note: The windows build for Ollama is still under development.

Install required tools:

119
120
- MSVC toolchain - C/C++ and cmake as minimal requirements
- Go version 1.22 or higher
121
- MinGW (pick one variant) with GCC.
122
123
  - [MinGW-w64](https://www.mingw-w64.org/)
  - [MSYS2](https://www.msys2.org/)
124
125
126

```powershell
$env:CGO_ENABLED="1"
127
128
go generate ./...
go build .
129
130
131
132
```

#### Windows CUDA (NVIDIA)

133
In addition to the common Windows development tools described above, install CUDA after installing MSVC.
134

135
- [NVIDIA CUDA](https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html)
136
137
138
139


#### Windows ROCm (AMD Radeon)

140
In addition to the common Windows development tools described above, install AMDs HIP package after installing MSVC.
141

142
- [AMD HIP](https://www.amd.com/en/developer/resources/rocm-hub/hip-sdk.html)
143
144
- [Strawberry Perl](https://strawberryperl.com/)

145
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`).