development.md 3.99 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
```

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

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

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

37
```bash
Jeffrey Morgan's avatar
Jeffrey Morgan committed
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
Then generate dependencies:
57

58
59
60
```
go generate ./...
```
61

62
Then build the binary:
63

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

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

John's avatar
John committed
72
Install [CLBlast](https://github.com/CNugteren/CLBlast/blob/master/doc/installation.md) and [ROCm](https://rocm.docs.amd.com/en/latest/deploy/linux/quick_start.html) 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
go generate ./...
83
```
84

85
Then build the binary:
86

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

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
95
96
97
#### Advanced CPU Settings

By default, running `go generate ./...` will compile a few different variations
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
105
106
107
108
you might use:

```
OLLAMA_CUSTOM_CPU_DEFS="-DLLAMA_AVX=on -DLLAMA_AVX2=on -DLLAMA_F16C=on -DLLAMA_FMA=on" go generate ./...
go build .
```

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
119

### Windows

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

Install required tools:

- MSVC toolchain - C/C++ and cmake as minimal requirements
120
- go version 1.22 or higher
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
- MinGW (pick one variant) with GCC.
  - <https://www.mingw-w64.org/>
  - <https://www.msys2.org/>

```powershell
$env:CGO_ENABLED="1"

go generate ./...

go build .
```

#### Windows CUDA (NVIDIA)

In addition to the common Windows development tools described above, install:
136

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