bench.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. # Benchmark
  2. name: Benchmark
  3. on:
  4. workflow_dispatch:
  5. inputs:
  6. gpu-series:
  7. description: 'Azure GPU series to run with'
  8. required: true
  9. type: choice
  10. options:
  11. - Standard_NC4as_T4_v3
  12. - Standard_NC24ads_A100_v4
  13. - Standard_NC80adis_H100_v5
  14. sha:
  15. description: 'Commit SHA1 to build'
  16. required: false
  17. type: string
  18. duration:
  19. description: 'Duration of the bench'
  20. type: string
  21. default: 10m
  22. push:
  23. branches:
  24. - master
  25. paths: ['llama.cpp', 'ggml.c', 'ggml-backend.c', 'ggml-quants.c', '**/*.cu', 'examples/server/*.h*', 'examples/server/*.cpp']
  26. pull_request_target:
  27. types: [opened, synchronize, reopened]
  28. paths: ['llama.cpp', 'ggml.c', 'ggml-backend.c', 'ggml-quants.c', '**/*.cu', 'examples/server/*.h*', 'examples/server/*.cpp']
  29. schedule:
  30. - cron: '04 2 * * *'
  31. concurrency:
  32. group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || github.run_id }}-${{ github.event.inputs.sha }}
  33. cancel-in-progress: true
  34. jobs:
  35. bench-server-baseline:
  36. runs-on: Standard_NC4as_T4_v3
  37. env:
  38. RUNNER_LABEL: Standard_NC4as_T4_v3 # FIXME Do not find a way to not duplicate it
  39. N_USERS: 8
  40. DURATION: 10m
  41. strategy:
  42. matrix:
  43. model: [phi-2]
  44. ftype: [q4_0, q8_0, f16]
  45. include:
  46. - model: phi-2
  47. ftype: q4_0
  48. pr_comment_enabled: "true"
  49. if: |
  50. inputs.gpu-series == 'Standard_NC4as_T4_v3'
  51. || (
  52. github.event_name == 'schedule'
  53. && github.ref_name == 'master'
  54. && github.repository_owner == 'ggerganov'
  55. )
  56. || github.event_name == 'pull_request_target'
  57. || (
  58. github.event_name == 'push'
  59. && github.event.ref == 'refs/heads/master'
  60. && github.repository_owner == 'ggerganov'
  61. )
  62. steps:
  63. - name: Clone
  64. id: checkout
  65. uses: actions/checkout@v4
  66. with:
  67. fetch-depth: 0
  68. ref: ${{ github.event.inputs.sha || github.event.pull_request.head.sha || github.sha || github.head_ref || github.ref_name }}
  69. - name: Install python env
  70. id: pipenv
  71. run: |
  72. cd examples/server/bench
  73. python3 -m venv venv
  74. source venv/bin/activate
  75. pip install -r requirements.txt
  76. - name: Prometheus
  77. id: install_prometheus
  78. run: |
  79. wget --quiet https://github.com/prometheus/prometheus/releases/download/v2.51.0/prometheus-2.51.0.linux-amd64.tar.gz
  80. tar xzf prometheus*.tar.gz --strip-components=1
  81. ./prometheus --config.file=examples/server/bench/prometheus.yml &
  82. while ! nc -z localhost 9090; do
  83. sleep 0.1
  84. done
  85. - name: Set up Go
  86. uses: actions/setup-go@v5
  87. with:
  88. go-version: '1.21'
  89. - name: Install k6 and xk6-sse
  90. id: k6_installation
  91. run: |
  92. cd examples/server/bench
  93. go install go.k6.io/xk6/cmd/xk6@latest
  94. xk6 build master \
  95. --with github.com/phymbert/xk6-sse
  96. - name: Build
  97. id: cmake_build
  98. run: |
  99. set -eux
  100. cmake -B build \
  101. -DGGML_NATIVE=OFF \
  102. -DLLAMA_BUILD_SERVER=ON \
  103. -DLLAMA_CURL=ON \
  104. -DLLAMA_CUBLAS=ON \
  105. -DCUDAToolkit_ROOT=/usr/local/cuda \
  106. -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
  107. -DCMAKE_CUDA_ARCHITECTURES=75 \
  108. -DLLAMA_FATAL_WARNINGS=OFF \
  109. -DLLAMA_ALL_WARNINGS=OFF \
  110. -DCMAKE_BUILD_TYPE=Release;
  111. cmake --build build --config Release -j $(nproc) --target llama-server
  112. - name: Download the dataset
  113. id: download_dataset
  114. run: |
  115. cd examples/server/bench
  116. wget --quiet https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfiltered/resolve/main/ShareGPT_V3_unfiltered_cleaned_split.json
  117. - name: Server bench
  118. id: server_bench
  119. env:
  120. HEAD_REF: ${{ github.head_ref || github.ref_name }}
  121. run: |
  122. set -eux
  123. cd examples/server/bench
  124. source venv/bin/activate
  125. python bench.py \
  126. --runner-label ${{ env.RUNNER_LABEL }} \
  127. --name ${{ github.job }} \
  128. --branch $HEAD_REF \
  129. --commit ${{ github.event.inputs.sha || github.event.pull_request.head.sha || github.sha }} \
  130. --scenario script.js \
  131. --duration ${{ github.event.inputs.duration || env.DURATION }} \
  132. --hf-repo ggml-org/models \
  133. --hf-file ${{ matrix.model }}/ggml-model-${{ matrix.ftype }}.gguf \
  134. --model-path-prefix /models \
  135. --parallel ${{ env.N_USERS }} \
  136. -ngl 33 \
  137. --batch-size 2048 \
  138. --ubatch-size 256 \
  139. --ctx-size 16384 \
  140. --n-prompts 1000 \
  141. --max-prompt-tokens 1024 \
  142. --max-tokens 2048
  143. cat results.github.env >> $GITHUB_ENV
  144. # Remove dataset as we do not want it in the artefact
  145. rm ShareGPT_V3_unfiltered_cleaned_split.json
  146. - uses: actions/upload-artifact@v4
  147. with:
  148. name: bench-server-${{ github.job }}-${{ env.RUNNER_LABEL }}-${{ matrix.model }}-${{ matrix.ftype }}
  149. compression-level: 9
  150. path: |
  151. examples/server/bench/*.jpg
  152. examples/server/bench/*.json
  153. examples/server/bench/*.log
  154. - name: Commit status
  155. uses: Sibz/github-status-action@v1
  156. with:
  157. authToken: ${{secrets.GITHUB_TOKEN}}
  158. sha: ${{ inputs.sha || github.event.pull_request.head.sha || github.sha }}
  159. context: bench-server-${{ github.job }}-${{ env.RUNNER_LABEL }}-${{ matrix.model }}-${{ matrix.ftype }}
  160. description: |
  161. ${{ env.BENCH_RESULTS }}
  162. state: 'success'
  163. - name: Upload benchmark images
  164. uses: devicons/public-upload-to-imgur@v2.2.2
  165. continue-on-error: true # Important as it looks unstable: 503
  166. id: imgur_step
  167. with:
  168. client_id: ${{secrets.IMGUR_CLIENT_ID}}
  169. path: |
  170. examples/server/bench/prompt_tokens_seconds.jpg
  171. examples/server/bench/predicted_tokens_seconds.jpg
  172. examples/server/bench/kv_cache_usage_ratio.jpg
  173. examples/server/bench/requests_processing.jpg
  174. - name: Extract mermaid
  175. id: set_mermaid
  176. run: |
  177. set -eux
  178. cd examples/server/bench
  179. PROMPT_TOKENS_SECONDS=$(cat prompt_tokens_seconds.mermaid)
  180. echo "PROMPT_TOKENS_SECONDS<<EOF" >> $GITHUB_ENV
  181. echo "$PROMPT_TOKENS_SECONDS" >> $GITHUB_ENV
  182. echo "EOF" >> $GITHUB_ENV
  183. PREDICTED_TOKENS_SECONDS=$(cat predicted_tokens_seconds.mermaid)
  184. echo "PREDICTED_TOKENS_SECONDS<<EOF" >> $GITHUB_ENV
  185. echo "$PREDICTED_TOKENS_SECONDS" >> $GITHUB_ENV
  186. echo "EOF" >> $GITHUB_ENV
  187. KV_CACHE_USAGE_RATIO=$(cat kv_cache_usage_ratio.mermaid)
  188. echo "KV_CACHE_USAGE_RATIO<<EOF" >> $GITHUB_ENV
  189. echo "$KV_CACHE_USAGE_RATIO" >> $GITHUB_ENV
  190. echo "EOF" >> $GITHUB_ENV
  191. REQUESTS_PROCESSING=$(cat requests_processing.mermaid)
  192. echo "REQUESTS_PROCESSING<<EOF" >> $GITHUB_ENV
  193. echo "$REQUESTS_PROCESSING" >> $GITHUB_ENV
  194. echo "EOF" >> $GITHUB_ENV
  195. - name: Extract image url
  196. id: extract_image_url
  197. continue-on-error: true
  198. run: |
  199. set -eux
  200. echo "IMAGE_O=${{ fromJSON(steps.imgur_step.outputs.imgur_urls)[0] }}" >> $GITHUB_ENV
  201. echo "IMAGE_1=${{ fromJSON(steps.imgur_step.outputs.imgur_urls)[1] }}" >> $GITHUB_ENV
  202. echo "IMAGE_2=${{ fromJSON(steps.imgur_step.outputs.imgur_urls)[2] }}" >> $GITHUB_ENV
  203. echo "IMAGE_3=${{ fromJSON(steps.imgur_step.outputs.imgur_urls)[3] }}" >> $GITHUB_ENV
  204. - name: Comment PR
  205. uses: mshick/add-pr-comment@v2
  206. id: comment_pr
  207. if: ${{ github.event.pull_request != '' && matrix.pr_comment_enabled == 'true' }}
  208. with:
  209. message-id: bench-server-${{ github.job }}-${{ env.RUNNER_LABEL }}-${{ matrix.model }}-${{ matrix.ftype }}
  210. message: |
  211. <p align="center">
  212. 📈 **llama.cpp server** for _${{ github.job }}_ on _${{ env.RUNNER_LABEL }}_ for `${{ matrix.model }}`-`${{ matrix.ftype }}`: **${{ env.BENCH_ITERATIONS}} iterations** 🚀
  213. </p>
  214. <details>
  215. <summary>Expand details for performance related PR only</summary>
  216. - Concurrent users: ${{ env.N_USERS }}, duration: ${{ github.event.inputs.duration || env.DURATION }}
  217. - HTTP request : avg=${{ env.HTTP_REQ_DURATION_AVG }}ms p(95)=${{ env.HTTP_REQ_DURATION_P_95_ }}ms fails=${{ env.HTTP_REQ_FAILED_PASSES }}, finish reason: stop=${{ env.LLAMACPP_COMPLETIONS_STOP_RATE_PASSES }} truncated=${{ env.LLAMACPP_COMPLETIONS_TRUNCATED_RATE_PASSES }}
  218. - Prompt processing (pp): avg=${{ env.LLAMACPP_PROMPT_PROCESSING_SECOND_AVG }}tk/s p(95)=${{ env.LLAMACPP_PROMPT_PROCESSING_SECOND_P_95_ }}tk/s
  219. - Token generation (tg): avg=${{ env.LLAMACPP_TOKENS_SECOND_AVG }}tk/s p(95)=${{ env.LLAMACPP_TOKENS_SECOND_P_95_ }}tk/s
  220. - ${{ env.BENCH_GRAPH_XLABEL }}
  221. <p align="center">
  222. <img width="100%" height="100%" src="${{ env.IMAGE_O }}" alt="prompt_tokens_seconds" />
  223. <details>
  224. <summary>More</summary>
  225. ```mermaid
  226. ${{ env.PROMPT_TOKENS_SECONDS }}
  227. ```
  228. </details>
  229. <img width="100%" height="100%" src="${{ env.IMAGE_1 }}" alt="predicted_tokens_seconds"/>
  230. <details>
  231. <summary>More</summary>
  232. ```mermaid
  233. ${{ env.PREDICTED_TOKENS_SECONDS }}
  234. ```
  235. </details>
  236. </p>
  237. <details>
  238. <summary>Details</summary>
  239. <p align="center">
  240. <img width="100%" height="100%" src="${{ env.IMAGE_2 }}" alt="kv_cache_usage_ratio" />
  241. <details>
  242. <summary>More</summary>
  243. ```mermaid
  244. ${{ env.KV_CACHE_USAGE_RATIO }}
  245. ```
  246. </details>
  247. <img width="100%" height="100%" src="${{ env.IMAGE_3 }}" alt="requests_processing"/>
  248. <details>
  249. <summary>More</summary>
  250. ```mermaid
  251. ${{ env.REQUESTS_PROCESSING }}
  252. ```
  253. </details>
  254. </p>
  255. </details>
  256. </details>