Skip to content

Commit 55ccb13

Browse files
weiqingyweiqingy
andauthored
[ci] Pin Ollama to the AVX2 CPU build in the integration jobs (#904)
llama-server ships one libggml-cpu-<microarch> build per instruction set and loads the best match for the host CPU at runtime. The hosted runner pool is mixed, so the kernels that serve a request depend on the machine a job lands on, and jobs on the newer hosts intermittently die with a llama-server segmentation fault (ollama/ollama#17006). Remove the AVX-512-bearing builds after install so llama-server falls back to the AVX2 build, whose kernels every runner in the pool shares. Also log the runner CPU and the remaining builds, so a future failure can be attributed to the microarchitecture that served it. Co-authored-by: weiqingy <ywqapply@gmail.com>
1 parent 6f020c5 commit 55ccb13

1 file changed

Lines changed: 73 additions & 11 deletions

File tree

tools/start_ollama_server.sh

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,80 @@ trap 'rm -f "$install_script"' EXIT
2828
# The upstream installer probes for the .tar.zst asset with a silent HEAD request, and on
2929
# any failure of that probe falls back to a .tgz that current releases no longer publish.
3030
# A single transient network error therefore turns into a hard 404, so retry the install.
31-
attempts=3
32-
for attempt in $(seq 1 "$attempts"); do
33-
if curl -fsSL https://ollama.com/install.sh -o "$install_script" && sh "$install_script"; then
34-
exit 0
35-
fi
31+
install_ollama() {
32+
attempts=3
33+
for attempt in $(seq 1 "$attempts"); do
34+
if curl -fsSL https://ollama.com/install.sh -o "$install_script" && sh "$install_script"; then
35+
return 0
36+
fi
37+
38+
if [ "$attempt" -lt "$attempts" ]; then
39+
delay=$((attempt * 10))
40+
echo "ollama install attempt ${attempt}/${attempts} failed; retrying in ${delay}s" >&2
41+
sleep "$delay"
42+
fi
43+
done
44+
45+
echo "ollama install failed after ${attempts} attempts" >&2
46+
return 1
47+
}
3648

37-
if [ "$attempt" -lt "$attempts" ]; then
38-
delay=$((attempt * 10))
39-
echo "ollama install attempt ${attempt}/${attempts} failed; retrying in ${delay}s" >&2
40-
sleep "$delay"
49+
install_ollama || exit 1
50+
51+
# llama-server ships one libggml-cpu-<microarch> build per instruction set and loads the
52+
# best match for the host CPU. The hosted runner pool is mixed, so which kernels serve a
53+
# request depends on the machine the job happens to land on. Log it, so a failure can be
54+
# attributed to the microarchitecture that served it.
55+
find_ollama_lib_dir() {
56+
for dir in /usr/local/lib/ollama /usr/lib/ollama /opt/ollama/lib; do
57+
if compgen -G "${dir}/libggml-cpu-*" > /dev/null 2>&1; then
58+
echo "$dir"
59+
return 0
60+
fi
61+
done
62+
return 1
63+
}
64+
65+
cpu_model=$(sed -n 's/^model name[[:space:]]*: *//p' /proc/cpuinfo | head -1)
66+
cpu_isa=""
67+
for flag in avx2 avx512f avx512_bf16 amx_tile; do
68+
if grep -qm1 "^flags.*\b${flag}\b" /proc/cpuinfo; then
69+
cpu_isa="${cpu_isa}${cpu_isa:+,}${flag}"
4170
fi
4271
done
72+
echo "ollama-cpu: model='${cpu_model:-unknown}' isa='${cpu_isa:-none}'"
73+
74+
lib_dir=$(find_ollama_lib_dir) || lib_dir=""
75+
if [ -z "$lib_dir" ]; then
76+
echo "ollama-cpu: no libggml-cpu-* builds found; leaving backend selection untouched"
77+
exit 0
78+
fi
79+
80+
# Upstream reports llama-server segfaulting on hosts whose CPU exposes the newer vector
81+
# extensions (ollama/ollama#17006). Every AVX-512-bearing build is removed so llama-server
82+
# falls back to the AVX2 build, whose kernels are shared by every runner in the pool and do
83+
# not crash. Keep this list in sync with ggml's GGML_CPU_ALL_VARIANTS x86 variants.
84+
avx512_variants="skylakex cannonlake cascadelake icelake cooperlake zen4 sapphirerapids"
85+
86+
for variant in $avx512_variants; do
87+
for build in "$lib_dir"/libggml-cpu-"$variant".*; do
88+
[ -e "$build" ] || continue
89+
sudo mv "$build" "${build}.disabled"
90+
echo "ollama-cpu: disabled $(basename "$build")"
91+
done
92+
done
93+
94+
echo "ollama-cpu: remaining builds:"
95+
for build in "$lib_dir"/libggml-cpu-*; do
96+
case "$build" in
97+
*.disabled) continue ;;
98+
esac
99+
echo "ollama-cpu: $(basename "$build")"
100+
done
43101

44-
echo "ollama install failed after ${attempts} attempts" >&2
45-
exit 1
102+
# The installer runs ollama as a systemd unit, so restart it to drop any backend the
103+
# running process already mapped.
104+
if systemctl is-active --quiet ollama; then
105+
sudo systemctl restart ollama
106+
echo "ollama-cpu: restarted ollama"
107+
fi

0 commit comments

Comments
 (0)