Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # vim: filetype=dockerfile
- ARG ROCMVERSION=7.2.1
- ARG JETPACK5VERSION=r35.4.1
- ARG JETPACK6VERSION=r36.4.0
- ARG CMAKEVERSION=3.31.2
- ARG NINJAVERSION=1.12.1
- ARG VULKANVERSION=1.4.321.1
- # Default empty stages for local MLX source overrides.
- # Override with: docker build --build-context local-mlx=../mlx --build-context local-mlx-c=../mlx-c
- FROM scratch AS local-mlx
- FROM scratch AS local-mlx-c
- FROM quay.io/almalinuxorg/almalinux:8 AS init
- #RUN dnf update -y
- FROM init AS init-conf
- # TODO: add this repo to fs file
- RUN --mount=type=cache,target=/root/.ccache \
- dnf install -y \
- git \
- unzip \
- epel-release\
- yum-utils \
- && yum-config-manager --add-repo "https://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo"
- FROM init-conf AS base-amd64
- RUN --mount=type=cache,target=/root/.ccache \
- dnf install -y \
- ccache \
- gcc-toolset-13-gcc \
- gcc-toolset-13-gcc-c++ \
- gcc-toolset-13-binutils
- RUN --mount=type=cache,target=/root/.ccache \
- dnf install -y \
- cuda-toolkit-13-4.x86_64 \
- openblas.x86_64 lapack.x86_64 \
- libcudnn9-cuda-13.x86_64 \
- libcudnn9-devel-cuda-13.x86_64 \
- libnccl.x86_64 \
- libnccl-devel.x86_64 \
- && dnf clean all
- FROM base-amd64 AS base
- # TODO move Cmake and ninja to "offlice" version (download and move to dir)
- RUN curl --retry 3 -fsSL https://github.com/Kitware/CMake/releases/download/v3.31.2/cmake-3.31.2-linux-x86_64.tar.gz -o /tmp/cmake.tar.gz \
- && tar xzf /tmp/cmake.tar.gz -C /usr/local --strip-components 1 \
- && rm /tmp/cmake.tar.gz
- RUN curl --retry 3 -fsSL -o /tmp/ninja.zip https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux.zip \
- && unzip /tmp/ninja.zip -d /usr/local/bin \
- && rm /tmp/ninja.zip
- ENV CMAKE_GENERATOR=Ninja
- ENV LDFLAGS=-s
- ENV PATH=/usr/local/cuda-13/bin:/opt/rh/gcc-toolset-13/root/usr/bin:$PATH
- ENV BLAS_INCLUDE_DIRS=/usr/include/openblas
- ENV LAPACK_INCLUDE_DIRS=/usr/include/openblas
- ENV CGO_LDFLAGS="-L/usr/local/cuda-13/lib64 -L/usr/local/cuda-13/targets/x86_64-linux/lib/stubs"
- #
- # Go build
- #
- FROM base AS build
- WORKDIR /go/src/github.com/ollama/ollama
- COPY go.mod go.sum ./
- RUN curl --retry 3 -fsSL https://go.dev/dl/go1.26.0.linux-amd64.tar.gz -o /tmp/go.tar.gz \
- && tar xzf /tmp/go.tar.gz -C /usr/local \
- && rm /tmp/go.tar.gz
- ENV PATH=/usr/local/go/bin:$PATH
- RUN go mod download
- # # #
- # # # GPU toolchain stages — provide compilers for llama-server GPU builds
- # # #
- # # FROM base AS cuda-12-deps
- # # ARG CUDA12VERSION=12.8
- # # RUN dnf install -y cuda-toolkit-${CUDA12VERSION//./-}
- # # ENV PATH=/usr/local/cuda-12/bin:$PATH
- # # FROM base AS rocm-7-deps
- # # ENV PATH=/opt/rocm/llvm/bin:/opt/rocm/hcc/bin:/opt/rocm/hip/bin:/opt/rocm/bin:$PATH
- # # FROM base AS vulkan-deps
- # # ARG VULKANVERSION
- # # RUN ln -s /usr/bin/python3 /usr/bin/python \
- # # && curl --retry 3 -fsSL https://sdk.lunarg.com/sdk/download/${VULKANVERSION}/linux/vulkansdk-linux-x86_64-${VULKANVERSION}.tar.xz -o /tmp/vulkansdk.tar.xz \
- # # && tar xvf /tmp/vulkansdk.tar.xz -C /tmp \
- # # && /tmp/${VULKANVERSION}/vulkansdk -j 8 vulkan-headers \
- # # && /tmp/${VULKANVERSION}/vulkansdk -j 8 spirv-headers \
- # # && /tmp/${VULKANVERSION}/vulkansdk -j 8 shaderc \
- # # && cp -r /tmp/${VULKANVERSION}/x86_64/include/* /usr/local/include/ \
- # # && cp -r /tmp/${VULKANVERSION}/x86_64/lib/* /usr/local/lib \
- # # && cp -r /tmp/${VULKANVERSION}/x86_64/share/* /usr/local/share/ \
- # # && cp -r /tmp/${VULKANVERSION}/x86_64/bin/* /usr/local/bin/ \
- # # && rm -rf /tmp/${VULKANVERSION} /tmp/vulkansdk.tar.xz
- # # ENV VULKAN_SDK=/usr/local
- # # #
- # # # llama-server stages — rebuild when LLAMA_CPP_VERSION, llama/server/, llama/compat/, or cmake/ changes.
- # # #
- # # # CPU stage: llama-server + ggml-base + ggml-cpu variants → lib/ollama/
- # # # GPU stages: GPU backend .so only → lib/ollama/<variant>/
- # # #
- #
- # MLX stage
- #
- FROM build AS mlx-base
- # ARG OLLAMA_MLX_BUILD_JOBS=
- ARG OLLAMA_MLX_NVCC_THREADS=2
- # ARG MLX_CUDA_RAM_MB=
- WORKDIR /go/src/github.com/ollama/ollama
- COPY CMakeLists.txt CMakePresets.json ./
- COPY cmake cmake
- COPY mlx mlx
- COPY mlxrunner/xgrammar/native mlxrunner/xgrammar/native
- COPY go.mod go.sum ./
- COPY MLX_VERSION MLX_C_VERSION ./
- RUN curl --retry 3 -fsSL https://go.dev/dl/go1.26.0.linux-amd64.tar.gz -o /tmp/go.tar.gz \
- && tar xzf /tmp/go.tar.gz -C /usr/local \
- && rm /tmp/go.tar.gz
- RUN --mount=type=cache,target=/root/.ccache go mod download
- # RUN --mount=type=cache,target=/root/.ccache \
- FROM mlx-base AS mlx
- RUN --mount=type=bind,from=local-mlx,target=/tmp/local-mlx,rw \
- --mount=type=bind,from=local-mlx-c,target=/tmp/local-mlx-c,rw \
- if [ -f /tmp/local-mlx/CMakeLists.txt ]; then \
- export OLLAMA_MLX_SOURCE=/tmp/local-mlx; \
- fi \
- && if [ -f /tmp/local-mlx-c/CMakeLists.txt ]; then \
- export OLLAMA_MLX_C_SOURCE=/tmp/local-mlx-c; \
- fi \
- && cmake -S . \
- -B build/mlx_cuda_v13 \
- -DOLLAMA_MLX_BACKENDS=cuda_v13 \
- -DBLAS_INCLUDE_DIRS=/usr/include/openblas \
- -DLAPACK_INCLUDE_DIRS=/usr/include/openblas \
- -DCMAKE_CUDA_FLAGS="-t ${OLLAMA_MLX_NVCC_THREADS}" ${MLX_CUDA_RAM_MB:+-DMLX_CUDA_RAM_MB=${MLX_CUDA_RAM_MB}} \
- -DOLLAMA_PAYLOAD_INSTALL_PREFIX=/go/src/github.com/ollama/ollama/dist \
- && cmake --build build/mlx_cuda_v13 --target ollama-mlx-cuda_v13 -- --parallel 14
- FROM scratch AS publish-mlx
- COPY --from=mlx /go/src/github.com/ollama/ollama/dist/lib/ollama /lib/ollama/
- FROM build AS llama-server-cpu
- COPY LLAMA_CPP_VERSION .
- COPY llama/server llama/server
- COPY llama/compat llama/compat
- COPY cmake cmake
- # hacw a look no dile sate checked in loop and change loop to static
- # RUN --mount=type=cache,target=/root/.ccache \
- RUN --mount=type=cache,target=/root/.ccache \
- cmake -S llama/server --preset cpu
- RUN --mount=type=cache,target=/root/.ccache cmake --build build/llama-server-cpu -- -j 12 \
- && cmake --install build/llama-server-cpu --component llama-server --strip \
- && for lib in \
- /usr/lib64/libgomp.so* \
- /usr/lib64/libomp.so* \
- /opt/rh/gcc-toolset-13/root/usr/lib64/libgomp.so* \
- /opt/rh/gcc-toolset-13/root/usr/lib64/libomp.so*; do \
- [ -e "$lib" ] && cp -a "$lib" dist/lib/ollama/ || true; \
- done
- # CMD [ "/bin/sh" ]
- # FROM build AS publish-llama
- # COPY --from=llama-server-cpu /go/src/github.com/ollama/ollama/dist/lib/ollama /lib/ollama/
- # # # FROM cuda-12-deps AS llama-server-cuda_v12
- # # # COPY LLAMA_CPP_VERSION .
- # # # COPY llama/server llama/server
- # # # COPY llama/compat llama/compat
- # # # COPY cmake cmake
- # # # RUN --mount=type=cache,target=/root/.ccache \
- # # # cmake -S llama/server --preset llama_cuda_v12_linux \
- # # # && cmake --build build/llama-server-cuda_v12 -- -l $(nproc) \
- # # # && cmake --install build/llama-server-cuda_v12 --component llama-server --strip
- # # # FROM scratch AS publish-llama-server-cuda_v12
- # # # COPY --from=llama-server-cuda_v12 dist/lib/ollama /lib/ollama/
- FROM llama-server-cpu AS llama-server-cuda_v13
- COPY LLAMA_CPP_VERSION .
- COPY llama/server llama/server
- COPY llama/compat llama/compat
- COPY cmake cmake
- # RUN --mount=type=cache,target=/root/.ccache \
- RUN --mount=type=cache,target=/root/.ccache \
- cmake -S llama/server \
- -DCMAKE_C_COMPILER_LAUNCHER=ccache \
- -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
- --preset llama_cuda_v13_linux
- RUN --mount=type=cache,target=/root/.ccache \
- cmake --build build/llama-server-cuda_v13 -j 12 \
- && cmake --install build/llama-server-cuda_v13 --component llama-server --strip
- ENTRYPOINT [ "/bin/bash" ]
- # FROM scratch AS publish-llama-server-cuda_v13
- # COPY --from=llama-server-cuda_v13 /go/src/github.com/ollama/ollama/dist/lib/ollama /lib/ollama/
- # # FROM rocm-7-deps AS llama-server-rocm_v7_2
- # # ENV CC=clang CXX=clang++ CXXFLAGS=--gcc-toolchain=/opt/rh/gcc-toolset-13/root/usr
- # # COPY LLAMA_CPP_VERSION .
- # # COPY llama/server llama/server
- # # COPY llama/compat llama/compat
- # # COPY cmake cmake
- # # RUN --mount=type=cache,target=/root/.ccache \
- # # cmake -S llama/server --preset rocm_v7_2_linux \
- # # && cmake --build build/llama-server-rocm_v7_2 -- -l $(nproc) \
- # # && cmake --install build/llama-server-rocm_v7_2 --component llama-server --strip
- # # RUN rm -f dist/lib/ollama/rocm_v7_2/rocblas/library/*gfx90[06]*
- # # FROM scratch AS publish-llama-server-rocm_v7_2
- # # COPY --from=llama-server-rocm_v7_2 dist/lib/ollama /lib/ollama/
- # # FROM vulkan-deps AS llama-server-vulkan
- # # COPY LLAMA_CPP_VERSION .
- # # COPY llama/server llama/server
- # # COPY llama/compat llama/compat
- # # COPY cmake cmake
- # # RUN --mount=type=cache,target=/root/.ccache \
- # # cmake -S llama/server --preset vulkan \
- # # && cmake --build build/llama-server-vulkan -- -l $(nproc) \
- # # && cmake --install build/llama-server-vulkan --component llama-server --strip
- # # FROM scratch AS publish-llama-server-vulkan
- # # COPY --from=llama-server-vulkan dist/lib/ollama /lib/ollama/
- # # #
- # # # JetPack stages — self-contained with their own base images
- # # #
- # # FROM --platform=linux/arm64 nvcr.io/nvidia/l4t-jetpack:${JETPACK5VERSION} AS jetpack-5
- # # ARG CMAKEVERSION
- # # ARG NINJAVERSION
- # # RUN apt-get update && apt-get install -y curl ccache git unzip \
- # # && curl --retry 3 -fsSL https://github.com/Kitware/CMake/releases/download/v${CMAKEVERSION}/cmake-${CMAKEVERSION}-linux-$(uname -m).tar.gz -o /tmp/cmake.tar.gz \
- # # && tar xzf /tmp/cmake.tar.gz -C /usr/local --strip-components 1 \
- # # && rm /tmp/cmake.tar.gz \
- # # && curl --retry 3 -fsSL -o /tmp/ninja.zip https://github.com/ninja-build/ninja/releases/download/v${NINJAVERSION}/ninja-linux-aarch64.zip \
- # # && unzip /tmp/ninja.zip -d /usr/local/bin \
- # # && rm /tmp/ninja.zip
- # # ENV CMAKE_GENERATOR=Ninja
- # # COPY LLAMA_CPP_VERSION .
- # # COPY llama/server llama/server
- # # COPY llama/compat llama/compat
- # # COPY cmake cmake
- # # RUN --mount=type=cache,target=/root/.ccache \
- # # cmake -S llama/server --preset llama_cuda_jetpack5 \
- # # && cmake --build build/llama-server-cuda_jetpack5 -- -l $(nproc) \
- # # && cmake --install build/llama-server-cuda_jetpack5 --component llama-server --strip
- # # FROM scratch AS publish-llama-server-cuda_jetpack5
- # # COPY --from=jetpack-5 dist/lib/ollama /lib/ollama/
- # # FROM --platform=linux/arm64 nvcr.io/nvidia/l4t-jetpack:${JETPACK6VERSION} AS jetpack-6
- # # ARG CMAKEVERSION
- # # ARG NINJAVERSION
- # # RUN apt-get update && apt-get install -y curl ccache git unzip \
- # # && curl --retry 3 -fsSL https://github.com/Kitware/CMake/releases/download/v${CMAKEVERSION}/cmake-${CMAKEVERSION}-linux-$(uname -m).tar.gz -o /tmp/cmake.tar.gz \
- # # && tar xzf /tmp/cmake.tar.gz -C /usr/local --strip-components 1 \
- # # && rm /tmp/cmake.tar.gz \
- # # && curl --retry 3 -fsSL -o /tmp/ninja.zip https://github.com/ninja-build/ninja/releases/download/v${NINJAVERSION}/ninja-linux-aarch64.zip \
- # # && unzip /tmp/ninja.zip -d /usr/local/bin \
- # # && rm /tmp/ninja.zip
- # # ENV CMAKE_GENERATOR=Ninja
- # # COPY LLAMA_CPP_VERSION .
- # # COPY llama/server llama/server
- # # COPY llama/compat llama/compat
- # # COPY cmake cmake
- # # RUN --mount=type=cache,target=/root/.ccache \
- # # cmake -S llama/server --preset llama_cuda_jetpack6 \
- # # && cmake --build build/llama-server-cuda_jetpack6 -- -l $(nproc) \
- # # && cmake --install build/llama-server-cuda_jetpack6 --component llama-server --strip
- # # FROM scratch AS publish-llama-server-cuda_jetpack6
- # # COPY --from=jetpack-6 dist/lib/ollama /lib/ollama/
- # FROM build AS ollama-build
- # ARG GOFLAGS="'-ldflags=-w -s'"
- # ENV CGO_ENABLED=1
- # ARG CGO_CFLAGS
- # ARG CGO_CXXFLAGS
- # ENV CGO_CFLAGS="${CGO_CFLAGS}"
- # ENV CGO_CXXFLAGS="${CGO_CXXFLAGS}"
- # COPY . .
- # COPY --from=llama-server-cuda_v13 /go/src/github.com/ollama/ollama/dist/lib/ollama /lib/ollama/
- # # RUN --mount=type=cache,target=/root/.cache/go-build \
- # RUN --mount=type=cache,target=/root/.cache/go-build \
- # go build -p 1 -trimpath -buildmode=pie -o /bin/ollama .
- # RUN cmake -S . -B build/go-license \
- # -DOLLAMA_LLAMA_BACKENDS="cuda_v13" \
- # -DOLLAMA_MLX_BACKENDS="cuda_v13"
- # RUN cmake --build build/go-license --target ollama-go-license
- # # FROM scratch AS publish-go
- # # COPY --from=ollama-build /bin/ollama /bin/ollama
- # # COPY --from=ollama-build /go/src/github.com/ollama/ollama/build/go-license/lib/ollama/GO_LICENSE /lib/ollama/GO_LICENSE
- # #
- # # Assembly stages — combine llama-server variants + GPU runtime libs
- # #
- # # CMD [ "/bin/sh" ]
- # # FROM scratch AS amd64
- # # COPY --from=llama-server-cpu dist/lib/ollama /lib/ollama/
- # # COPY --from=llama-server-cuda_v12 dist/lib/ollama /lib/ollama/
- # # COPY --from=llama-server-cuda_v13 dist/lib/ollama /lib/ollama/
- # # COPY --from=llama-server-vulkan dist/lib/ollama /lib/ollama/
- # # FROM scratch AS rocm
- # # COPY --from=llama-server-cpu dist/lib/ollama /lib/ollama
- # # COPY --from=llama-server-rocm_v7_2 dist/lib/ollama /lib/ollama
- # # FROM --platform=linux/amd64 scratch AS amd64-archive
- # # COPY --from=amd64 /lib/ollama /lib/ollama/
- # # COPY --from=llama-server-rocm_v7_2 dist/lib/ollama /lib/ollama/
- # # FROM --platform=linux/arm64 scratch AS arm64-archive
- # # COPY --from=arm64 /lib/ollama /lib/ollama/
- # # FROM ${TARGETARCH}-archive AS archive
- # # COPY --from=build /bin/ollama /bin/ollama
- # # COPY --from=build /go/src/github.com/ollama/ollama/build/go-license/lib/ollama/GO_LICENSE /lib/ollama/GO_LICENSE
- # FROM ubuntu:24.04 AS image-archive
- # COPY --from=ollama-build /bin/ollama /bin/ollama
- # COPY --from=ollama-build /go/src/github.com/ollama/ollama/build/go-license/lib/ollama/GO_LICENSE /lib/ollama/GO_LICENSE
- # FROM image-archive
- # # # SHELL [ "/bin/bash" ]
- # WORKDIR /usr/bin
- # # COPY --from=image-archive "/bin/ollama" ./
- # ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- # ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64
- # ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
- # ENV NVIDIA_VISIBLE_DEVICES=all
- # ENV OLLAMA_HOST=0.0.0.0:11434
- # ENV OLLAMA_DEBUG=1
- # ENV OLLAMA_KEEP_ALIVE=120m
- # ENV OLLAMA_KV_CACHE_TYPE=q8_0
- # ENV OLLAMA_CONTEXT_LENGTH=8192
- # #OLLAMA_FLASH_ATTENTION=1
- # ENV OLLAMA_MAX_LOADED_MODELS=1
- # ENV OLLAMA_NUM_PARALLEL=1
- # # for img generation
- # ENV OLLAMA_GPU_OVERHEAD=1073741824
- # #shared memory between vram and ram 1=on (enable when OOM)
- # ENV GGML_CUDA_ENABLE_UNIFIED_MEMORY=1
- # #GGML_CUDA_ENABLE_UNIFIED_MEMORY=0
- # EXPOSE 11434
- # # # ENTRYPOINT ["/bin/ollama"]
- # # # # CMD ["serve"]
- # # ENTRYPOINT [ "/bin/sh" ]
- # CMD [ "/bin/sh" ]
Advertisement
Add Comment
Please, Sign In to add comment