Skip to content

Commit a3be74a

Browse files
committed
Merge branch 'main' of https://github.com/ollama/ollama into testing
2 parents 9dc3889 + 30a9f06 commit a3be74a

File tree

417 files changed

+178301
-15876
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

417 files changed

+178301
-15876
lines changed

.dockerignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ ollama
33
app
44
macapp
55
dist
6-
llm/llama.cpp
76
.env
87
.cache
98
test_data
10-
llm/build
119
llama/build

.gitattributes

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
llm/ext_server/* linguist-vendored
1+
llama/**/*.cpp linguist-vendored
2+
llama/**/*.hpp linguist-vendored
3+
llama/**/*.h linguist-vendored
4+
llama/**/*.c linguist-vendored
5+
llama/**/*.cu linguist-vendored
6+
llama/**/*.cuh linguist-vendored
7+
llama/**/*.m linguist-vendored
8+
llama/**/*.metal linguist-vendored
9+
210
* text=auto
311
*.go text eol=lf

.github/workflows/release.yaml

Lines changed: 153 additions & 162 deletions
Large diffs are not rendered by default.

.github/workflows/test.yaml

Lines changed: 152 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
name: test
22

3+
env:
4+
ROCM_WINDOWS_URL: https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-24.Q3-WinSvr2022-For-HIP.exe
5+
MSYS2_URL: https://github.com/msys2/msys2-installer/releases/download/2024-07-27/msys2-x86_64-20240727.exe
6+
CUDA_12_WINDOWS_URL: https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_551.61_windows.exe
7+
CUDA_12_WINDOWS_VER: 12.4
8+
39
concurrency:
410
# For PRs, later CI runs preempt previous ones. e.g. a force push on a PR
511
# cancels running CI jobs and starts all new ones.
@@ -21,9 +27,7 @@ jobs:
2127
changes:
2228
runs-on: ubuntu-latest
2329
outputs:
24-
GENERATE: ${{ steps.changes.outputs.GENERATE }}
25-
GENERATE_CUDA: ${{ steps.changes.outputs.GENERATE_CUDA }}
26-
GENERATE_ROCM: ${{ steps.changes.outputs.GENERATE_ROCM }}
30+
RUNNERS: ${{ steps.changes.outputs.RUNNERS }}
2731
steps:
2832
- uses: actions/checkout@v4
2933
with:
@@ -38,52 +42,12 @@ jobs:
3842
}
3943
4044
{
41-
echo GENERATE=$(changed 'llm/llama.cpp' 'llm/patches/**' 'llm/ext_server/**' 'llm/generate/**')
42-
echo GENERATE_CUDA=$(changed 'llm/llama.cpp' 'llm/patches/**' 'llm/ext_server/**' 'llm/generate/**')
43-
echo GENERATE_ROCM=$(changed 'llm/llama.cpp' 'llm/patches/**' 'llm/ext_server/**' 'llm/generate/**')
45+
echo RUNNERS=$(changed 'llama/**')
4446
} >>$GITHUB_OUTPUT
4547
46-
generate:
47-
needs: [changes]
48-
if: ${{ needs.changes.outputs.GENERATE == 'True' }}
49-
strategy:
50-
matrix:
51-
os: [ubuntu-latest, macos-latest, windows-2019]
52-
arch: [amd64, arm64]
53-
exclude:
54-
- os: ubuntu-latest
55-
arch: arm64
56-
- os: windows-2019
57-
arch: arm64
58-
runs-on: ${{ matrix.os }}
59-
env:
60-
GOARCH: ${{ matrix.arch }}
61-
CGO_ENABLED: '1'
62-
steps:
63-
- uses: actions/checkout@v4
64-
- uses: actions/setup-go@v5
65-
with:
66-
go-version-file: go.mod
67-
cache: true
68-
- run: go get ./...
69-
- run: |
70-
$gopath=(get-command go).source | split-path -parent
71-
$gccpath=(get-command gcc).source | split-path -parent
72-
& "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
73-
cd $env:GITHUB_WORKSPACE
74-
$env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
75-
$env:PATH="$gopath;$gccpath;$env:PATH"
76-
echo $env:PATH
77-
go generate -x ./...
78-
if: ${{ startsWith(matrix.os, 'windows-') }}
79-
name: 'Windows Go Generate'
80-
- run: go generate -x ./...
81-
if: ${{ ! startsWith(matrix.os, 'windows-') }}
82-
name: 'Unix Go Generate'
83-
- run: go build .
84-
generate-cuda:
48+
runners-linux-cuda:
8549
needs: [changes]
86-
if: ${{ needs.changes.outputs.GENERATE_CUDA == 'True' }}
50+
if: ${{ needs.changes.outputs.RUNNERS == 'True' }}
8751
strategy:
8852
matrix:
8953
cuda-version:
@@ -93,8 +57,6 @@ jobs:
9357
steps:
9458
- run: |
9559
apt-get update && apt-get install -y git build-essential curl
96-
curl -fsSL https://github.com/Kitware/CMake/releases/download/v3.28.1/cmake-3.28.1-linux-x86_64.tar.gz \
97-
| tar -zx -C /usr --strip-components 1
9860
env:
9961
DEBIAN_FRONTEND: noninteractive
10062
- uses: actions/checkout@v4
@@ -105,12 +67,11 @@ jobs:
10567
- run: go get ./...
10668
- run: |
10769
git config --global --add safe.directory /__w/ollama/ollama
108-
go generate -x ./...
109-
env:
110-
OLLAMA_SKIP_CPU_GENERATE: '1'
111-
generate-rocm:
70+
cores=$(grep '^core id' /proc/cpuinfo |sort -u|wc -l)
71+
make -j $cores cuda_v11
72+
runners-linux-rocm:
11273
needs: [changes]
113-
if: ${{ needs.changes.outputs.GENERATE_ROCM == 'True' }}
74+
if: ${{ needs.changes.outputs.RUNNERS == 'True' }}
11475
strategy:
11576
matrix:
11677
rocm-version:
@@ -120,8 +81,6 @@ jobs:
12081
steps:
12182
- run: |
12283
apt-get update && apt-get install -y git build-essential curl rocm-libs
123-
curl -fsSL https://github.com/Kitware/CMake/releases/download/v3.28.1/cmake-3.28.1-linux-x86_64.tar.gz \
124-
| tar -zx -C /usr --strip-components 1
12584
env:
12685
DEBIAN_FRONTEND: noninteractive
12786
- uses: actions/checkout@v4
@@ -132,86 +91,163 @@ jobs:
13291
- run: go get ./...
13392
- run: |
13493
git config --global --add safe.directory /__w/ollama/ollama
135-
go generate -x ./...
136-
env:
137-
OLLAMA_SKIP_CPU_GENERATE: '1'
94+
cores=$(grep '^core id' /proc/cpuinfo |sort -u|wc -l)
95+
make -j $cores rocm
13896
13997
# ROCm generation step
140-
generate-windows-rocm:
98+
runners-windows-rocm:
14199
needs: [changes]
142-
if: ${{ needs.changes.outputs.GENERATE_ROCM == 'True' }}
100+
if: ${{ needs.changes.outputs.RUNNERS == 'True' }}
143101
runs-on: windows
144102
steps:
145103
- uses: actions/checkout@v4
146104
- uses: actions/setup-go@v5
147105
with:
148106
go-version-file: go.mod
149107
cache: true
150-
- name: 'Install ROCm'
108+
- name: Set make jobs default
109+
run: |
110+
echo "MAKEFLAGS=--jobs=$((Get-ComputerInfo -Property CsProcessors).CsProcessors.NumberOfCores)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
111+
112+
# ROCM installation steps
113+
- name: 'Cache ROCm installer'
114+
id: cache-rocm
115+
uses: actions/cache@v4
116+
with:
117+
path: rocm-install.exe
118+
key: ${{ env.ROCM_WINDOWS_URL }}
119+
- name: 'Conditionally Download ROCm'
120+
if: steps.cache-rocm.outputs.cache-hit != 'true'
151121
run: |
152122
$ErrorActionPreference = "Stop"
153-
write-host "downloading AMD HIP Installer"
154-
Invoke-WebRequest -Uri "https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-24.Q3-WinSvr2022-For-HIP.exe" -OutFile "${env:RUNNER_TEMP}\rocm-install.exe"
155-
write-host "Installing AMD HIP"
156-
Start-Process "${env:RUNNER_TEMP}\rocm-install.exe" -ArgumentList '-install' -NoNewWindow -Wait
157-
write-host "Completed AMD HIP"
123+
Invoke-WebRequest -Uri "${env:ROCM_WINDOWS_URL}" -OutFile "rocm-install.exe"
124+
- name: 'Install ROCm'
125+
run: |
126+
Start-Process "rocm-install.exe" -ArgumentList '-install' -NoNewWindow -Wait
158127
- name: 'Verify ROCm'
159128
run: |
160129
& 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' --version
161-
- run: go get ./...
162-
- run: |
163-
$gopath=(get-command go).source | split-path -parent
164-
& "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
165-
cd $env:GITHUB_WORKSPACE
166-
$env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
167-
$env:PATH="$gopath;$env:PATH"
168-
$env:OLLAMA_SKIP_CPU_GENERATE="1"
169-
$env:HIP_PATH=$(Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | split-path | split-path)
170-
go generate -x ./...
171-
name: go generate
172-
env:
173-
OLLAMA_SKIP_CPU_GENERATE: '1'
130+
echo "HIP_PATH=$(Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | split-path | split-path | select -first 1)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
131+
132+
- name: Add msys paths
133+
run: |
134+
echo "c:\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
135+
echo "C:\msys64\clang64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
136+
- name: Install msys2 tools
137+
run: |
138+
Start-Process "c:\msys64\usr\bin\pacman.exe" -ArgumentList @("-S", "--noconfirm", "mingw-w64-clang-x86_64-gcc-compat", "mingw-w64-clang-x86_64-clang") -NoNewWindow -Wait
139+
140+
- name: make rocm runner
141+
run: |
142+
import-module 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll'
143+
Enter-VsDevShell -vsinstallpath 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise' -skipautomaticlocation -DevCmdArguments '-arch=x64 -no_logo'
144+
if (!(gcc --version | select-string -quiet clang)) { throw "wrong gcc compiler detected - must be clang" }
145+
make -C llama print-HIP_PATH print-HIP_LIB_DIR
146+
make rocm
174147
175148
# CUDA generation step
176-
generate-windows-cuda:
149+
runners-windows-cuda:
177150
needs: [changes]
178-
if: ${{ needs.changes.outputs.GENERATE_CUDA == 'True' }}
151+
if: ${{ needs.changes.outputs.RUNNERS == 'True' }}
179152
runs-on: windows
180153
steps:
181154
- uses: actions/checkout@v4
182155
- uses: actions/setup-go@v5
183156
with:
184157
go-version-file: go.mod
185158
cache: true
186-
- name: 'Install CUDA'
159+
- name: Set make jobs default
160+
run: |
161+
echo "MAKEFLAGS=--jobs=$((Get-ComputerInfo -Property CsProcessors).CsProcessors.NumberOfCores)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
162+
163+
# CUDA installation steps
164+
- name: 'Cache CUDA installer'
165+
id: cache-cuda
166+
uses: actions/cache@v4
167+
with:
168+
path: cuda-install.exe
169+
key: ${{ env.CUDA_12_WINDOWS_URL }}
170+
- name: 'Conditionally Download CUDA'
171+
if: steps.cache-cuda.outputs.cache-hit != 'true'
187172
run: |
188173
$ErrorActionPreference = "Stop"
189-
write-host "downloading CUDA Installer"
190-
Invoke-WebRequest -Uri "https://developer.download.nvidia.com/compute/cuda/11.3.1/local_installers/cuda_11.3.1_465.89_win10.exe" -OutFile "${env:RUNNER_TEMP}\cuda-install.exe"
191-
write-host "Installing CUDA"
192-
Start-Process "${env:RUNNER_TEMP}\cuda-install.exe" -ArgumentList '-s' -NoNewWindow -Wait
193-
write-host "Completed CUDA"
174+
Invoke-WebRequest -Uri "${env:CUDA_12_WINDOWS_URL}" -OutFile "cuda-install.exe"
175+
- name: 'Install CUDA'
176+
run: |
177+
$subpackages = @("cudart", "nvcc", "cublas", "cublas_dev") | foreach-object {"${_}_${{ env.CUDA_12_WINDOWS_VER }}"}
178+
Start-Process "cuda-install.exe" -ArgumentList (@("-s") + $subpackages) -NoNewWindow -Wait
179+
- name: 'Verify CUDA'
180+
run: |
181+
& (resolve-path "c:\Program Files\NVIDIA*\CUDA\v*\bin\nvcc.exe")[0] --version
194182
$cudaPath=((resolve-path "c:\Program Files\NVIDIA*\CUDA\v*\bin\nvcc.exe")[0].path | split-path | split-path)
195183
$cudaVer=($cudaPath | split-path -leaf ) -replace 'v(\d+).(\d+)', '$1_$2'
196-
echo "$cudaPath\bin" >> $env:GITHUB_PATH
197-
echo "CUDA_PATH=$cudaPath" >> $env:GITHUB_ENV
198-
echo "CUDA_PATH_V${cudaVer}=$cudaPath" >> $env:GITHUB_ENV
199-
echo "CUDA_PATH_VX_Y=CUDA_PATH_V${cudaVer}" >> $env:GITHUB_ENV
200-
- name: 'Verify CUDA'
201-
run: nvcc -V
202-
- run: go get ./...
203-
- name: go generate
184+
echo "$cudaPath\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
185+
echo "CUDA_PATH=$cudaPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
186+
echo "CUDA_PATH_V${cudaVer}=$cudaPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
187+
echo "CUDA_PATH_VX_Y=CUDA_PATH_V${cudaVer}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
188+
189+
- name: Add msys paths
190+
run: |
191+
echo "c:\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
192+
echo "C:\msys64\clang64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
193+
- name: Install msys2 tools
194+
run: |
195+
Start-Process "c:\msys64\usr\bin\pacman.exe" -ArgumentList @("-S", "--noconfirm", "mingw-w64-clang-x86_64-gcc-compat", "mingw-w64-clang-x86_64-clang") -NoNewWindow -Wait
196+
- name: make cuda runner
197+
run: |
198+
import-module 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll'
199+
Enter-VsDevShell -vsinstallpath 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise' -skipautomaticlocation -DevCmdArguments '-arch=x64 -no_logo'
200+
if (!(gcc --version | select-string -quiet clang)) { throw "wrong gcc compiler detected - must be clang" }
201+
make cuda_v$(($env:CUDA_PATH | split-path -leaf) -replace 'v(\d+).*', '$1')
202+
203+
runners-cpu:
204+
needs: [changes]
205+
if: ${{ needs.changes.outputs.RUNNERS == 'True' }}
206+
strategy:
207+
matrix:
208+
os: [ubuntu-latest, macos-latest, windows-2019]
209+
arch: [amd64, arm64]
210+
exclude:
211+
- os: ubuntu-latest
212+
arch: arm64
213+
- os: windows-2019
214+
arch: arm64
215+
runs-on: ${{ matrix.os }}
216+
env:
217+
GOARCH: ${{ matrix.arch }}
218+
ARCH: ${{ matrix.arch }}
219+
CGO_ENABLED: '1'
220+
steps:
221+
- uses: actions/checkout@v4
222+
- uses: actions/setup-go@v5
223+
with:
224+
go-version-file: go.mod
225+
cache: true
226+
- name: Add msys paths
227+
if: ${{ startsWith(matrix.os, 'windows-') }}
228+
run: |
229+
echo "c:\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
230+
echo "C:\msys64\clang64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
231+
- name: Install msys2 tools
232+
if: ${{ startsWith(matrix.os, 'windows-') }}
233+
run: |
234+
Start-Process "c:\msys64\usr\bin\pacman.exe" -ArgumentList @("-S", "--noconfirm", "mingw-w64-clang-x86_64-gcc-compat", "mingw-w64-clang-x86_64-clang") -NoNewWindow -Wait
235+
- name: 'Build Windows Go Runners'
236+
if: ${{ startsWith(matrix.os, 'windows-') }}
204237
run: |
205238
$gopath=(get-command go).source | split-path -parent
206-
$cudabin=(get-command nvcc).source | split-path
207-
& "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
208-
cd $env:GITHUB_WORKSPACE
239+
$gccpath=(get-command gcc).source | split-path -parent
240+
import-module 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll'
241+
Enter-VsDevShell -vsinstallpath 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise' -skipautomaticlocation -DevCmdArguments '-arch=x64 -no_logo'
209242
$env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
210-
$env:PATH="$gopath;$cudabin;$env:PATH"
211-
$env:OLLAMA_SKIP_CPU_GENERATE="1"
212-
go generate -x ./...
213-
env:
214-
OLLAMA_SKIP_CPU_GENERATE: '1'
243+
$env:PATH="$gopath;$gccpath;$env:PATH"
244+
echo $env:PATH
245+
if (!(gcc --version | select-string -quiet clang)) { throw "wrong gcc compiler detected - must be clang" }
246+
make -j 4
247+
- name: 'Build Unix Go Runners'
248+
if: ${{ ! startsWith(matrix.os, 'windows-') }}
249+
run: make -j 4
250+
- run: go build .
215251

