run.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. if [ -z "$2" ]; then
  14. echo "usage: $0 <output-dir> <mnt-dir>"
  15. exit 1
  16. fi
  17. mkdir -p "$1"
  18. mkdir -p "$2"
  19. OUT=$(realpath "$1")
  20. MNT=$(realpath "$2")
  21. rm -v $OUT/*.log
  22. rm -v $OUT/*.exit
  23. rm -v $OUT/*.md
  24. sd=`dirname $0`
  25. cd $sd/../
  26. SRC=`pwd`
  27. ## helpers
  28. # download a file if it does not exist or if it is outdated
  29. function gg_wget {
  30. local out=$1
  31. local url=$2
  32. local cwd=`pwd`
  33. mkdir -p $out
  34. cd $out
  35. # should not re-download if file is the same
  36. wget -nv -N $url
  37. cd $cwd
  38. }
  39. function gg_printf {
  40. printf -- "$@" >> $OUT/README.md
  41. }
  42. function gg_run {
  43. ci=$1
  44. set -o pipefail
  45. set -x
  46. gg_run_$ci | tee $OUT/$ci.log
  47. cur=$?
  48. echo "$cur" > $OUT/$ci.exit
  49. set +x
  50. set +o pipefail
  51. gg_sum_$ci
  52. ret=$((ret | cur))
  53. }
  54. ## ci
  55. # ctest_debug
  56. function gg_run_ctest_debug {
  57. cd ${SRC}
  58. rm -rf build-ci-debug && mkdir build-ci-debug && cd build-ci-debug
  59. set -e
  60. (time cmake -DCMAKE_BUILD_TYPE=Debug .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  61. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  62. (time ctest --output-on-failure -E test-opt ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  63. set +e
  64. }
  65. function gg_sum_ctest_debug {
  66. gg_printf '### %s\n\n' "${ci}"
  67. gg_printf 'Runs ctest in debug mode\n'
  68. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  69. gg_printf '```\n'
  70. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  71. gg_printf '```\n'
  72. gg_printf '\n'
  73. }
  74. # ctest_release
  75. function gg_run_ctest_release {
  76. cd ${SRC}
  77. rm -rf build-ci-release && mkdir build-ci-release && cd build-ci-release
  78. set -e
  79. (time cmake -DCMAKE_BUILD_TYPE=Release .. ) 2>&1 | tee -a $OUT/${ci}-cmake.log
  80. (time make -j ) 2>&1 | tee -a $OUT/${ci}-make.log
  81. if [ -z $GG_BUILD_LOW_PERF ]; then
  82. (time ctest --output-on-failure ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  83. else
  84. (time ctest --output-on-failure -E test-opt ) 2>&1 | tee -a $OUT/${ci}-ctest.log
  85. fi
  86. set +e
  87. }
  88. function gg_sum_ctest_release {
  89. gg_printf '### %s\n\n' "${ci}"
  90. gg_printf 'Runs ctest in release mode\n'
  91. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  92. gg_printf '```\n'
  93. gg_printf '%s\n' "$(cat $OUT/${ci}-ctest.log)"
  94. gg_printf '```\n'
  95. }
  96. # gpt_2
  97. function gg_run_gpt_2 {
  98. cd ${SRC}
  99. gg_wget models-mnt/gpt-2 https://huggingface.co/ggerganov/ggml/resolve/main/ggml-model-gpt-2-117M.bin
  100. cd build-ci-release
  101. set -e
  102. model="../models-mnt/gpt-2/ggml-model-gpt-2-117M.bin"
  103. prompts="../examples/prompts/gpt-2.txt"
  104. (time ./bin/gpt-2 --model ${model} -s 1234 -n 64 -tt ${prompts} ) 2>&1 | tee -a $OUT/${ci}-tg.log
  105. (time ./bin/gpt-2 --model ${model} -s 1234 -n 64 -p "I believe the meaning of life is") 2>&1 | tee -a $OUT/${ci}-tg.log
  106. set +e
  107. }
  108. function gg_sum_gpt_2 {
  109. gg_printf '### %s\n\n' "${ci}"
  110. gg_printf 'Runs short GPT-2 text generation\n'
  111. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  112. gg_printf '```\n'
  113. gg_printf '%s\n' "$(cat $OUT/${ci}-tg.log)"
  114. gg_printf '```\n'
  115. }
  116. # mpt
  117. function gg_run_mpt {
  118. cd ${SRC}
  119. gg_wget models-mnt/mpt/7B/ https://huggingface.co/mosaicml/mpt-7b/raw/main/config.json
  120. gg_wget models-mnt/mpt/7B/ https://huggingface.co/mosaicml/mpt-7b/raw/main/tokenizer.json
  121. gg_wget models-mnt/mpt/7B/ https://huggingface.co/mosaicml/mpt-7b/raw/main/tokenizer_config.json
  122. gg_wget models-mnt/mpt/7B/ https://huggingface.co/mosaicml/mpt-7b/raw/main/pytorch_model.bin.index.json
  123. gg_wget models-mnt/mpt/7B/ https://huggingface.co/mosaicml/mpt-7b/raw/main/configuration_mpt.py
  124. gg_wget models-mnt/mpt/7B/ https://huggingface.co/mosaicml/mpt-7b/resolve/main/pytorch_model-00001-of-00002.bin
  125. gg_wget models-mnt/mpt/7B/ https://huggingface.co/mosaicml/mpt-7b/resolve/main/pytorch_model-00002-of-00002.bin
  126. cd build-ci-release
  127. set -e
  128. path_models="../models-mnt/mpt/7B"
  129. model_f16="${path_models}/ggml-model-f16.bin"
  130. model_q4_0="${path_models}/ggml-model-q4_0.bin"
  131. python3 ../examples/mpt/convert-h5-to-ggml.py ${path_models} 1
  132. ./bin/mpt-quantize ${model_f16} ${model_q4_0} q4_0
  133. (time ./bin/mpt --model ${model_f16} -s 1234 -n 64 -p "I believe the meaning of life is") 2>&1 | tee -a $OUT/${ci}-tg.log
  134. (time ./bin/mpt --model ${model_q4_0} -s 1234 -n 64 -p "I believe the meaning of life is") 2>&1 | tee -a $OUT/${ci}-tg.log
  135. set +e
  136. }
  137. function gg_sum_mpt {
  138. gg_printf '### %s\n\n' "${ci}"
  139. gg_printf 'Runs short MPT text generation\n'
  140. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  141. gg_printf '```\n'
  142. gg_printf '%s\n' "$(cat $OUT/${ci}-tg.log)"
  143. gg_printf '```\n'
  144. }
  145. # mnist
  146. function gg_run_mnist {
  147. cd ${SRC}
  148. cd build-ci-release
  149. set -e
  150. mkdir -p models/mnist
  151. python3 ../examples/mnist/convert-h5-to-ggml.py ../examples/mnist/models/mnist/mnist_model.state_dict
  152. model_f32="./models/mnist/ggml-model-f32.bin"
  153. samples="../examples/mnist/models/mnist/t10k-images.idx3-ubyte"
  154. # first command runs and exports "mnist.ggml", the second command runs the exported model
  155. (time ./bin/mnist ${model_f32} ${samples} ) 2>&1 | tee -a $OUT/${ci}-mnist.log
  156. (time ./bin/mnist-cpu ./mnist.ggml ${samples} ) 2>&1 | tee -a $OUT/${ci}-mnist.log
  157. set +e
  158. }
  159. function gg_sum_mnist {
  160. gg_printf '### %s\n\n' "${ci}"
  161. gg_printf 'MNIST\n'
  162. gg_printf '- status: %s\n' "$(cat $OUT/${ci}.exit)"
  163. gg_printf '```\n'
  164. gg_printf '%s\n' "$(cat $OUT/${ci}-mnist.log)"
  165. gg_printf '```\n'
  166. }
  167. ## main
  168. if [ -z $GG_BUILD_LOW_PERF ]; then
  169. rm -rf ${SRC}/models-mnt
  170. mnt_models=${MNT}/models
  171. mkdir -p ${mnt_models}
  172. ln -sfn ${mnt_models} ${SRC}/models-mnt
  173. fi
  174. python3 -m pip install -r ${SRC}/requirements.txt
  175. ret=0
  176. test $ret -eq 0 && gg_run ctest_debug
  177. test $ret -eq 0 && gg_run ctest_release
  178. test $ret -eq 0 && gg_run gpt_2
  179. test $ret -eq 0 && gg_run mnist
  180. if [ -z $GG_BUILD_LOW_PERF ]; then
  181. test $ret -eq 0 && gg_run mpt
  182. fi
  183. exit $ret