Repository navigation
Expand file tree
/
Copy pathDockerfile.rocm
More file actions
231 lines (200 loc) · 10.5 KB
/
Copy pathDockerfile.rocm
File metadata and controls
231 lines (200 loc) · 10.5 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# syntax=docker/dockerfile:1.7
# ─── Stage 1: builder ───────────────────────────────────────────────────────
# ROCm/HIP sibling of the CUDA Dockerfile. ROCM_VERSION / UBUNTU_VERSION /
# LUCE_HIP_ARCHES are build args so the same Dockerfile can be repinned.
# • lucebox-hub:rocm — ROCm 7.2.4, gfx1151 (+ optional fat gfx list)
# See docker-bake.hcl for the canonical invocation.
#
# NOTE: ROCm 7.2.4 is the stack the engine is built and tested on (the
# Lucebox boxes and the AMD CI runner); the engine no longer builds on 6.x.
# Keep the base's major version aligned with the host driver: a 6.4.x
# userspace segfaults at model load against a ROCm 7.x host driver (seen on
# gfx1151 + host ROCm 7.2.2: SIGSEGV in backend creation, bogus 1.28 TB VRAM
# report). Ubuntu 24.04: ROCm 7.2's CMake package files need CMake >= 3.25,
# and 22.04 ships 3.22.
ARG ROCM_VERSION=7.2.4
ARG UBUNTU_VERSION=24.04
FROM rocm/dev-ubuntu-${UBUNTU_VERSION}:${ROCM_VERSION} AS builder
ARG DEBIAN_FRONTEND=noninteractive
# Fat-binary HIP arch list, semicolon-separated. Each gfx target adds build
# time + kernel code the same way CUDA arches do, so narrow this to your host
# for fast local builds: LUCE_HIP_ARCHES=gfx1151 docker buildx bake rocm-local
# dflash-supported gfx targets (all have the sm_75+ equivalent features dflash
# assumes; pre-RDNA/CDNA1 parts are excluded):
# gfx1151 Strix Halo / Ryzen AI MAX+ 395 (the lucebox appliance iGPU)
# gfx1100 RDNA3 RX 7900 XTX / W7900
# gfx1200 RDNA4 RX 9060 (Navi 44)
# gfx1201 RDNA4 RX 9070 / Radeon AI PRO R9700 (Navi 48)
# gfx942 CDNA3 MI300X / MI300A
# NB: gfx1200 and gfx1201 are NOT code-object compatible; the R9700 needs gfx1201.
# gfx90a CDNA2 MI200 / MI250
ARG LUCE_HIP_ARCHES="gfx1151"
# ROCm toolchain on PATH (hipcc + amdclang). The rocm/dev-ubuntu base installs
# ROCm at /opt/rocm; ROCM_PATH lets server/CMakeLists.txt resolve the HIP rpath
# and rocwmma header roots (server/CMakeLists.txt:33-41).
ENV ROCM_PATH=/opt/rocm
ENV PATH=/opt/rocm/bin:/opt/rocm/lib/llvm/bin:${PATH}
# Unlike the CUDA image there is NO driver-stub symlink step: the ROCm base
# ships the real HIP runtime libs (libamdhip64.so etc.) and the host kernel
# driver (/dev/kfd, /dev/dri) is wired in at run time via --device.
# hipblas/rocblas: ggml's HIP backend hard-requires them.
# hipCUB/rocPRIM: ggml's ROCm argsort/top-k kernels use their headers for the
# large-N device-sort path. rocWMMA is also required by the DS4 indexed
# prefill kernel. The ROCm apt repository ships these headers separately from
# the base HIP toolchain. hipBLASLt is optional for ggml-hip: with its -dev
# package present the DS4V vision ops are built, without it --mmproj is refused.
# (deps/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt does find_package(hipblas)
# for its BLAS matmul path). The rocm/dev-ubuntu base ships the HIP toolchain
# but NOT the math libs, so they are installed explicitly from the ROCm apt
# repo the base image already configures.
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
cmake \
curl \
git \
git-lfs \
hipblas-dev \
hipblaslt-dev \
hipcub-dev \
libcurl4-openssl-dev \
ninja-build \
pkg-config \
python3 \
rocblas-dev \
rocprim-dev \
rocwmma-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /src
# COPY ordering mirrors the CUDA Dockerfile: C++ build inputs first so the
# (slow) HIP build layer stays cached across Python-only edits.
COPY server/CMakeLists.txt /src/server/CMakeLists.txt
COPY server/cmake /src/server/cmake
COPY server/include /src/server/include
COPY server/src /src/server/src
COPY server/test /src/server/test
COPY server/hip_compat /src/server/hip_compat
COPY server/deps /src/server/deps
# status.html: luce_server's POST_BUILD copies server/share/status.html into
# build/share/. Without this COPY the build links then dies on the missing file.
COPY server/share /src/server/share
# Vendored ggml sources must already be present on the host before
# `docker build` (.git/ is .dockerignore'd so submodules cannot be fetched
# inside the image).
RUN test -f /src/server/deps/llama.cpp/ggml/CMakeLists.txt \
|| (echo "ERROR: missing vendored ggml sources at server/deps/llama.cpp/ggml in the docker build context." >&2 \
&& exit 1)
# Configure + build for HIP. LUCE_GPU_BACKEND=hip selects the ggml-hip
# backend (server/CMakeLists.txt:70-78); LUCE_HIP_ARCHITECTURES pins the
# gfx list. Block-Sparse-Attention is a CUDA-only kernel set, so BSA is OFF for
# HIP; FA_ALL_QUANTS OFF keeps the fattn build tractable (matches the lucebox
# native HIP build). CMAKE_BUILD_WITH_INSTALL_RPATH bakes the $ORIGIN-relative
# rpath (incl. ggml-hip + ROCm lib) so the binaries find their .so files after
# the COPY into the runtime stage.
RUN cmake -S /src/server -B /src/server/build \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
-DLUCE_GPU_BACKEND=hip \
-DLUCE_HIP_ARCHITECTURES="${LUCE_HIP_ARCHES}" \
-DLUCE_FA_ALL_QUANTS=OFF \
-DLUCE_ENABLE_BSA=OFF \
&& cmake --build /src/server/build --target test_dflash luce_server test_server_unit --parallel
# Prune the build tree to only what the runtime stage needs: the native server,
# test_dflash, test_server_unit, and the ggml shared libs their embedded rpath
# ($ORIGIN/deps/...) looks up.
RUN cd /src/server/build \
&& find . -mindepth 1 -maxdepth 1 \
! -name test_dflash ! -name luce_server ! -name test_server_unit ! -name deps -exec rm -rf {} + \
&& find deps -mindepth 1 -type f ! -name 'lib*.so*' -delete \
&& find deps -depth -type d -empty -delete
# Python sources, workspace manifests, lockfile, READMEs (same as CUDA stage).
COPY pyproject.toml uv.lock README.md /src/
COPY server/pyproject.toml server/README.md /src/server/
COPY server/scripts /src/server/scripts
COPY optimizations/pflash /src/optimizations/pflash
COPY optimizations/megakernel /src/optimizations/megakernel
# ─── Stage 2: runtime ───────────────────────────────────────────────────────
# Runtime reuses the ROCm base so the HIP runtime libs (libamdhip64,
# libhsa-runtime64, librocm-core, …) the binaries link against are present and
# version-matched to the builder. This makes a larger image than a minimal
# runtime would; slimming to `ubuntu:${UBUNTU_VERSION}` + the AMD repo's
# `rocm-language-runtime` meta-package is a follow-up optimisation (the build
# stage is unaffected, so it can be done independently).
FROM rocm/dev-ubuntu-${UBUNTU_VERSION}:${ROCM_VERSION} AS runtime
ARG DEBIAN_FRONTEND=noninteractive
# Image identity baked in for /props.build (git_sha / image_tag / build_time),
# wired from docker-bake.hcl. Empty in non-bake builds → JSON null at /props.
ARG GIT_SHA=""
ARG IMAGE_TAG=""
ARG BUILD_TIME=""
ENV ROCM_PATH=/opt/rocm
ENV PATH=/opt/rocm/bin:${PATH}
# hipblas/rocblas runtime libs: the dflash binaries link ggml-hip against
# them (see builder stage). Their .so files must be present at runtime for
# the server to load.
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
hipblas \
hipblaslt \
libgomp1 \
pciutils \
rocblas \
&& rm -rf /var/lib/apt/lists/*
# uv (pinned) manages Python 3.12 + resolves the luce + pflash
# workspace. Copied from the official image rather than `curl | sh`, so the
# version is fixed and no remote installer script runs at build time.
COPY --from=ghcr.io/astral-sh/uv:0.11.2 /uv /uvx /usr/local/bin/
# Ubuntu 24.04 ships a Python 3.12 of its own; take uv's managed build anyway,
# as the CUDA image does, so the interpreter lives under /opt/uv.
ENV UV_PYTHON_INSTALL_DIR=/opt/uv/python \
UV_TOOL_DIR=/opt/uv/tools \
UV_PYTHON_PREFERENCE=only-managed
WORKDIR /opt/lucebox-hub
COPY --from=builder /src/pyproject.toml /src/uv.lock /src/README.md /opt/lucebox-hub/
COPY --from=builder /src/optimizations/pflash /opt/lucebox-hub/optimizations/pflash
COPY --from=builder /src/optimizations/megakernel/pyproject.toml \
/src/optimizations/megakernel/README.md \
/opt/lucebox-hub/optimizations/megakernel/
COPY --from=builder /src/server/scripts /opt/lucebox-hub/server/scripts
COPY --from=builder /src/server/pyproject.toml /src/server/README.md \
/opt/lucebox-hub/server/
COPY --from=builder /src/server/build /opt/lucebox-hub/server/build
COPY share/model_cards /opt/lucebox-hub/share/model_cards
RUN mkdir -p /opt/lucebox-hub/server/share \
&& ln -s /opt/lucebox-hub/share/model_cards \
/opt/lucebox-hub/server/share/model_cards
RUN test -x /opt/lucebox-hub/server/build/test_dflash \
&& test -x /opt/lucebox-hub/server/build/luce_server \
&& test -x /opt/lucebox-hub/server/build/test_server_unit \
&& test -f /opt/lucebox-hub/server/share/model_cards/qwen3.6-27b.json \
&& chmod +x /opt/lucebox-hub/server/scripts/entrypoint.sh
RUN printf '%s\n%s\n%s\n' "$GIT_SHA" "$IMAGE_TAG" "$BUILD_TIME" \
> /opt/lucebox-hub/IMAGE_INFO
# Register the ggml lib dirs with ld.so. HIP names its backend lib dir
# `ggml-hip` (server/CMakeLists.txt:74), where the CUDA image uses `ggml-cuda`.
RUN printf '%s\n%s\n' \
/opt/lucebox-hub/server/build/deps/llama.cpp/ggml/src \
/opt/lucebox-hub/server/build/deps/llama.cpp/ggml/src/ggml-hip \
> /etc/ld.so.conf.d/lucebox-ggml.conf \
&& ldconfig
ENV UV_LINK_MODE=hardlink \
UV_NO_CACHE=1
RUN uv sync --no-dev --frozen --no-editable 2>/dev/null \
|| uv sync --no-dev --frozen --no-editable
RUN chmod -R a+rX /opt/lucebox-hub/.venv /opt/lucebox-hub /opt/uv
# Models live in server/models/ — bind-mount or volume them in.
# ROCm run example (note: AMD uses --device, not --gpus):
# docker run --rm --device /dev/kfd --device /dev/dri \
# --group-add video --group-add render \
# --security-opt seccomp=unconfined -p 8080:8080 \
# -v "$PWD/server/models:/opt/lucebox-hub/server/models" \
# ghcr.io/luce-org/lucebox-hub:rocm
VOLUME ["/opt/lucebox-hub/server/models"]
ENV LUCE_HOST=0.0.0.0 \
LUCE_PORT=8080 \
LUCE_BIN=/opt/lucebox-hub/server/build/test_dflash \
LUCE_SERVER_BIN=/opt/lucebox-hub/server/build/luce_server
EXPOSE 8080
ENTRYPOINT ["/opt/lucebox-hub/server/scripts/entrypoint.sh"]