Repository navigation
Expand file tree
/
Copy pathDockerfile.baseline
More file actions
155 lines (144 loc) · 7.88 KB
/
Copy pathDockerfile.baseline
File metadata and controls
155 lines (144 loc) · 7.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Build environment for the voxtype baseline x86-64 binary.
#
# WHY THIS EXISTS: every other x86-64 variant is built with
# `-C target-cpu=haswell` or higher, so all of them SIGILL on a CPU without
# AVX2. That is not a hypothetical: #612 came from a 2012 MacBook Pro with an
# Ivy Bridge i5-3210M, which has `avx` and `f16c` but no `avx2`, `fma` or
# `bmi2`. Before this variant existed, the honest advice to those users was
# "build it yourself".
#
# The floor is x86-64-v2 (SSE4.2 + POPCNT, Nehalem 2008 and later) rather than
# plain x86-64. It reaches every machine that could plausibly run a modern
# Linux desktop and is meaningfully faster than true baseline. Going lower buys
# hardware nobody is running voxtype on.
#
# Ubuntu 22.04 for the same reason as Dockerfile.build: newer distros ship a
# libstdc++ whose inlined templates leak AVX-512 into binaries regardless of
# RUSTFLAGS.
#
# Usage:
# docker build -f Dockerfile.baseline -t voxtype-baseline .
# docker run --rm -v $(pwd)/releases:/output voxtype-baseline
#
FROM ubuntu:22.04
ARG VERSION=1.1.0
ARG DEBIAN_FRONTEND=noninteractive
ENV VERSION=${VERSION}
# Retry apt. Acquire::Retries covers connection errors; the loop covers a 404
# or a size mismatch while an Ubuntu mirror is mid-sync.
RUN printf 'Acquire::Retries "5";\nAcquire::http::Timeout "30";\n' \
> /etc/apt/apt.conf.d/80-voxtype-retries
RUN for attempt in 1 2 3 4; do apt-get update && apt-get install -y \
curl \
build-essential \
clang \
cmake \
pkg-config \
libasound2-dev \
libx11-dev \
libxi-dev \
libxtst-dev \
libgtk-3-dev \
libglib2.0-dev \
libappindicator3-dev \
git \
binutils \
&& break; \
[ "$attempt" = 4 ] && exit 1; \
echo "apt failed (attempt $attempt), mirror may be syncing; retrying in 90s"; \
if [ "$attempt" = 2 ]; then echo "switching apt to azure.archive.ubuntu.com"; sed -i -E 's#https?://(archive|security)\.ubuntu\.com#http://azure.archive.ubuntu.com#g' /etc/apt/sources.list /etc/apt/sources.list.d/*.sources 2>/dev/null || true; fi; \
rm -rf /var/lib/apt/lists/*; sleep 90; \
done && rm -rf /var/lib/apt/lists/*
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
WORKDIR /build
COPY . .
# The whole point of the variant. Three channels, one per compiler route
# (#740 shipped because only the first of these existed - GGML_* and
# CMAKE_C_FLAGS as plain ENV are read by nothing in the build chain, and
# ggml silently fell back to -march=native on an AVX2 build host):
#
# RUSTFLAGS - the Rust half of the binary
# CFLAGS/CXXFLAGS - C/C++ built via the cc crate, and the base
# flags the cmake crate passes as CMAKE_C_FLAGS
# CMAKE_TOOLCHAIN_FILE - ggml's own CMake options (GGML_NATIVE and the
# per-ISA switches); CMake >= 3.21 reads this
# from the environment, and it is the only way
# to reach option() values inside whisper-rs-sys
ENV RUSTFLAGS="-C target-cpu=x86-64-v2 -C target-feature=-avx2,-fma,-bmi2,-avx512f,-avx512bw,-avx512cd,-avx512dq,-avx512vl,-gfni"
ENV CFLAGS="-march=x86-64-v2"
ENV CXXFLAGS="-march=x86-64-v2"
ENV CMAKE_TOOLCHAIN_FILE=/build/cmake/x86-64-v2-toolchain.cmake
# transcribe-cpp-sys does not consume the whisper/ggml toolchain variables
# above. Override the workspace's v3 default so the worker keeps this
# variant's x86-64-v2 floor too.
ENV TRANSCRIBE_CMAKE_ARGS="-DTRANSCRIBE_USE_SYSTEM_BLAS=OFF -DTRANSCRIBE_X86_CONSERVATIVE=ON -DGGML_SSE42=ON"
# Lets the SIGILL banner know it is the baseline build, so it never advises
# switching to itself.
ENV VOXTYPE_VARIANT=baseline
# Every release binary carries the GGUF client (gguf, cohere-gguf,
# parakeet-gguf) so `.gguf` catalog models route to the worker. This variant
# ships a CPU worker; GPU GGUF on Whisper builds comes from the vulkan variant.
RUN cargo build --release --features gguf,cohere-gguf,parakeet-gguf \
&& cp target/release/voxtype /tmp/voxtype-baseline \
&& cargo build --release -p voxtype-gguf-worker \
&& cp target/release/voxtype-gguf-worker /tmp/voxtype-gguf-worker
RUN scripts/verify-gguf-companion.sh --cpu-only --run \
/tmp/voxtype-baseline /tmp/voxtype-gguf-worker
# What this can and cannot prove.
#
# Hard gate: AVX-512 (zmm) - ggml compiles it only when asked, so any zmm
# means the toolchain constraints did not take.
#
# BMI2, FMA, and ymm counts are reported but NOT gated. A correct baseline
# binary legitimately contains all three behind runtime CPUID dispatch:
# ring's hand-written assembly carries ~370 BMI2 instructions (mulx/rorx in
# bn_mulx4x_mont, the chacha20 AVX2 path, the curve25519 ADX path) and
# rustfft's AVX kernels carry ~1800 FMA - none of which execute on a CPU
# whose CPUID lacks the feature. #740's ggml contamination added only ~60
# BMI2 on top of ring's baseline, so no static count can separate a broken
# build from a correct one. The decisive check is BEHAVIORAL: the QEMU step
# below runs the binary on a modeled v2 CPU where TCG genuinely cannot
# decode out-of-floor instructions, and CI runs full inference the same way
# (verified: the rc4 binary SIGILLs there exactly as it did on real Ivy
# Bridge; the fixed build transcribes).
RUN echo "=== Verifying baseline binary ===" \
&& objdump -d /tmp/voxtype-baseline > /tmp/baseline.dis \
&& objdump -d /tmp/voxtype-gguf-worker >> /tmp/baseline.dis \
&& zmm=$(grep -c zmm /tmp/baseline.dis || true) \
&& bmi2=$(grep -cP '\t(shrx|sarx|shlx|mulx|pdep|pext|bzhi|rorx)[ \t]' /tmp/baseline.dis || true) \
&& ymm=$(grep -c ymm /tmp/baseline.dis || true) \
&& fma=$(grep -cP '\t(vfmadd|vfmsub|vfnmadd|vfnmsub)' /tmp/baseline.dis || true) \
&& echo " zmm (AVX-512, gated): $zmm" \
&& echo " BMI2 (informational, ~370 expected from ring): $bmi2" \
&& echo " ymm (AVX/AVX2, informational): $ymm" \
&& echo " FMA (informational, ~1800 expected from rustfft): $fma" \
&& rm /tmp/baseline.dis \
&& if [ "$zmm" -gt 0 ]; then \
echo "ERROR: AVX-512 present; the toolchain constraints did not take effect" && exit 1; \
fi \
&& echo "✓ no AVX-512. Behavioral floor check follows."
# Behavioral floor check: execute the binary on a QEMU-modeled Nehalem
# (x86-64-v2: SSE4.2 + POPCNT, no AVX). TCG software emulation genuinely
# cannot decode instructions outside the modeled CPU, so an unconditional
# v3 instruction on any startup path dies here instead of on a user's
# machine. Inference is exercised separately in CI, where a model is
# available - this catches the load-and-dispatch paths.
RUN for attempt in 1 2 3 4; do apt-get update && apt-get install -y qemu-user-static && break; \
[ "$attempt" = 4 ] && exit 1; \
echo "apt failed (attempt $attempt), mirror may be syncing; retrying in 90s"; \
if [ "$attempt" = 2 ]; then echo "switching apt to azure.archive.ubuntu.com"; sed -i -E 's#https?://(archive|security)\.ubuntu\.com#http://azure.archive.ubuntu.com#g' /etc/apt/sources.list /etc/apt/sources.list.d/*.sources 2>/dev/null || true; fi; \
rm -rf /var/lib/apt/lists/*; sleep 90; \
done && rm -rf /var/lib/apt/lists/* \
&& echo "=== QEMU Nehalem floor check ===" \
&& qemu-x86_64-static -cpu Nehalem /tmp/voxtype-baseline --version \
&& qemu-x86_64-static -cpu Nehalem /tmp/voxtype-baseline --help > /dev/null \
&& qemu-x86_64-static -cpu Nehalem /tmp/voxtype-gguf-worker 2>&1 | grep -q usage \
&& echo "✓ starts on a v2-floor CPU model."
CMD mkdir -p /output \
&& cp /tmp/voxtype-baseline /output/voxtype-${VERSION}-linux-x86_64-baseline \
&& cp /tmp/voxtype-gguf-worker /output/voxtype-${VERSION}-linux-x86_64-baseline.gguf-worker \
&& chmod 755 /output/voxtype-${VERSION}-linux-x86_64-baseline \
&& chmod 755 /output/voxtype-${VERSION}-linux-x86_64-baseline.gguf-worker \
&& echo "Binary copied to /output:" \
&& ls -la /output/voxtype-*