216252
lint:
217253
strategy:
@@ -245,7 +281,7 @@ jobs:
245281
shell: bash
246282
- uses: golangci/golangci-lint-action@v6
247283
with:
248-
args: --timeout 8m0s -v
284+
args: --timeout 10m0s -v
249285
test:
250286
strategy:
251287
matrix:
@@ -260,9 +296,6 @@ jobs:
260296
env:
261297
GOARCH: ${{ matrix.arch }}
262298
CGO_ENABLED: '1'
263-
OLLAMA_CPU_TARGET: 'static'
264-
OLLAMA_SKIP_CPU_GENERATE: '1'
265-
OLLAMA_SKIP_METAL_GENERATE: '1'
266299
steps:
267300
- uses: actions/checkout@v4
268301
with:
@@ -277,6 +310,17 @@ jobs:
277310
arm64) echo ARCH=arm64 ;;
278311
esac >>$GITHUB_ENV
279312
shell: bash
280-
- run: go generate ./...
281313
- run: go build
282314
- run: go test -v ./...
315+
316+
patches:
317+
needs: [changes]
318+
if: ${{ needs.changes.outputs.RUNNERS == 'True' }}
319+
runs-on: ubuntu-latest
320+
steps:
321+
- uses: actions/checkout@v4
322+
with:
323+
submodules: recursive
324+
- name: Verify patches carry all the changes
325+
run: |
326+
make apply-patches sync && git diff --compact-summary --exit-code llama

0 commit comments

Comments
 (0)