Skip to content

Ontwikkeling

Installeer vereisten:

  • Go
  • CMake 3.24 of nieuwer
  • C/C++-compiler: Clang op macOS, Visual Studio 2022 C++-tools op Windows, of GCC/Clang op Linux
  • Ninja in PATH wordt aanbevolen, vooral op Windows

Voor pure Go-iteratie tegen een bestaande native payload, voer je Ollama uit vanaf de root van de repository:

shell
go run . serve

NOTE

Ollama bevat native code die is gecompileerd met CGO. Van tijd tot tijd kunnen deze gegevensstructuren veranderen en kan CGO uit sync raken, wat leidt tot onverwachte crashes. Je kunt een volledige build van de native code forceren door eerst go clean -cache uit te voeren.

Bouwmodel voor native code

Voor een nieuwe checkout, of na het aanpassen van native code, bouw je vanaf de root van de repository. Op macOS arm64 bouwt dit Metal-inferentie. Op alle andere platforms bouwt dit alleen CPU-inferentie. Het bouwt de Go-binair in de root van de repository en installeert de native runtime-payload onder build/lib/ollama.

shell
cmake -B build .
cmake --build build --parallel 8
./ollama serve

Om te installeren in een standaard prefix-indeling:

shell
cmake --install build --prefix /path/to/install

Op alle platforms behalve macOS arm64 selecteer je de GPU-backends expliciet om ze te bouwen:

shell
cmake -B build . -DOLLAMA_LLAMA_BACKENDS="cuda_v13;vulkan"
cmake --build build --parallel 8

Ondersteunde backend-waarden zijn cuda_v12, cuda_v13, rocm_v7_1, rocm_v7_2, vulkan, cuda_jetpack5 en cuda_jetpack6.

Gebruik standaard CMake-architectuuroverrides om GPU-builds te beperken voor lokale hardware:

shell
# CUDA
cmake -B build . -DOLLAMA_LLAMA_BACKENDS=cuda_v13 -DCMAKE_CUDA_ARCHITECTURES=native

# ROCm / HIP
cmake -B build . -DOLLAMA_LLAMA_BACKENDS=rocm_v7_2 -DCMAKE_HIP_ARCHITECTURES=gfx1100

Je kunt GGML-buildopties aanpassen door GGML_*-waarden in te stellen tijdens het configureren. Bijvoorbeeld om CUDA flash attention-kernels uit te schakelen voor lokaal debuggen:

shell
cmake -B build . -DOLLAMA_LLAMA_BACKENDS=cuda_v12 -DGGML_CUDA_FA=OFF

macOS (Apple Silicon)

Aanvullende vereisten:

MLX Metal vereist de Metal-toolchain. Installeer eerst Xcode, daarna:

shell
xcodebuild -downloadComponent MetalToolchain

Windows

Aanvullende vereisten:

Voor Ninja-builds voer je CMake uit vanuit een Developer PowerShell/Opdrachtprompt of een andere shell waarin de Visual Studio-compiler beschikbaar is.

Bouwen voor Vulkan vereist de VULKAN_SDK-omgevingsvariabele:

PowerShell

powershell
$env:VULKAN_SDK="C:\VulkanSDK\<version>"

CMD

cmd
set VULKAN_SDK=C:\VulkanSDK\<version>

Windows (ARM)

Windows ARM ondersteunt momenteel geen aanvullende versnellingsbibliotheken.

Linux

Aanvullende vereisten:

  • (Optioneel) AMD GPU-ondersteuning
  • (Optioneel) NVIDIA GPU-ondersteuning
  • (Optioneel) Vulkan GPU-ondersteuning
    • Vulkan SDK - nuttig voor AMD/Intel GPU's
    • Of installeer via pakketbeheer: sudo apt install vulkan-sdk (Ubuntu/Debian) of sudo dnf install vulkan-sdk (Fedora/CentOS)
  • (Optioneel) MLX-engineondersteuning
    • CUDA 13+ SDK
    • cuDNN 9+
    • OpenBLAS/LAPACK: sudo apt install libopenblas-dev liblapack-dev liblapacke-dev (Ubuntu/Debian)

IMPORTANT

Zorg dat vereisten in PATH staan voordat je CMake uitvoert.

MLX Engine (Optioneel)

De MLX-engine maakt het mogelijk om op safetensor gebaseerde modellen uit te voeren. Op macOS arm64 is MLX standaard ingeschakeld. Op andere platforms worden MLX-backends geselecteerd met OLLAMA_MLX_BACKENDS.

CUDA

Vereist CUDA 13+ en cuDNN 9+.

shell
cmake -B build . -DOLLAMA_MLX_BACKENDS=cuda_v13
cmake --build build --parallel 8

Lokale overschrijvingen van MLX-broncode

Om te bouwen tegen een lokale checkout van MLX en/of MLX-C (nuttig voor ontwikkeling), stel je omgevingsvariabelen in voordat je CMake uitvoert:

shell
export OLLAMA_MLX_SOURCE=/path/to/mlx
export OLLAMA_MLX_C_SOURCE=/path/to/mlx-c

Op macOS arm64:

shell
OLLAMA_MLX_SOURCE=../mlx OLLAMA_MLX_C_SOURCE=../mlx-c cmake -B build .
cmake --build build --parallel 8

Voor CUDA:

powershell
$env:OLLAMA_MLX_SOURCE="../mlx"
$env:OLLAMA_MLX_C_SOURCE="../mlx-c"
cmake -B build . -DOLLAMA_MLX_BACKENDS=cuda_v13
cmake --build build --parallel 8

Docker

shell
docker build .

ROCm

shell
docker build --build-arg FLAVOR=rocm .

Tests uitvoeren

Om tests uit te voeren, gebruik je go test:

shell
go test ./...

Bibliotheekdetectie

Ollama zoekt naar native hulpbinaire bestanden en versnellingsbibliotheken in geïnstalleerde en lokale ontwikkelindelingen:

  • ../lib/ollama voor standaardinstallaties waarbij ollama zich onder bin/ bevindt
  • ./lib/ollama voor Windows-release-payloads en lokale dist-uitvoer
  • . voor macOS-release-artefacten die hulpprogramma's naast ollama plaatsen
  • build/lib/ollama en dist/<platform>/lib/ollama voor lokale ontwikkelbuilds

Als de bibliotheken niet worden gevonden, zal Ollama niet uitvoeren met enige versnellingsbibliotheken.