test.yaml 11 KB

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