test.yaml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. name: test
  2. concurrency:
  3. # For PRs, later CI runs preempt previous ones. e.g. a force push on a PR
  4. # cancels running CI jobs and starts all new ones.
  5. #
  6. # For non-PR pushes, concurrency.group needs to be unique for every distinct
  7. # CI run we want to have happen. Use run_id, which in practice means all
  8. # non-PR CI runs will be allowed to run without preempting each other.
  9. group: ${{ github.workflow }}-$${{ github.pull_request.number || github.run_id }}
  10. cancel-in-progress: true
  11. on:
  12. pull_request:
  13. paths:
  14. - '**/*'
  15. - '!docs/**'
  16. - '!README.md'
  17. jobs:
  18. changes:
  19. runs-on: ubuntu-latest
  20. outputs:
  21. GENERATE: ${{ steps.changes.outputs.GENERATE }}
  22. GENERATE_CUDA: ${{ steps.changes.outputs.GENERATE_CUDA }}
  23. GENERATE_ROCM: ${{ steps.changes.outputs.GENERATE_ROCM }}
  24. steps:
  25. - uses: actions/checkout@v4
  26. with:
  27. fetch-depth: 0
  28. - id: changes
  29. run: |
  30. changed() {
  31. git diff-tree -r --no-commit-id --name-only \
  32. $(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}) \
  33. ${{ github.event.pull_request.head.sha }} \
  34. | xargs python3 -c "import sys; from pathlib import Path; print(any(Path(x).match(glob) for x in sys.argv[1:] for glob in '$*'.split(' ')))"
  35. }
  36. {
  37. echo GENERATE=$(changed 'llm/llama.cpp' 'llm/patches/**' 'llm/ext_server/**' 'llm/generate/**')
  38. echo GENERATE_CUDA=$(changed 'llm/llama.cpp' 'llm/patches/**' 'llm/ext_server/**' 'llm/generate/**')
  39. echo GENERATE_ROCM=$(changed 'llm/llama.cpp' 'llm/patches/**' 'llm/ext_server/**' 'llm/generate/**')
  40. } >>$GITHUB_OUTPUT
  41. generate:
  42. needs: [changes]
  43. if: ${{ needs.changes.outputs.GENERATE == 'True' }}
  44. strategy:
  45. matrix:
  46. os: [ubuntu-latest, macos-latest, windows-2019]
  47. arch: [amd64, arm64]
  48. exclude:
  49. - os: ubuntu-latest
  50. arch: arm64
  51. - os: windows-2019
  52. arch: arm64
  53. runs-on: ${{ matrix.os }}
  54. env:
  55. GOARCH: ${{ matrix.arch }}
  56. steps:
  57. - uses: actions/checkout@v4
  58. - uses: actions/setup-go@v5
  59. with:
  60. go-version-file: go.mod
  61. cache: true
  62. - run: go get ./...
  63. - run: |
  64. $gopath=(get-command go).source | split-path -parent
  65. $gccpath=(get-command gcc).source | split-path -parent
  66. & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
  67. cd $env:GITHUB_WORKSPACE
  68. $env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
  69. $env:PATH="$gopath;$gccpath;$env:PATH"
  70. echo $env:PATH
  71. go generate -x ./...
  72. if: ${{ startsWith(matrix.os, 'windows-') }}
  73. name: 'Windows Go Generate'
  74. - run: go generate -x ./...
  75. if: ${{ ! startsWith(matrix.os, 'windows-') }}
  76. name: 'Unix Go Generate'
  77. - uses: actions/upload-artifact@v4
  78. with:
  79. name: ${{ matrix.os }}-${{ matrix.arch }}-libraries
  80. path: |
  81. llm/build/**/bin/*
  82. llm/build/**/*.a
  83. generate-cuda:
  84. needs: [changes]
  85. if: ${{ needs.changes.outputs.GENERATE_CUDA == 'True' }}
  86. strategy:
  87. matrix:
  88. cuda-version:
  89. - '11.8.0'
  90. runs-on: linux
  91. container: nvidia/cuda:${{ matrix.cuda-version }}-devel-ubuntu20.04
  92. steps:
  93. - run: |
  94. apt-get update && apt-get install -y git build-essential curl
  95. curl -fsSL https://github.com/Kitware/CMake/releases/download/v3.28.1/cmake-3.28.1-linux-x86_64.tar.gz \
  96. | tar -zx -C /usr --strip-components 1
  97. env:
  98. DEBIAN_FRONTEND: noninteractive
  99. - uses: actions/checkout@v4
  100. - uses: actions/setup-go@v4
  101. with:
  102. go-version-file: go.mod
  103. cache: true
  104. - run: go get ./...
  105. - run: |
  106. git config --global --add safe.directory /__w/ollama/ollama
  107. go generate -x ./...
  108. env:
  109. OLLAMA_SKIP_CPU_GENERATE: '1'
  110. - uses: actions/upload-artifact@v4
  111. with:
  112. name: cuda-${{ matrix.cuda-version }}-libraries
  113. path: |
  114. llm/build/**/bin/*
  115. dist/windows-amd64/**
  116. generate-rocm:
  117. needs: [changes]
  118. if: ${{ needs.changes.outputs.GENERATE_ROCM == 'True' }}
  119. strategy:
  120. matrix:
  121. rocm-version:
  122. - '6.1.1'
  123. runs-on: linux
  124. container: rocm/dev-ubuntu-20.04:${{ matrix.rocm-version }}
  125. steps:
  126. - run: |
  127. apt-get update && apt-get install -y git build-essential curl rocm-libs
  128. curl -fsSL https://github.com/Kitware/CMake/releases/download/v3.28.1/cmake-3.28.1-linux-x86_64.tar.gz \
  129. | tar -zx -C /usr --strip-components 1
  130. env:
  131. DEBIAN_FRONTEND: noninteractive
  132. - uses: actions/checkout@v4
  133. - uses: actions/setup-go@v4
  134. with:
  135. go-version-file: go.mod
  136. cache: true
  137. - run: go get ./...
  138. - run: |
  139. git config --global --add safe.directory /__w/ollama/ollama
  140. go generate -x ./...
  141. env:
  142. OLLAMA_SKIP_CPU_GENERATE: '1'
  143. - uses: actions/upload-artifact@v4
  144. with:
  145. name: rocm-${{ matrix.rocm-version }}-libraries
  146. path: |
  147. llm/build/**/bin/*
  148. dist/windows-amd64/**
  149. # ROCm generation step
  150. generate-windows-rocm:
  151. needs: [changes]
  152. if: ${{ needs.changes.outputs.GENERATE_ROCM == 'True' }}
  153. runs-on: windows
  154. steps:
  155. - uses: actions/checkout@v4
  156. - uses: actions/setup-go@v5
  157. with:
  158. go-version-file: go.mod
  159. cache: true
  160. - name: 'Install ROCm'
  161. run: |
  162. $ErrorActionPreference = "Stop"
  163. write-host "downloading AMD HIP Installer"
  164. Invoke-WebRequest -Uri "https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-23.Q4-WinSvr2022-For-HIP.exe" -OutFile "${env:RUNNER_TEMP}\rocm-install.exe"
  165. write-host "Installing AMD HIP"
  166. Start-Process "${env:RUNNER_TEMP}\rocm-install.exe" -ArgumentList '-install' -NoNewWindow -Wait
  167. write-host "Completed AMD HIP"
  168. - name: 'Verify ROCm'
  169. run: |
  170. & 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' --version
  171. - run: go get ./...
  172. - run: |
  173. $gopath=(get-command go).source | split-path -parent
  174. & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
  175. cd $env:GITHUB_WORKSPACE
  176. $env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
  177. $env:PATH="$gopath;$env:PATH"
  178. $env:OLLAMA_SKIP_CPU_GENERATE="1"
  179. $env:HIP_PATH=$(Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | split-path | split-path)
  180. go generate -x ./...
  181. name: go generate
  182. env:
  183. OLLAMA_SKIP_CPU_GENERATE: '1'
  184. # TODO - do we need any artifacts?
  185. # CUDA generation step
  186. generate-windows-cuda:
  187. needs: [changes]
  188. if: ${{ needs.changes.outputs.GENERATE_CUDA == 'True' }}
  189. runs-on: windows
  190. steps:
  191. - uses: actions/checkout@v4
  192. - uses: actions/setup-go@v5
  193. with:
  194. go-version-file: go.mod
  195. cache: true
  196. - name: 'Install CUDA'
  197. run: |
  198. $ErrorActionPreference = "Stop"
  199. write-host "downloading CUDA Installer"
  200. 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"
  201. write-host "Installing CUDA"
  202. Start-Process "${env:RUNNER_TEMP}\cuda-install.exe" -ArgumentList '-s' -NoNewWindow -Wait
  203. write-host "Completed CUDA"
  204. $cudaPath=((resolve-path "c:\Program Files\NVIDIA*\CUDA\v*\bin\nvcc.exe")[0].path | split-path | split-path)
  205. $cudaVer=($cudaPath | split-path -leaf ) -replace 'v(\d+).(\d+)', '$1_$2'
  206. echo "$cudaPath\bin" >> $env:GITHUB_PATH
  207. echo "CUDA_PATH=$cudaPath" >> $env:GITHUB_ENV
  208. echo "CUDA_PATH_V${cudaVer}=$cudaPath" >> $env:GITHUB_ENV
  209. echo "CUDA_PATH_VX_Y=CUDA_PATH_V${cudaVer}" >> $env:GITHUB_ENV
  210. - name: 'Verify CUDA'
  211. run: nvcc -V
  212. - run: go get ./...
  213. - name: go generate
  214. run: |
  215. $gopath=(get-command go).source | split-path -parent
  216. $cudabin=(get-command nvcc).source | split-path
  217. & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
  218. cd $env:GITHUB_WORKSPACE
  219. $env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
  220. $env:PATH="$gopath;$cudabin;$env:PATH"
  221. $env:OLLAMA_SKIP_CPU_GENERATE="1"
  222. go generate -x ./...
  223. env:
  224. OLLAMA_SKIP_CPU_GENERATE: '1'
  225. # TODO - do we need any artifacts?
  226. lint:
  227. strategy:
  228. matrix:
  229. os: [ubuntu-latest, macos-latest, windows-2019]
  230. arch: [amd64, arm64]
  231. exclude:
  232. - os: ubuntu-latest
  233. arch: arm64
  234. - os: windows-2019
  235. arch: arm64
  236. - os: macos-latest
  237. arch: amd64
  238. runs-on: ${{ matrix.os }}
  239. env:
  240. GOARCH: ${{ matrix.arch }}
  241. CGO_ENABLED: '1'
  242. steps:
  243. - uses: actions/checkout@v4
  244. with:
  245. submodules: recursive
  246. - uses: actions/setup-go@v5
  247. with:
  248. go-version-file: go.mod
  249. cache: false
  250. - run: |
  251. case ${{ matrix.arch }} in
  252. amd64) echo ARCH=x86_64 ;;
  253. arm64) echo ARCH=arm64 ;;
  254. esac >>$GITHUB_ENV
  255. shell: bash
  256. - run: |
  257. mkdir -p llm/build/linux/$ARCH/stub/bin
  258. touch llm/build/linux/$ARCH/stub/bin/ollama_llama_server
  259. if: ${{ startsWith(matrix.os, 'ubuntu-') }}
  260. - run: |
  261. mkdir -p llm/build/darwin/$ARCH/stub/bin
  262. touch llm/build/darwin/$ARCH/stub/bin/ollama_llama_server
  263. if: ${{ startsWith(matrix.os, 'macos-') }}
  264. - uses: golangci/golangci-lint-action@v6
  265. with:
  266. args: --timeout 8m0s -v ${{ startsWith(matrix.os, 'windows-') && '' || '--disable gofmt --disable goimports' }}
  267. test:
  268. strategy:
  269. matrix:
  270. os: [ubuntu-latest, macos-latest, windows-2019]
  271. arch: [amd64]
  272. exclude:
  273. - os: ubuntu-latest
  274. arch: arm64
  275. - os: windows-2019
  276. arch: arm64
  277. runs-on: ${{ matrix.os }}
  278. env:
  279. GOARCH: ${{ matrix.arch }}
  280. CGO_ENABLED: '1'
  281. OLLAMA_CPU_TARGET: 'static'
  282. OLLAMA_SKIP_CPU_GENERATE: '1'
  283. OLLAMA_SKIP_METAL_GENERATE: '1'
  284. steps:
  285. - uses: actions/checkout@v4
  286. with:
  287. submodules: recursive
  288. - uses: actions/setup-go@v5
  289. with:
  290. go-version-file: go.mod
  291. cache: true
  292. - run: |
  293. case ${{ matrix.arch }} in
  294. amd64) echo ARCH=x86_64 ;;
  295. arm64) echo ARCH=arm64 ;;
  296. esac >>$GITHUB_ENV
  297. shell: bash
  298. - run: |
  299. mkdir -p llm/build/linux/$ARCH/stub/bin
  300. touch llm/build/linux/$ARCH/stub/bin/ollama_llama_server
  301. if: ${{ startsWith(matrix.os, 'ubuntu-') }}
  302. - run: |
  303. mkdir -p llm/build/darwin/$ARCH/stub/bin
  304. touch llm/build/darwin/$ARCH/stub/bin/ollama_llama_server
  305. if: ${{ startsWith(matrix.os, 'macos-') }}
  306. shell: bash
  307. - run: go generate ./...
  308. - run: go build
  309. - run: go test -v ./...
  310. - uses: actions/upload-artifact@v4
  311. with:
  312. name: ${{ matrix.os }}-binaries
  313. path: ollama