Skip to content

Commit 9fe1165

Browse files
fix(turboquant): retain CPU variants in GPU builds (#11276)
Select the CPU_ALL_VARIANTS target for x86 GPU images so partial offload uses runtime-selected host kernels. Keep GPU arm64 builds on the portable fallback until their toolchains consistently provide gcc-14. Assisted-by: Codex:gpt-5 Co-authored-by: localai-org-maint-bot <306269227+localai-org-maint-bot@users.noreply.github.com>
1 parent ad2be8a commit 9fe1165

4 files changed

Lines changed: 50 additions & 10 deletions

File tree

.docker/turboquant-build-target.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
arch=${1:?target architecture is required}
5+
build_type=${2-}
6+
7+
# GPU arm64 base images do not consistently provide the gcc-14 toolchain needed
8+
# to compile ggml's armv9.2 CPU variants. Keep their portable fallback until the
9+
# builder images can supply that compiler.
10+
if [ "$arch" = "arm64" ] && [ -n "$build_type" ]; then
11+
echo turboquant-fallback
12+
else
13+
echo turboquant-cpu-all
14+
fi

.docker/turboquant-compile.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@ fi
1919

2020
cd /LocalAI/backend/cpp/turboquant
2121

22-
if [ -z "${BUILD_TYPE:-}" ]; then
23-
# Pure CPU image: one ggml CPU_ALL_VARIANTS build replaces the per-microarch binaries.
22+
BUILD_TARGET=$(/LocalAI/.docker/turboquant-build-target.sh "${TARGETARCH}" "${BUILD_TYPE:-}")
23+
if [ "$BUILD_TARGET" = "turboquant-cpu-all" ]; then
24+
# BUILD_TYPE remains in the environment, so GPU builds retain their accelerator while
25+
# ggml selects the best CPU library when model work is offloaded to the host.
2426
# arm64: the armv9.2 SME variants need gcc-14 (gcc-13 rejects +sme).
2527
if [ "${TARGETARCH}" = "arm64" ]; then
28+
sh /LocalAI/.docker/apt-mirror.sh || true
2629
apt-get update -qq && apt-get install -y -qq gcc-14 g++-14
2730
export CC=gcc-14 CXX=g++-14
2831
fi
29-
make turboquant-cpu-all
30-
else
31-
# GPU build (cublas/hipblas/sycl/vulkan/...): single fallback CPU build, the accelerator
32-
# does the compute. Keeps the GPU compile from also building the CPU variant matrix and
33-
# avoids the gcc-14 apt step on GPU base images such as nvidia l4t.
34-
make turboquant-fallback
3532
fi
33+
make "$BUILD_TARGET"
3634
make turboquant-grpc
3735
make turboquant-rpc-server
3836

backend/cpp/turboquant/run.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ grep -e "flags" /proc/cpuinfo | head -1
1212

1313
BINARY=turboquant-fallback
1414

15-
# x86/arm64 ship a single turboquant-cpu-all built with ggml CPU_ALL_VARIANTS: ggml's
15+
# CPU images and x86 GPU images ship a single turboquant-cpu-all built with ggml
16+
# CPU_ALL_VARIANTS: ggml's
1617
# backend registry dlopens the best libggml-cpu-*.so for this host, so no shell-side
17-
# probing. ROCm ships only turboquant-fallback, so fall back to it when cpu-all is absent.
18+
# probing. GPU arm64 images still ship turboquant-fallback until their builder toolchains
19+
# support ggml's complete arm variant matrix.
1820
if [ -e "$CURDIR"/turboquant-cpu-all ]; then
1921
BINARY=turboquant-cpu-all
2022
fi
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
CURDIR=$(dirname "$(realpath "$0")")
5+
SELECTOR="$CURDIR/../../.docker/turboquant-build-target.sh"
6+
7+
assert_target() {
8+
local arch=$1
9+
local build_type=$2
10+
local expected=$3
11+
local actual
12+
13+
actual=$("$SELECTOR" "$arch" "$build_type")
14+
if [ "$actual" != "$expected" ]; then
15+
echo "FAIL: $arch/$build_type selected $actual, expected $expected"
16+
exit 1
17+
fi
18+
}
19+
20+
assert_target amd64 cublas turboquant-cpu-all
21+
assert_target amd64 vulkan turboquant-cpu-all
22+
assert_target amd64 "" turboquant-cpu-all
23+
assert_target arm64 cublas turboquant-fallback
24+
assert_target arm64 "" turboquant-cpu-all
25+
26+
echo "PASS: turboquant build target preserves CPU variants where supported"

0 commit comments

Comments
 (0)