Updating toolboxes with a two-stage build process to reduce size

This commit is contained in:
Donato Capitella
2025-08-16 10:21:59 +01:00
parent 551d14b11d
commit ca0800bd01
9 changed files with 492 additions and 209 deletions
+66 -30
View File
@@ -1,7 +1,8 @@
FROM fedora:rawhide
# build stage
FROM registry.fedoraproject.org/fedora:rawhide AS builder
# getting Rocm6.4.3 repos
RUN <<EOF
# rocm 6.4.3 repo
RUN <<'EOF'
tee /etc/yum.repos.d/rocm.repo <<REPO
[ROCm-6.4.3]
name=ROCm6.4.3
@@ -11,55 +12,90 @@ priority=50
gpgcheck=1
gpgkey=https://repo.radeon.com/rocm/rocm.gpg.key
REPO
EOF
# Install build dependencies and tools
RUN dnf install -y \
# deps
RUN dnf -y --nodocs --setopt=install_weak_deps=False install \
make gcc cmake lld clang clang-devel compiler-rt libcurl-devel \
rocm rocminfo radeontop \
git vim \
&& dnf clean all
git vim sudo rsync \
&& dnf clean all && rm -rf /var/cache/dnf/*
WORKDIR /opt/
# rocWMMA
WORKDIR /opt
RUN git clone -b release/rocm-rel-7.0 https://github.com/ROCm/rocWMMA.git
RUN sudo mkdir -p /usr/include/rocwmma
RUN sudo cp -r rocWMMA/library/include/rocwmma /usr/include/
# Set up working directory
# llama.cpp
WORKDIR /opt/llama.cpp
# Clone llama.cpp repository (with submodules)
RUN git clone --recursive https://github.com/ggerganov/llama.cpp.git .
# Build llama.cpp with HIP support
# build
RUN git clean -xdf \
&& git pull \
&& git submodule update --recursive \
&& \
# Configure and compile with HIP toolchain
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" \
cmake -S . -B build \
-DGGML_HIP=ON \
-DAMDGPU_TARGETS=gfx1151 \
-DCMAKE_BUILD_TYPE=Release \
-DLLAMA_HIP_UMA=ON \
-DGGML_HIP_ROCWMMA_FATTN=ON \
&& cmake --build build --config Release -- -j$(nproc) \
&& cmake --install build --config Release
&& git pull \
&& git submodule update --recursive \
&& HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" \
cmake -S . -B build \
-DGGML_HIP=ON \
-DAMDGPU_TARGETS=gfx1151 \
-DCMAKE_BUILD_TYPE=Release \
-DLLAMA_HIP_UMA=ON \
-DGGML_HIP_ROCWMMA_FATTN=ON \
&& cmake --build build --config Release -- -j$(nproc) \
&& cmake --install build --config Release
# libs
RUN find /opt/llama.cpp/build -type f -name 'lib*.so*' -exec cp {} /usr/lib64/ \; \
&& ldconfig
# helper
COPY gguf-vram-estimator.py /usr/local/bin/gguf-vram-estimator.py
RUN chmod +x /usr/local/bin/gguf-vram-estimator.py
# runtime stage
FROM registry.fedoraproject.org/fedora-minimal:rawhide
# rocm 6.4.3 repo
RUN <<'EOF'
tee /etc/yum.repos.d/rocm.repo <<REPO
[ROCm-6.4.3]
name=ROCm6.4.3
baseurl=https://repo.radeon.com/rocm/el9/6.4.3/main
enabled=1
priority=50
gpgcheck=1
gpgkey=https://repo.radeon.com/rocm/rocm.gpg.key
REPO
EOF
# runtime deps
RUN microdnf -y --nodocs --setopt=install_weak_deps=0 install \
bash ca-certificates libatomic libstdc++ libgcc \
rocm rocminfo radeontop \
&& microdnf clean all && rm -rf /var/cache/dnf/*
# copy
COPY --from=builder /usr/local/ /usr/local/
COPY --from=builder /usr/include/rocwmma /usr/include/rocwmma
# ld
RUN echo "/usr/local/lib" > /etc/ld.so.conf.d/local.conf \
&& echo "/usr/local/lib64" >> /etc/ld.so.conf.d/local.conf \
&& ldconfig \
&& cp -n /usr/local/lib/libllama*.so* /usr/lib64/ 2>/dev/null || true \
&& ldconfig
# helper
COPY gguf-vram-estimator.py /usr/local/bin/gguf-vram-estimator.py
RUN chmod +x /usr/local/bin/gguf-vram-estimator.py
# profile
RUN printf '%s\n' \
'export ROCBLAS_USE_HIPBLASLT=1' \
> /etc/profile.d/rocm.sh \
&& chmod +x /etc/profile.d/rocm.sh \
> /etc/profile.d/rocm.sh && chmod +x /etc/profile.d/rocm.sh \
&& echo 'source /etc/profile.d/rocm.sh' >> /etc/bashrc
# Default to interactive shell
# shell
CMD ["/bin/bash"]