fix: use ollama v0.23.2 native CMake build system for ROCm 6 + gfx906

The old Dockerfile used the deprecated llama.cpp/ subdirectory approach
which doesn't exist in ollama v0.23.2. Now using the official CMake
presets (ROCm 6 preset) with AMDGPU_TARGETS including gfx906:xnack-.
This commit is contained in:
2026-05-09 22:13:47 -04:00
parent f023dc1ee4
commit c6d2f5918f

View File

@@ -1,50 +1,74 @@
# ollama-gfx906/Dockerfile # ollama-gfx906/Dockerfile
# #
# Custom ollama image with ROCm 6.1 + gfx906 (MI50) support. # Custom ollama image with ROCm 6.1 + gfx906 (MI50) support.
# The default ollama/rocm image ships ROCm 7.2 which dropped gfx906 support. # The official ollama/rocm image ships ROCm 7.2 which dropped gfx906.
# This builds ollama and its llama.cpp runner from source, targeting gfx906. # This uses v0.23.2's native CMake build system with AMDGPU_TARGETS including gfx906.
# #
# Build: docker build -t ollama/ollama:rocm-gfx906 ./ai/ollama # Build: docker build -t ollama/ollama:rocm-gfx906 ai/ollama
FROM rocm/dev-ubuntu-22.04:6.1.2-complete AS builder FROM rocm/dev-ubuntu-22.04:6.1.2-complete AS builder
# Build dependencies (CMake, Ninja, Go)
ARG CMAKEVERSION=3.31.2
ARG NINJAVERSION=1.12.1
ARG GOLANG_VERSION=1.22.0
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
git golang-go cmake build-essential pkg-config \ curl git ccache build-essential pkg-config \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Install CMake from official binaries
RUN curl -fsSL https://github.com/Kitware/CMake/releases/download/v${CMAKEVERSION}/cmake-${CMAKEVERSION}-linux-x86_64.tar.gz \
| tar xz -C /usr/local --strip-components 1
# Install Ninja
RUN curl -fsSL -o /tmp/ninja.zip \
https://github.com/ninja-build/ninja/releases/download/v${NINJAVERSION}/ninja-linux.zip \
&& unzip /tmp/ninja.zip -d /usr/local/bin && rm /tmp/ninja.zip
# Install Go
RUN curl -fsSL https://go.dev/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz \
| tar xz -C /usr/local
ENV PATH=/usr/local/go/bin:$PATH
ARG OLLAMA_VERSION=v0.23.2 ARG OLLAMA_VERSION=v0.23.2
RUN git clone --depth 1 --branch ${OLLAMA_VERSION} https://github.com/ollama/ollama.git /build RUN git clone --depth 1 --branch ${OLLAMA_VERSION} https://github.com/ollama/ollama.git /build
WORKDIR /build WORKDIR /build
# ROCm paths from the base image
ENV HIP_PATH=/opt/rocm ENV HIP_PATH=/opt/rocm
ENV ROCM_PATH=/opt/rocm ENV ROCM_PATH=/opt/rocm
ENV PATH=/opt/rocm/bin:/opt/rocm/hip/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ENV PATH=/opt/rocm/bin:/opt/rocm/hip/bin:/opt/rocm/hcc/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN cd llama.cpp && \ ENV CMAKE_GENERATOR=Ninja
mkdir -p build && cd build && \ ENV LDFLAGS=-s
# Build with ROCm 6 preset + gfx906 target
RUN mkdir -p build && cd build && \
cmake .. \ cmake .. \
-DLLAMA_HIPBLAS=ON \ --preset 'ROCm 6' \
-DCMAKE_C_COMPILER=clang \ -DAMDGPU_TARGETS="gfx906:xnack-;gfx940;gfx1010;gfx1030;gfx1100;gfx1200" \
-DCMAKE_CXX_COMPILER=clang++ \ -DCMAKE_BUILD_TYPE=Release && \
-DAMDGPU_TARGETS=gfx906 \ cmake --build . -- -l $(nproc) && \
-DCMAKE_BUILD_TYPE=Release \ cmake --install . --component HIP --strip --prefix /build/dist
-DLLAMA_NATIVE=OFF \
-DLLAMA_BUILD_TESTS=OFF \
-DLLAMA_BUILD_EXAMPLES=OFF \
-DLLAMA_BUILD_SERVER=OFF && \
cmake --build . --config Release -j$(nproc) && \
cmake --install . --prefix /build/dist
ENV CGO_ENABLED=0 # Build the Go binary
RUN go build -trimpath -o dist/ollama . ENV CGO_ENABLED=1
ENV CC=clang
ENV CXX=clang++
RUN go build -trimpath -o /build/dist/ollama .
FROM ubuntu:22.04 # ---------- Runtime image ----------
FROM ubuntu:24.04
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates curl libstdc++6 libgomp1 \ ca-certificates curl libstdc++6 libgomp1 libvulkan1 libopenblas0 \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Copy ROCm 6.1 runtime libraries
COPY --from=builder /opt/rocm/lib/ /opt/rocm/lib/ COPY --from=builder /opt/rocm/lib/ /opt/rocm/lib/
COPY --from=builder /opt/rocm/share/ /opt/rocm/share/ COPY --from=builder /opt/rocm/share/ /opt/rocm/share/
# Copy ollama binary and backend
COPY --from=builder /build/dist/ollama /usr/bin/ollama COPY --from=builder /build/dist/ollama /usr/bin/ollama
COPY --from=builder /build/dist/lib/ /usr/lib/ollama/ COPY --from=builder /build/dist/lib/ /usr/lib/ollama/