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

Michael Yang's avatar
Michael Yang committed
3
Install prerequisites:
4

Michael Yang's avatar
Michael Yang committed
5
- [Go](https://go.dev/doc/install)
6
- C/C++ Compiler e.g. Clang on macOS, [TDM-GCC](https://github.com/jmeubank/tdm-gcc/releases/latest) (Windows amd64) or [llvm-mingw](https://github.com/mstorsjo/llvm-mingw) (Windows arm64), GCC/Clang on Linux.
7

Michael Yang's avatar
Michael Yang committed
8
Then build and run Ollama from the root directory of the repository:
9

10
```shell
Michael Yang's avatar
Michael Yang committed
11
go run . serve
12
13
```

Michael Yang's avatar
Michael Yang committed
14
## macOS (Apple Silicon)
15

Michael Yang's avatar
Michael Yang committed
16
macOS Apple Silicon supports Metal which is built-in to the Ollama binary. No additional steps are required.
17

Michael Yang's avatar
Michael Yang committed
18
## macOS (Intel)
19

Michael Yang's avatar
Michael Yang committed
20
Install prerequisites:
21

Michael Yang's avatar
Michael Yang committed
22
- [CMake](https://cmake.org/download/) or `brew install cmake`
23

Michael Yang's avatar
Michael Yang committed
24
Then, configure and build the project:
25

26
```shell
Michael Yang's avatar
Michael Yang committed
27
28
cmake -B build
cmake --build build
29
30
```

Michael Yang's avatar
Michael Yang committed
31
Lastly, run Ollama:
32

33
```shell
Michael Yang's avatar
Michael Yang committed
34
go run . serve
35
36
```

Michael Yang's avatar
Michael Yang committed
37
## Windows
38

Michael Yang's avatar
Michael Yang committed
39
Install prerequisites:
40

Michael Yang's avatar
Michael Yang committed
41
42
43
- [CMake](https://cmake.org/download/)
- [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/) including the Native Desktop Workload
- (Optional) AMD GPU support
Chuanhui Liu's avatar
Chuanhui Liu committed
44
    - [ROCm](https://rocm.docs.amd.com/en/latest/)
Michael Yang's avatar
Michael Yang committed
45
46
47
    - [Ninja](https://github.com/ninja-build/ninja/releases)
- (Optional) NVIDIA GPU support
    - [CUDA SDK](https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64&target_version=11&target_type=exe_network)
48

Michael Yang's avatar
Michael Yang committed
49
Then, configure and build the project:
50

51
```shell
Michael Yang's avatar
Michael Yang committed
52
53
cmake -B build
cmake --build build --config Release
54
55
```

56
57
58
59
60
61
62
63
> [!IMPORTANT]
> Building for ROCm requires additional flags:
> ```
> cmake -B build -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
> cmake --build build --config Release
> ```


Michael Yang's avatar
Michael Yang committed
64
Lastly, run Ollama:
65

66
```shell
Michael Yang's avatar
Michael Yang committed
67
68
go run . serve
```
69

Michael Yang's avatar
Michael Yang committed
70
## Windows (ARM)
71

Daniel Hiltgen's avatar
Daniel Hiltgen committed
72
Windows ARM does not support additional acceleration libraries at this time.  Do not use cmake, simply `go run` or `go build`.
73

Michael Yang's avatar
Michael Yang committed
74
## Linux
75

Michael Yang's avatar
Michael Yang committed
76
Install prerequisites:
77

Michael Yang's avatar
Michael Yang committed
78
79
80
81
82
- [CMake](https://cmake.org/download/) or `sudo apt install cmake` or `sudo dnf install cmake`
- (Optional) AMD GPU support
    - [ROCm](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/install/quick-start.html)
- (Optional) NVIDIA GPU support
    - [CUDA SDK](https://developer.nvidia.com/cuda-downloads)
83

Michael Yang's avatar
Michael Yang committed
84
85
> [!IMPORTANT]
> Ensure prerequisites are in `PATH` before running CMake.
86
87


Michael Yang's avatar
Michael Yang committed
88
Then, configure and build the project:
89

90
```shell
Michael Yang's avatar
Michael Yang committed
91
92
cmake -B build
cmake --build build
93
94
```

Michael Yang's avatar
Michael Yang committed
95
Lastly, run Ollama:
96

97
```shell
Michael Yang's avatar
Michael Yang committed
98
go run . serve
99
100
```

Michael Yang's avatar
Michael Yang committed
101
## Docker
102

103
```shell
Michael Yang's avatar
Michael Yang committed
104
docker build .
105
106
```

Michael Yang's avatar
Michael Yang committed
107
108
### ROCm

109
```shell
Michael Yang's avatar
Michael Yang committed
110
docker build --build-arg FLAVOR=rocm .
111
112
```

Michael Yang's avatar
Michael Yang committed
113
114
115
## Running tests

To run tests, use `go test`:
116

117
```shell
Michael Yang's avatar
Michael Yang committed
118
go test ./...
119
```
120

121
> NOTE: In rare circumstances, you may need to change a package using the new
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
> "synctest" package in go1.24.
>
> If you do not have the "synctest" package enabled, you will not see build or
> test failures resulting from your change(s), if any, locally, but CI will
> break.
>
> If you see failures in CI, you can either keep pushing changes to see if the
> CI build passes, or you can enable the "synctest" package locally to see the
> failures before pushing.
>
> To enable the "synctest" package for testing, run the following command:
>
> ```shell
> GOEXPERIMENT=synctest go test ./...
> ```
>
> If you wish to enable synctest for all go commands, you can set the
> `GOEXPERIMENT` environment variable in your shell profile or by using:
>
> ```shell
> go env -w GOEXPERIMENT=synctest
> ```
>
> Which will enable the "synctest" package for all go commands without needing
> to set it for all shell sessions.
>
> The synctest package is not required for production builds.

150
151
152
153
154
155
156
157
158
## Library detection

Ollama looks for acceleration libraries in the following paths relative to the `ollama` executable:

* `./lib/ollama` (Windows)
* `../lib/ollama` (Linux)
* `.` (macOS)
* `build/lib/ollama` (for development)

Chuanhui Liu's avatar
Chuanhui Liu committed
159
If the libraries are not found, Ollama will not run with any acceleration libraries.