diff --git a/container-images/asahi/Containerfile b/container-images/asahi/Containerfile index 06e5ce86..95f19d29 100644 --- a/container-images/asahi/Containerfile +++ b/container-images/asahi/Containerfile @@ -1,25 +1,11 @@ FROM fedora:41 -# renovate: datasource=github-releases depName=containers/omlmd extractVersion=^v(?.*) -ARG OMLMD_VERSION=0.1.6 ARG LLAMA_CPP_SHA=1329c0a75e6a7defc5c380eaf80d8e0f66d7da78 # renovate: datasource=git-refs depName=ggerganov/whisper.cpp packageName=https://github.com/ggerganov/whisper.cpp gitRef=master versioning=loose type=digest ARG WHISPER_CPP_SHA=31aea563a83803c710691fed3e8d700e06ae6788 -RUN dnf install -y dnf-plugins-core && \ - dnf copr enable -y @asahi/fedora-remix-branding && \ - dnf install -y asahi-repos && \ - dnf install -y mesa-vulkan-drivers vulkan-headers vulkan-loader-devel \ - vulkan-tools spirv-tools glslc glslang git procps-ng vim cmake gcc-c++ \ - python3-pip python3-argcomplete && \ - dnf clean all && \ - rm -rf /var/cache/*dnf* - -RUN /usr/bin/python3 --version -RUN pip install "omlmd==${OMLMD_VERSION}" - COPY ../scripts /scripts RUN chmod +x /scripts/*.sh && \ - /scripts/build_llama_and_whisper.sh "$LLAMA_CPP_SHA" "$WHISPER_CPP_SHA" \ - "/usr" "-DGGML_VULKAN=1" + /scripts/build_llama_and_whisper.sh "asahi" "$LLAMA_CPP_SHA" \ + "$WHISPER_CPP_SHA" "/usr" "-DGGML_VULKAN=1" diff --git a/container-images/cuda/Containerfile b/container-images/cuda/Containerfile index 8cda78a2..40a45153 100644 --- a/container-images/cuda/Containerfile +++ b/container-images/cuda/Containerfile @@ -5,32 +5,17 @@ ARG LLAMA_CPP_SHA=1329c0a75e6a7defc5c380eaf80d8e0f66d7da78 # renovate: datasource=git-refs depName=ggerganov/whisper.cpp packageName=https://github.com/ggerganov/whisper.cpp gitRef=master versioning=loose type=digest ARG WHISPER_CPP_SHA=31aea563a83803c710691fed3e8d700e06ae6788 -# Install dependencies only needed for building -RUN dnf install -y git cmake gcc-c++ && \ - dnf clean all && rm -rf /var/cache/*dnf* - -# Set the temporary installation directory -ARG INSTALL_PREFIX=/tmp/install - COPY ../scripts /scripts RUN chmod +x /scripts/*.sh && \ - /scripts/build_llama_and_whisper.sh "$LLAMA_CPP_SHA" "$WHISPER_CPP_SHA" \ - "$INSTALL_PREFIX" \ + /scripts/build_llama_and_whisper.sh "cuda" "$LLAMA_CPP_SHA" \ + "$WHISPER_CPP_SHA" "/tmp/install" \ "-DGGML_CUDA=1" "-DCMAKE_EXE_LINKER_FLAGS=-Wl,--allow-shlib-undefined" # Final runtime image FROM docker.io/nvidia/cuda:12.6.2-runtime-ubi9 -# renovate: datasource=github-releases depName=containers/omlmd extractVersion=^v(?.*) -ARG OMLMD_VERSION=0.1.6 - -# Install minimal runtime dependencies -RUN dnf install -y python3 python3-pip && \ - dnf clean all && \ - rm -rf /var/cache/*dnf* - -# Install Python packages in the runtime image -RUN pip install "omlmd==${OMLMD_VERSION}" +RUN dnf install -y python3 && \ + dnf clean all && rm -rf /var/cache/*dnf* # Copy the entire installation directory from the builder COPY --from=builder /tmp/install /usr diff --git a/container-images/ramalama/Containerfile b/container-images/ramalama/Containerfile index 3dcce925..b1efaeab 100644 --- a/container-images/ramalama/Containerfile +++ b/container-images/ramalama/Containerfile @@ -1,42 +1,13 @@ FROM registry.access.redhat.com/ubi9/ubi:9.4-1214.1729773476 -# renovate: datasource=github-releases depName=containers/omlmd extractVersion=^v(?.*) -ARG OMLMD_VERSION=0.1.6 ARG LLAMA_CPP_SHA=1329c0a75e6a7defc5c380eaf80d8e0f66d7da78 # renovate: datasource=git-refs depName=ggerganov/whisper.cpp packageName=https://github.com/ggerganov/whisper.cpp gitRef=master versioning=loose type=digest ARG WHISPER_CPP_SHA=31aea563a83803c710691fed3e8d700e06ae6788 -# vulkan-headers vulkan-loader-devel vulkan-tools glslc glslang python3-pip mesa-libOpenCL-$MESA_VER.aarch64 -RUN dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm && \ - crb enable && \ - dnf install -y epel-release && \ - dnf --enablerepo=ubi-9-appstream-rpms install -y git procps-ng vim \ - dnf-plugins-core python3-dnf-plugin-versionlock cmake gcc-c++ \ - python3-pip python3-argcomplete && \ - dnf copr enable -y slp/mesa-krunkit epel-9-$(uname -m) && \ - dnf install -y mesa-vulkan-drivers-23.3.3-102.el9 \ - vulkan-headers vulkan-loader-devel vulkan-tools spirv-tools glslc && \ - dnf clean all && \ - rm -rf /var/cache/*dnf* - -RUN /usr/bin/python3 --version -RUN pip install "omlmd==${OMLMD_VERSION}" - -RUN dnf config-manager --add-repo \ - https://mirror.stream.centos.org/9-stream/AppStream/$(uname -m)/os/ -RUN curl --retry 8 --retry-all-errors -o \ - /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official \ - http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-Official && \ - cat /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official -RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official -RUN dnf install -y glslang && \ - dnf clean all && \ - rm -rf /var/cache/*dnf* - COPY ../scripts /scripts RUN chmod +x /scripts/*.sh && \ - /scripts/build_llama_and_whisper.sh "$LLAMA_CPP_SHA" "$WHISPER_CPP_SHA" \ - "/usr" "-DGGML_KOMPUTE=1" + /scripts/build_llama_and_whisper.sh "ramalama" "$LLAMA_CPP_SHA" \ + "$WHISPER_CPP_SHA" "/usr" "-DGGML_KOMPUTE=1" ENV WHISPER_CPP_SHA=${WHISPER_CPP_SHA} ENV LLAMA_CPP_SHA=${LLAMA_CPP_SHA} diff --git a/container-images/rocm/Containerfile b/container-images/rocm/Containerfile index b32f6be2..fd71f4fb 100644 --- a/container-images/rocm/Containerfile +++ b/container-images/rocm/Containerfile @@ -1,27 +1,12 @@ FROM quay.io/ramalama/ramalama:latest -RUN /usr/bin/python3 --version - ARG ROCM_VERSION=6.2.2 ARG AMDGPU_VERSION=6.2.2 COPY rocm/amdgpu.repo /etc/yum.repos.d/ COPY rocm/rocm.repo /etc/yum.repos.d/ - -RUN dnf config-manager --add-repo \ - https://mirror.stream.centos.org/9-stream/AppStream/$(uname -m)/os/ -RUN curl --retry 8 --retry-all-errors -o \ - /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official \ - http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-Official && \ - cat /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official -RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official - COPY scripts /scripts -RUN dnf install -y rocm-dev hipblas-devel rocblas-devel && \ - dnf clean all && \ - chmod +x /scripts/*.sh && \ - /scripts/build_llama_and_whisper.sh "$LLAMA_CPP_SHA" "$WHISPER_CPP_SHA" \ - "/usr" "-DGGML_HIPBLAS=1" && \ - rm -rf /var/cache/*dnf* /opt/rocm-*/lib/llvm \ - /opt/rocm-*/lib/rocblas/library/*gfx9* +RUN chmod +x /scripts/*.sh && \ + /scripts/build_llama_and_whisper.sh "rocm" "$LLAMA_CPP_SHA" \ + "$WHISPER_CPP_SHA" "/usr" "-DGGML_HIPBLAS=1" diff --git a/container-images/scripts/build_llama_and_whisper.sh b/container-images/scripts/build_llama_and_whisper.sh index ff57218a..2a573634 100644 --- a/container-images/scripts/build_llama_and_whisper.sh +++ b/container-images/scripts/build_llama_and_whisper.sh @@ -1,34 +1,85 @@ #!/bin/bash +dnf_install() { + local rpm_list=("python3" "python3-pip" "gcc-c++" "cmake" "vim" "procps-ng" \ + "git") + if [ "$containerfile" = "ramalama" ]; then + dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm + crb enable + dnf install -y epel-release + rpm_list+=("dnf-plugins-core" "python3-dnf-plugin-versionlock" \ + "python3-argcomplete") + dnf --enablerepo=ubi-9-appstream-rpms install -y "${rpm_list[@]}" + local uname_m + uname_m="$(uname -m)" + dnf copr enable -y slp/mesa-krunkit "epel-9-$uname_m" + dnf install -y mesa-vulkan-drivers-23.3.3-102.el9 vulkan-headers \ + vulkan-loader-devel vulkan-tools spirv-tools glslc + local url="https://mirror.stream.centos.org/9-stream/AppStream/$uname_m/os/" + dnf config-manager --add-repo "$url" + url="http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-Official" + curl --retry 8 --retry-all-errors -o \ + /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official "$url" + rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official + dnf install -y glslang + elif [ "$containerfile" = "asahi" ]; then + dnf install -y dnf-plugins-core + dnf copr enable -y @asahi/fedora-remix-branding + dnf install -y asahi-repos + dnf install -y mesa-vulkan-drivers vulkan-headers vulkan-loader-devel \ + vulkan-tools spirv-tools glslc glslang python3-argcomplete \ + "${rpm_list[@]}" + elif [ "$containerfile" = "rocm" ]; then + dnf install -y rocm-dev hipblas-devel rocblas-devel + else + dnf install -y "${rpm_list[@]}" + fi +} + +cmake_steps() { + local flag="$1" + cmake -B build "${common_flags[@]}" "$flag" + cmake --build build --config Release -j"$(nproc)" + cmake --install build +} + main() { set -e - local llama_cpp_sha="$1" - local whisper_cpp_sha="$2" - local install_prefix="$3" - local build_flag_1="$4" - local build_flag_2="$5" + local containerfile="$1" + local llama_cpp_sha="$2" + local whisper_cpp_sha="$3" + local install_prefix="$4" + local build_flag_1="$5" + local build_flag_2="$6" + local common_flags=("-DGGML_CCACHE=0" \ + "-DCMAKE_INSTALL_PREFIX=$install_prefix" "$build_flag_1") + if [ -n "$build_flag_2" ]; then + common_flags+=("$build_flag_2") + fi + + dnf_install + git clone https://github.com/ggerganov/llama.cpp cd llama.cpp git reset --hard "$llama_cpp_sha" - cmake -B build -DGGML_CCACHE=0 "$build_flag_1" "$build_flag_2" \ - -DCMAKE_INSTALL_PREFIX="$install_prefix" - cmake --build build --config Release -j"$(nproc)" - cmake --install build + cmake_steps cd .. - rm -rf llama.cpp git clone https://github.com/ggerganov/whisper.cpp cd whisper.cpp git reset --hard "$whisper_cpp_sha" - cmake -B build -DGGML_CCACHE=0 "$build_flag_1" "$build_flag_2" \ - -DBUILD_SHARED_LIBS=NO -DCMAKE_INSTALL_PREFIX="$install_prefix" - cmake --build build --config Release -j"$(nproc)" - cmake --install build + cmake_steps "-DBUILD_SHARED_LIBS=NO" mv build/bin/main "$install_prefix/bin/whisper-main" mv build/bin/server "$install_prefix/bin/whisper-server" cd .. - rm -rf whisper.cpp + + CMAKE_ARGS="${common_flags[*]}" FORCE_CMAKE=1 \ + pip install --prefix="$install_prefix" 'llama-cpp-python[server]' + + dnf clean all + rm -rf /var/cache/*dnf* /opt/rocm-*/lib/llvm \ + /opt/rocm-*/lib/rocblas/library/*gfx9* llama.cpp whisper.cpp } main "$@" diff --git a/container-images/vulkan/Containerfile b/container-images/vulkan/Containerfile index 5d9eaacc..b89b8348 100644 --- a/container-images/vulkan/Containerfile +++ b/container-images/vulkan/Containerfile @@ -2,6 +2,6 @@ FROM quay.io/ramalama/ramalama:latest COPY ../scripts /scripts RUN chmod +x /scripts/*.sh && \ - /scripts/build_llama_and_whisper.sh "$LLAMA_CPP_SHA" "$WHISPER_CPP_SHA" \ - "/usr" "-DGGML_VULKAN=1" + /scripts/build_llama_and_whisper.sh "vulkan" "$LLAMA_CPP_SHA" \ + "$WHISPER_CPP_SHA" "/usr" "-DGGML_VULKAN=1"