Skip to content

Commit

Permalink
Merge pull request #430 from containers/llama-cpp-python-server
Browse files Browse the repository at this point in the history
Install llama-cpp-python[server]
  • Loading branch information
rhatdan authored Nov 11, 2024
2 parents 752395d + 99eade4 commit 5cc73ed
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 101 deletions.
18 changes: 2 additions & 16 deletions container-images/asahi/Containerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
FROM fedora:41

# renovate: datasource=github-releases depName=containers/omlmd extractVersion=^v(?<version>.*)
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"

23 changes: 4 additions & 19 deletions container-images/cuda/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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(?<version>.*)
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
Expand Down
33 changes: 2 additions & 31 deletions container-images/ramalama/Containerfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,13 @@
FROM registry.access.redhat.com/ubi9/ubi:9.4-1214.1729773476

# renovate: datasource=github-releases depName=containers/omlmd extractVersion=^v(?<version>.*)
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}
21 changes: 3 additions & 18 deletions container-images/rocm/Containerfile
Original file line number Diff line number Diff line change
@@ -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"

81 changes: 66 additions & 15 deletions container-images/scripts/build_llama_and_whisper.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
Expand Down
4 changes: 2 additions & 2 deletions container-images/vulkan/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 5cc73ed

Please sign in to comment.