test.yaml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. name: test
  2. env:
  3. ROCM_WINDOWS_URL: https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-24.Q3-WinSvr2022-For-HIP.exe
  4. MSYS2_URL: https://github.com/msys2/msys2-installer/releases/download/2024-07-27/msys2-x86_64-20240727.exe
  5. CUDA_12_WINDOWS_URL: https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_551.61_windows.exe
  6. CUDA_12_WINDOWS_VER: 12.4
  7. concurrency:
  8. # For PRs, later CI runs preempt previous ones. e.g. a force push on a PR
  9. # cancels running CI jobs and starts all new ones.
  10. #
  11. # For non-PR pushes, concurrency.group needs to be unique for every distinct
  12. # CI run we want to have happen. Use run_id, which in practice means all
  13. # non-PR CI runs will be allowed to run without preempting each other.
  14. group: ${{ github.workflow }}-$${{ github.pull_request.number || github.run_id }}
  15. cancel-in-progress: true
  16. on:
  17. pull_request:
  18. paths:
  19. - '**/*'
  20. - '!docs/**'
  21. - '!README.md'
  22. jobs:
  23. changes:
  24. runs-on: ubuntu-latest
  25. outputs:
  26. RUNNERS: ${{ steps.changes.outputs.RUNNERS }}
  27. steps:
  28. - uses: actions/checkout@v4
  29. with:
  30. fetch-depth: 0
  31. - id: changes
  32. run: |
  33. changed() {
  34. git diff-tree -r --no-commit-id --name-only \
  35. $(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}) \
  36. ${{ github.event.pull_request.head.sha }} \
  37. | 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(' ')))"
  38. }
  39. {
  40. echo RUNNERS=$(changed 'llama/**')
  41. } >>$GITHUB_OUTPUT
  42. runners-linux-cuda:
  43. needs: [changes]
  44. if: ${{ needs.changes.outputs.RUNNERS == 'True' }}
  45. strategy:
  46. matrix:
  47. cuda-version:
  48. - '11.8.0'
  49. runs-on: linux
  50. container: nvidia/cuda:${{ matrix.cuda-version }}-devel-ubuntu20.04
  51. steps:
  52. - run: |
  53. apt-get update && apt-get install -y git build-essential curl
  54. env:
  55. DEBIAN_FRONTEND: noninteractive
  56. - uses: actions/checkout@v4
  57. - uses: actions/setup-go@v4
  58. with:
  59. go-version-file: go.mod
  60. cache: true
  61. - run: go get ./...
  62. - run: |
  63. git config --global --add safe.directory /__w/ollama/ollama
  64. cores=$(grep '^core id' /proc/cpuinfo |sort -u|wc -l)
  65. make -j $cores cuda_v11
  66. runners-linux-rocm:
  67. needs: [changes]
  68. if: ${{ needs.changes.outputs.RUNNERS == 'True' }}
  69. strategy:
  70. matrix:
  71. rocm-version:
  72. - '6.1.2'
  73. runs-on: linux
  74. container: rocm/dev-ubuntu-20.04:${{ matrix.rocm-version }}
  75. steps:
  76. - run: |
  77. apt-get update && apt-get install -y git build-essential curl rocm-libs
  78. env:
  79. DEBIAN_FRONTEND: noninteractive
  80. - uses: actions/checkout@v4
  81. - uses: actions/setup-go@v4
  82. with:
  83. go-version-file: go.mod
  84. cache: true
  85. - run: go get ./...
  86. - run: |
  87. git config --global --add safe.directory /__w/ollama/ollama
  88. cores=$(grep '^core id' /proc/cpuinfo |sort -u|wc -l)
  89. make -j $cores rocm
  90. # ROCm generation step
  91. runners-windows-rocm:
  92. needs: [changes]
  93. if: ${{ needs.changes.outputs.RUNNERS == 'True' }}
  94. runs-on: windows
  95. steps:
  96. - uses: actions/checkout@v4
  97. - uses: actions/setup-go@v5
  98. with:
  99. go-version-file: go.mod
  100. cache: true
  101. - name: Set make jobs default
  102. run: |
  103. echo "MAKEFLAGS=--jobs=$((Get-ComputerInfo -Property CsProcessors).CsProcessors.NumberOfCores)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
  104. # ROCM installation steps
  105. - name: 'Cache ROCm installer'
  106. id: cache-rocm
  107. uses: actions/cache@v4
  108. with:
  109. path: rocm-install.exe
  110. key: ${{ env.ROCM_WINDOWS_URL }}
  111. - name: 'Conditionally Download ROCm'
  112. if: steps.cache-rocm.outputs.cache-hit != 'true'
  113. run: |
  114. $ErrorActionPreference = "Stop"
  115. Invoke-WebRequest -Uri "${env:ROCM_WINDOWS_URL}" -OutFile "rocm-install.exe"
  116. - name: 'Install ROCm'
  117. run: |
  118. Start-Process "rocm-install.exe" -ArgumentList '-install' -NoNewWindow -Wait
  119. - name: 'Verify ROCm'
  120. run: |
  121. & 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' --version
  122. 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
  123. - name: Add msys paths
  124. run: |
  125. echo "c:\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
  126. echo "C:\msys64\clang64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
  127. - name: Install msys2 tools
  128. run: |
  129. 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
  130. - name: make rocm runner
  131. run: |
  132. import-module 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll'
  133. Enter-VsDevShell -vsinstallpath 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise' -skipautomaticlocation -DevCmdArguments '-arch=x64 -no_logo'
  134. if (!(gcc --version | select-string -quiet clang)) { throw "wrong gcc compiler detected - must be clang" }
  135. make -C llama print-HIP_PATH print-HIP_LIB_DIR
  136. make rocm
  137. # CUDA generation step
  138. runners-windows-cuda:
  139. needs: [changes]
  140. if: ${{ needs.changes.outputs.RUNNERS == 'True' }}
  141. runs-on: windows
  142. steps:
  143. - uses: actions/checkout@v4
  144. - uses: actions/setup-go@v5
  145. with:
  146. go-version-file: go.mod
  147. cache: true
  148. - name: Set make jobs default
  149. run: |
  150. echo "MAKEFLAGS=--jobs=$((Get-ComputerInfo -Property CsProcessors).CsProcessors.NumberOfCores)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
  151. # CUDA installation steps
  152. - name: 'Cache CUDA installer'
  153. id: cache-cuda
  154. uses: actions/cache@v4
  155. with:
  156. path: cuda-install.exe
  157. key: ${{ env.CUDA_12_WINDOWS_URL }}
  158. - name: 'Conditionally Download CUDA'
  159. if: steps.cache-cuda.outputs.cache-hit != 'true'
  160. run: |
  161. $ErrorActionPreference = "Stop"
  162. Invoke-WebRequest -Uri "${env:CUDA_12_WINDOWS_URL}" -OutFile "cuda-install.exe"
  163. - name: 'Install CUDA'
  164. run: |
  165. $subpackages = @("cudart", "nvcc", "cublas", "cublas_dev") | foreach-object {"${_}_${{ env.CUDA_12_WINDOWS_VER }}"}
  166. Start-Process "cuda-install.exe" -ArgumentList (@("-s") + $subpackages) -NoNewWindow -Wait
  167. - name: 'Verify CUDA'
  168. run: |
  169. & (resolve-path "c:\Program Files\NVIDIA*\CUDA\v*\bin\nvcc.exe")[0] --version
  170. $cudaPath=((resolve-path "c:\Program Files\NVIDIA*\CUDA\v*\bin\nvcc.exe")[0].path | split-path | split-path)
  171. $cudaVer=($cudaPath | split-path -leaf ) -replace 'v(\d+).(\d+)', '$1_$2'
  172. echo "$cudaPath\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
  173. echo "CUDA_PATH=$cudaPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
  174. echo "CUDA_PATH_V${cudaVer}=$cudaPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
  175. echo "CUDA_PATH_VX_Y=CUDA_PATH_V${cudaVer}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
  176. - name: Add msys paths
  177. run: |
  178. echo "c:\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
  179. echo "C:\msys64\clang64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
  180. - name: Install msys2 tools
  181. run: |
  182. 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
  183. - name: make cuda runner
  184. run: |
  185. import-module 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll'
  186. Enter-VsDevShell -vsinstallpath 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise' -skipautomaticlocation -DevCmdArguments '-arch=x64 -no_logo'
  187. if (!(gcc --version | select-string -quiet clang)) { throw "wrong gcc compiler detected - must be clang" }
  188. make cuda_v$(($env:CUDA_PATH | split-path -leaf) -replace 'v(\d+).*', '$1')
  189. runners-cpu:
  190. needs: [changes]
  191. if: ${{ needs.changes.outputs.RUNNERS == 'True' }}
  192. strategy:
  193. matrix:
  194. os: [ubuntu-latest, macos-latest, windows-2019]
  195. arch: [amd64, arm64]
  196. exclude:
  197. - os: ubuntu-latest
  198. arch: arm64
  199. - os: windows-2019
  200. arch: arm64
  201. runs-on: ${{ matrix.os }}
  202. env:
  203. GOARCH: ${{ matrix.arch }}
  204. ARCH: ${{ matrix.arch }}
  205. CGO_ENABLED: '1'
  206. steps:
  207. - uses: actions/checkout@v4
  208. - uses: actions/setup-go@v5
  209. with:
  210. go-version-file: go.mod
  211. cache: true
  212. - name: Add msys paths
  213. if: ${{ startsWith(matrix.os, 'windows-') }}
  214. run: |
  215. echo "c:\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
  216. echo "C:\msys64\clang64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
  217. - name: Install msys2 tools
  218. if: ${{ startsWith(matrix.os, 'windows-') }}
  219. run: |
  220. 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
  221. - name: 'Build Windows Go Runners'
  222. if: ${{ startsWith(matrix.os, 'windows-') }}
  223. run: |
  224. $gopath=(get-command go).source | split-path -parent
  225. $gccpath=(get-command gcc).source | split-path -parent
  226. import-module 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll'
  227. Enter-VsDevShell -vsinstallpath 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise' -skipautomaticlocation -DevCmdArguments '-arch=x64 -no_logo'
  228. $env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
  229. $env:PATH="$gopath;$gccpath;$env:PATH"
  230. echo $env:PATH
  231. if (!(gcc --version | select-string -quiet clang)) { throw "wrong gcc compiler detected - must be clang" }
  232. make -j 4
  233. - name: 'Build Unix Go Runners'
  234. if: ${{ ! startsWith(matrix.os, 'windows-') }}
  235. run: make -j 4
  236. - run: go build .
  237. lint:
  238. strategy:
  239. matrix:
  240. os: [ubuntu-latest, macos-latest, windows-2019]
  241. arch: [amd64, arm64]
  242. exclude:
  243. - os: ubuntu-latest
  244. arch: arm64
  245. - os: windows-2019
  246. arch: arm64
  247. - os: macos-latest
  248. arch: amd64
  249. runs-on: ${{ matrix.os }}
  250. env:
  251. GOARCH: ${{ matrix.arch }}
  252. CGO_ENABLED: '1'
  253. steps:
  254. - uses: actions/checkout@v4
  255. with:
  256. submodules: recursive
  257. - uses: actions/setup-go@v5
  258. with:
  259. go-version-file: go.mod
  260. cache: false
  261. - run: |
  262. case ${{ matrix.arch }} in
  263. amd64) echo ARCH=x86_64 ;;
  264. arm64) echo ARCH=arm64 ;;
  265. esac >>$GITHUB_ENV
  266. shell: bash
  267. - uses: golangci/golangci-lint-action@v6
  268. with:
  269. args: --timeout 10m0s -v
  270. test:
  271. strategy:
  272. matrix:
  273. os: [ubuntu-latest, macos-latest, windows-2019]
  274. arch: [amd64]
  275. exclude:
  276. - os: ubuntu-latest
  277. arch: arm64
  278. - os: windows-2019
  279. arch: arm64
  280. runs-on: ${{ matrix.os }}
  281. env:
  282. GOARCH: ${{ matrix.arch }}
  283. CGO_ENABLED: '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=amd64 ;;
  295. arm64) echo ARCH=arm64 ;;
  296. esac >>$GITHUB_ENV
  297. shell: bash
  298. - run: go build
  299. - run: go test -v ./...
  300. patches:
  301. needs: [changes]
  302. if: ${{ needs.changes.outputs.RUNNERS == 'True' }}
  303. runs-on: ubuntu-latest
  304. steps:
  305. - uses: actions/checkout@v4
  306. with:
  307. submodules: recursive
  308. - name: Verify patches carry all the changes
  309. run: |
  310. make apply-patches sync && git diff --compact-summary --exit-code llama