interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / ci / run.sh

395 lines · 10587 bytes Raw Blame History
1#/bin/bash
2#
3# sample usage:
4#
5# mkdir tmp
6#
7# # CPU-only build
8# bash ./ci/run.sh ./tmp/results ./tmp/mnt
9#
10# # with CUDA support
11# GG_BUILD_CUDA=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt
12#
13# # With SYCL support
14# GG_BUILD_SYCL=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt
15#
16
17if [ -z "$2" ]; then
18 echo "usage: $0 <output-dir> <mnt-dir>"
19 exit 1
20fi
21
22mkdir -p "$1"
23mkdir -p "$2"
24
25OUT=$(realpath "$1")
26MNT=$(realpath "$2")
27
28rm -v $OUT/*.log
29rm -v $OUT/*.exit
30rm -v $OUT/*.md
31
32sd=`dirname $0`
33cd $sd/../
34SRC=`pwd`
35
36CMAKE_EXTRA=""
37CTEST_EXTRA=""
38
39if [ ! -z ${GG_BUILD_METAL} ]; then
40 CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_METAL=ON"
41fi
42
43if [ ! -z ${GG_BUILD_CUDA} ]; then
44 CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_CUDA=ON"
45
46 if command -v nvidia-smi >/dev/null 2>&1; then
47 CUDA_ARCH=$(nvidia-smi --query-gpu=compute_cap --format=csv,noheader,nounits 2>/dev/null | head -1 | tr -d '.')
48 if [[ -n "$CUDA_ARCH" && "$CUDA_ARCH" =~ ^[0-9]+$ ]]; then
49 CMAKE_EXTRA="${CMAKE_EXTRA} -DCMAKE_CUDA_ARCHITECTURES=${CUDA_ARCH}"
50 else
51 echo "Warning: Using fallback CUDA architectures"
52 CMAKE_EXTRA="${CMAKE_EXTRA} -DCMAKE_CUDA_ARCHITECTURES=61;70;75;80;86;89"
53 fi
54 else
55 echo "Error: nvidia-smi not found, cannot build with CUDA"
56 exit 1
57 fi
58fi
59
60if [ ! -z ${GG_BUILD_ROCM} ]; then
61 CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_HIP=ON"
62 if [ -z ${GG_BUILD_AMDGPU_TARGETS} ]; then
63 echo "Missing GG_BUILD_AMDGPU_TARGETS, please set it to your GPU architecture (e.g. gfx90a, gfx1100, etc.)"
64 exit 1
65 fi
66
67 CMAKE_EXTRA="${CMAKE_EXTRA} -DAMDGPU_TARGETS=${GG_BUILD_AMDGPU_TARGETS}"
68fi
69
70if [ ! -z ${GG_BUILD_SYCL} ]; then
71 if [ -z ${ONEAPI_ROOT} ]; then
72 echo "Not detected ONEAPI_ROOT, please install oneAPI base toolkit and enable it by:"
73 echo "source /opt/intel/oneapi/setvars.sh"
74 exit 1
75 fi
76 # Use only main GPU
77 export ONEAPI_DEVICE_SELECTOR="level_zero:0"
78 # Enable sysman for correct memory reporting
79 export ZES_ENABLE_SYSMAN=1
80 # to circumvent precision issues on CPY operations
81 export SYCL_PROGRAM_COMPILE_OPTIONS="-cl-fp32-correctly-rounded-divide-sqrt"
82 CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_SYCL=1 -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON"
83fi
84
85if [ ! -z ${GG_BUILD_VULKAN} ]; then
86 CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_VULKAN=1"
87
88 # if on Mac, disable METAL
89 if [[ "$OSTYPE" == "darwin"* ]]; then
90 CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_METAL=OFF -DGGML_BLAS=OFF"
91 fi
92
93fi
94
95if [ ! -z ${GG_BUILD_WEBGPU} ]; then
96 CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_WEBGPU=1"
97fi
98
99if [ ! -z ${GG_BUILD_MUSA} ]; then
100 # Use qy1 by default (MTT S80)
101 MUSA_ARCH=${MUSA_ARCH:-21}
102 CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_MUSA=ON -DMUSA_ARCHITECTURES=${MUSA_ARCH}"
103fi
104
105if [ ! -z ${GG_BUILD_NO_SVE} ]; then
106 # arm 9 and newer enables sve by default, adjust these flags depending on the cpu used
107 CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_NATIVE=OFF -DGGML_CPU_ARM_ARCH=armv8.5-a+fp16+i8mm"
108fi
109
110## helpers
111
112# download a file if it does not exist or if it is outdated
113function gg_wget {
114 local out=$1
115 local url=$2
116
117 local cwd=`pwd`
118
119 mkdir -p $out
120 cd $out
121
122 # should not re-download if file is the same
123 wget -nv -N $url
124
125 cd $cwd
126}
127
128function gg_printf {
129 printf -- "$@" >> $OUT/README.md
130}
131
132function gg_run {
133 ci=$1
134
135 set -o pipefail
136 set -x
137
138 gg_run_$ci | tee $OUT/$ci.log
139 cur=$?
140 echo "$cur" > $OUT/$ci.exit
141
142 set +x
143 set +o pipefail
144
145 gg_sum_$ci
146
147 ret=$((ret | cur))
148}
149
150## ci
151
152# ctest_debug
153
154function gg_run_ctest_debug {
155 cd ${SRC}
156
157 rm -rf build-ci-debug && mkdir build-ci-debug && cd build-ci-debug
158
159 set -e
160
161 (time cmake -DCMAKE_BUILD_TYPE=Debug ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
162 (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
163
164 (time ctest ${CTEST_EXTRA} --output-on-failure -E "test-opt|test-backend-ops" ) 2>&1 | tee -a $OUT/${ci}-ctest.log
165
166 set +e
167}
168
169function gg_sum_ctest_debug {
170 gg_printf '### %s\n\n' "${ci}"
171
172 gg_printf 'Runs ctest in debug mode\n'
173 gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
174 gg_printf '```\n'
175 gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
176 gg_printf '```\n'
177 gg_printf '\n'
178}
179
180# ctest_release
181
182function gg_run_ctest_release {
183 cd ${SRC}
184
185 rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
186
187 set -e
188
189 (time cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_EXTRA} .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
190 (time make -j$(nproc) ) 2>&1 | tee -a $OUT/${ci}-make.log
191
192 if [ -z $GG_BUILD_LOW_PERF ]; then
193 (time ctest ${CTEST_EXTRA} --output-on-failure ) 2>&1 | tee -a $OUT/${ci}-ctest.log
194 else
195 (time ctest ${CTEST_EXTRA} --output-on-failure -E test-opt ) 2>&1 | tee -a $OUT/${ci}-ctest.log
196 fi
197
198 set +e
199}
200
201function gg_sum_ctest_release {
202 gg_printf '### %s\n\n' "${ci}"
203
204 gg_printf 'Runs ctest in release mode\n'
205 gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
206 gg_printf '```\n'
207 gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
208 gg_printf '```\n'
209}
210
211# gpt_2
212
213function gg_run_gpt_2 {
214 cd ${SRC}
215
216 gg_wget models-mnt/gpt-2 https://huggingface.co/ggerganov/ggml/resolve/main/ggml-model-gpt-2-117M.bin
217
218 cd build-ci-release
219
220 set -e
221
222 model="../models-mnt/gpt-2/ggml-model-gpt-2-117M.bin"
223 prompts="../examples/prompts/gpt-2.txt"
224
225 (time ./bin/gpt-2-backend --model ${model} -s 1234 -n 64 -tt ${prompts} ) 2>&1 | tee -a $OUT/${ci}-tg.log
226 (time ./bin/gpt-2-backend --model ${model} -s 1234 -n 64 -p "I believe the meaning of life is") 2>&1 | tee -a $OUT/${ci}-tg.log
227 (time ./bin/gpt-2-sched --model ${model} -s 1234 -n 64 -p "I believe the meaning of life is") 2>&1 | tee -a $OUT/${ci}-tg.log
228
229 (time ./bin/gpt-2-batched --model ${model} -s 1234 -n 64 -np 8 -p "I believe the meaning of life is") 2>&1 | tee -a $OUT/${ci}-tg.log
230
231 set +e
232}
233
234function gg_sum_gpt_2 {
235 gg_printf '### %s\n\n' "${ci}"
236
237 gg_printf 'Runs short GPT-2 text generation\n'
238 gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
239 gg_printf '```\n'
240 gg_printf '%s\n' "$(cat $OUT/${ci}-tg.log)"
241 gg_printf '```\n'
242}
243
244# TODO: update
245## mnist
246#
247#function gg_run_mnist {
248# cd ${SRC}
249#
250# cd build-ci-release
251#
252# set -e
253#
254# mkdir -p models/mnist
255# python3 ../examples/mnist/convert-h5-to-ggml.py ../examples/mnist/models/mnist/mnist_model.state_dict
256#
257# model_f32="./models/mnist/ggml-model-f32.bin"
258# samples="../examples/mnist/models/mnist/t10k-images.idx3-ubyte"
259#
260# # first command runs and exports "mnist.ggml", the second command runs the exported model
261#
262# (time ./bin/mnist ${model_f32} ${samples} ) 2>&1 | tee -a $OUT/${ci}-mnist.log
263# (time ./bin/mnist-cpu ./mnist.ggml ${samples} ) 2>&1 | tee -a $OUT/${ci}-mnist.log
264#
265# set +e
266#}
267#
268#function gg_sum_mnist {
269# gg_printf '### %s\n\n' "${ci}"
270#
271# gg_printf 'MNIST\n'
272# gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
273# gg_printf '```\n'
274# gg_printf '%s\n' "$(cat $OUT/${ci}-mnist.log)"
275# gg_printf '```\n'
276#}
277
278# sam
279
280function gg_run_sam {
281 cd ${SRC}
282
283 gg_wget models-mnt/sam/ https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth
284 gg_wget models-mnt/sam/ https://raw.githubusercontent.com/YavorGIvanov/sam.cpp/ceafb7467bff7ec98e0c4f952e58a9eb8fd0238b/img.jpg
285
286 cd build-ci-release
287
288 set -e
289
290 path_models="../models-mnt/sam/"
291 model_f16="${path_models}/ggml-model-f16.bin"
292 img_0="${path_models}/img.jpg"
293
294 python3 ../examples/sam/convert-pth-to-ggml.py ${path_models}/sam_vit_b_01ec64.pth ${path_models}/ 1
295
296 # Test default parameters
297 (time ./bin/sam -m ${model_f16} -i ${img_0} -st 0.925 ) 2>&1 | tee -a $OUT/${ci}-main.log
298 grep -q "point prompt" $OUT/${ci}-main.log
299 grep -q "bbox (371, 436), (144, 168)" $OUT/${ci}-main.log ||
300 grep -q "bbox (370, 439), (144, 168)" $OUT/${ci}-main.log
301
302 # Test box prompt and single mask output
303 (time ./bin/sam -m ${model_f16} -i ${img_0} -st 0.925 -b 368,144,441,173 -sm) 2>&1 | tee -a $OUT/${ci}-main.log
304 grep -q "box prompt" $OUT/${ci}-main.log
305 grep -q "bbox (370, 439), (144, 169)" $OUT/${ci}-main.log ||
306 grep -q "bbox (370, 439), (144, 168)" $OUT/${ci}-main.log
307
308 set +e
309}
310
311function gg_sum_sam {
312 gg_printf '### %s\n\n' "${ci}"
313
314 gg_printf 'Run SAM\n'
315 gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
316 gg_printf '```\n'
317 gg_printf '%s\n' "$(cat $OUT/${ci}-main.log)"
318 gg_printf '```\n'
319}
320
321# yolo
322
323function gg_run_yolo {
324 cd ${SRC}
325
326 gg_wget models-mnt/yolo/ https://huggingface.co/ggml-org/models/resolve/main/yolo/yolov3-tiny.weights
327 gg_wget models-mnt/yolo/ https://huggingface.co/ggml-org/models/resolve/main/yolo/dog.jpg
328
329 cd build-ci-release
330 cp -r ../examples/yolo/data .
331
332 set -e
333
334 path_models="../models-mnt/yolo/"
335
336 python3 ../examples/yolo/convert-yolov3-tiny.py ${path_models}/yolov3-tiny.weights
337
338 (time ./bin/yolov3-tiny -m yolov3-tiny.gguf -i ${path_models}/dog.jpg ) 2>&1 | tee -a $OUT/${ci}-main.log
339
340 grep -qE "dog: (55|56|57|58|59)%" $OUT/${ci}-main.log
341 grep -qE "car: (50|51|52|53|54)%" $OUT/${ci}-main.log
342 grep -qE "truck: (54|55|56|57|58)%" $OUT/${ci}-main.log
343 grep -qE "bicycle: (57|58|59|60|61)%" $OUT/${ci}-main.log
344
345 set +e
346}
347
348function gg_sum_yolo {
349 gg_printf '### %s\n\n' "${ci}"
350
351 gg_printf 'Run YOLO\n'
352 gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
353 gg_printf '```\n'
354 gg_printf '%s\n' "$(cat $OUT/${ci}-main.log)"
355 gg_printf '```\n'
356}
357
358## main
359
360if true ; then
361 # Create symlink: ./ggml/models-mnt -> $MNT/models/models-mnt
362 rm -rf ${SRC}/models-mnt
363 mnt_models=${MNT}/models
364 mkdir -p ${mnt_models}
365 ln -sfn ${mnt_models} ${SRC}/models-mnt
366
367 # Create a fresh python3 venv and enter it
368 if ! python3 -m venv "$MNT/venv"; then
369 echo "Error: Failed to create Python virtual environment at $MNT/venv."
370 exit 1
371 fi
372 source "$MNT/venv/bin/activate"
373
374 pip install -r ${SRC}/requirements.txt --disable-pip-version-check
375fi
376
377
378ret=0
379
380test $ret -eq 0 && gg_run ctest_debug
381test $ret -eq 0 && gg_run ctest_release
382
383test $ret -eq 0 && gg_run gpt_2
384#test $ret -eq 0 && gg_run mnist
385test $ret -eq 0 && gg_run sam
386test $ret -eq 0 && gg_run yolo
387
388if [ -z $GG_BUILD_LOW_PERF ]; then
389 # run tests meant for low-perf runners
390 date
391fi
392
393cat $OUT/README.md
394
395exit $ret