2024-07-17 21:44:19 +00:00
|
|
|
ARG GOLANG_VERSION=1.22.5
|
2024-01-21 19:37:11 +00:00
|
|
|
ARG CMAKE_VERSION=3.22.1
|
2024-06-14 03:46:14 +00:00
|
|
|
ARG CUDA_VERSION_11=11.3.1
|
2024-07-12 18:35:41 +00:00
|
|
|
ARG CUDA_V11_ARCHITECTURES="50;52;53;60;61;62;70;72;75;80;86"
|
2024-06-14 03:46:14 +00:00
|
|
|
ARG CUDA_VERSION_12=12.4.0
|
2024-07-12 18:35:41 +00:00
|
|
|
ARG CUDA_V12_ARCHITECTURES="60;61;62;70;72;75;80;86;87;89;90;90a"
|
2024-07-15 22:10:22 +00:00
|
|
|
ARG ROCM_VERSION=6.1.2
|
2023-09-22 18:57:31 +00:00
|
|
|
|
2024-01-21 19:37:11 +00:00
|
|
|
# Copy the minimal context we need to run the generate scripts
|
|
|
|
FROM scratch AS llm-code
|
|
|
|
COPY .git .git
|
|
|
|
COPY .gitmodules .gitmodules
|
|
|
|
COPY llm llm
|
2023-09-08 20:41:49 +00:00
|
|
|
|
2024-06-14 03:46:14 +00:00
|
|
|
FROM --platform=linux/amd64 nvidia/cuda:$CUDA_VERSION_11-devel-centos7 AS cuda-11-build-amd64
|
2024-01-21 19:37:11 +00:00
|
|
|
ARG CMAKE_VERSION
|
|
|
|
COPY ./scripts/rh_linux_deps.sh /
|
|
|
|
RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
|
|
|
|
ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
|
2024-03-26 20:04:17 +00:00
|
|
|
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
|
|
|
|
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
|
2024-01-21 20:57:13 +00:00
|
|
|
ARG CGO_CFLAGS
|
2024-07-12 18:35:41 +00:00
|
|
|
ARG CUDA_V11_ARCHITECTURES
|
2024-07-08 19:50:11 +00:00
|
|
|
ENV GOARCH amd64
|
2024-08-09 14:21:40 +00:00
|
|
|
RUN --mount=type=cache,target=/root/.ccache \
|
2024-06-14 03:46:14 +00:00
|
|
|
OLLAMA_SKIP_STATIC_GENERATE=1 \
|
|
|
|
OLLAMA_SKIP_CPU_GENERATE=1 \
|
2024-07-12 18:35:41 +00:00
|
|
|
CMAKE_CUDA_ARCHITECTURES="${CUDA_V11_ARCHITECTURES}" \
|
2024-06-14 03:46:14 +00:00
|
|
|
CUDA_VARIANT="_v11" \
|
|
|
|
bash gen_linux.sh
|
2024-01-21 19:37:11 +00:00
|
|
|
|
2024-06-14 03:46:14 +00:00
|
|
|
FROM --platform=linux/amd64 nvidia/cuda:$CUDA_VERSION_12-devel-centos7 AS cuda-12-build-amd64
|
|
|
|
ARG CMAKE_VERSION
|
|
|
|
COPY ./scripts/rh_linux_deps.sh /
|
|
|
|
RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
|
|
|
|
ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
|
|
|
|
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
|
|
|
|
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
|
|
|
|
ARG CGO_CFLAGS
|
2024-07-12 18:35:41 +00:00
|
|
|
ARG CUDA_V12_ARCHITECTURES
|
2024-06-14 03:46:14 +00:00
|
|
|
ENV GOARCH amd64
|
|
|
|
RUN --mount=type=cache,target=/root/.ccache \
|
|
|
|
OLLAMA_SKIP_STATIC_GENERATE=1 \
|
|
|
|
OLLAMA_SKIP_CPU_GENERATE=1 \
|
2024-07-12 18:35:41 +00:00
|
|
|
CMAKE_CUDA_ARCHITECTURES="${CUDA_V12_ARCHITECTURES}" \
|
2024-06-14 03:46:14 +00:00
|
|
|
CUDA_VARIANT="_v12" \
|
2024-07-12 18:35:41 +00:00
|
|
|
OLLAMA_CUSTOM_CUDA_DEFS="-DGGML_CUDA_USE_GRAPHS=on" \
|
2024-06-14 03:46:14 +00:00
|
|
|
bash gen_linux.sh
|
|
|
|
|
|
|
|
FROM --platform=linux/arm64 nvidia/cuda:$CUDA_VERSION_11-devel-rockylinux8 AS cuda-11-build-server-arm64
|
2024-01-21 19:37:11 +00:00
|
|
|
ARG CMAKE_VERSION
|
|
|
|
COPY ./scripts/rh_linux_deps.sh /
|
|
|
|
RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
|
2024-03-26 02:01:11 +00:00
|
|
|
ENV PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
|
2024-03-26 20:04:17 +00:00
|
|
|
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
|
|
|
|
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
|
2024-01-21 20:57:13 +00:00
|
|
|
ARG CGO_CFLAGS
|
2024-07-12 18:35:41 +00:00
|
|
|
ARG CUDA_V11_ARCHITECTURES
|
|
|
|
ENV GOARCH arm64
|
|
|
|
RUN OLLAMA_SKIP_STATIC_GENERATE=1 \
|
|
|
|
OLLAMA_SKIP_CPU_GENERATE=1 \
|
|
|
|
CMAKE_CUDA_ARCHITECTURES="${CUDA_V11_ARCHITECTURES}" \
|
|
|
|
CUDA_VARIANT="_v11" \
|
|
|
|
bash gen_linux.sh
|
|
|
|
|
|
|
|
FROM --platform=linux/arm64 nvidia/cuda:$CUDA_VERSION_12-devel-rockylinux8 AS cuda-12-build-server-arm64
|
|
|
|
ARG CMAKE_VERSION
|
|
|
|
COPY ./scripts/rh_linux_deps.sh /
|
|
|
|
RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
|
|
|
|
ENV PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
|
|
|
|
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
|
|
|
|
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
|
|
|
|
ARG CGO_CFLAGS
|
|
|
|
ARG CUDA_V12_ARCHITECTURES
|
2024-07-08 19:50:11 +00:00
|
|
|
ENV GOARCH arm64
|
2024-06-14 03:46:14 +00:00
|
|
|
RUN --mount=type=cache,target=/root/.ccache \
|
2024-07-12 18:35:41 +00:00
|
|
|
OLLAMA_SKIP_STATIC_GENERATE=1 \
|
|
|
|
OLLAMA_SKIP_CPU_GENERATE=1 \
|
|
|
|
CMAKE_CUDA_ARCHITECTURES="${CUDA_V12_ARCHITECTURES}" \
|
|
|
|
CUDA_VARIANT="_v12" \
|
|
|
|
OLLAMA_CUSTOM_CUDA_DEFS="-DGGML_CUDA_USE_GRAPHS=on" \
|
|
|
|
bash gen_linux.sh
|
2024-05-31 04:54:07 +00:00
|
|
|
|
2024-01-21 19:37:11 +00:00
|
|
|
|
2024-02-16 01:15:09 +00:00
|
|
|
FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete AS rocm-build-amd64
|
2024-01-21 19:37:11 +00:00
|
|
|
ARG CMAKE_VERSION
|
|
|
|
COPY ./scripts/rh_linux_deps.sh /
|
|
|
|
RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
|
|
|
|
ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
|
|
|
|
ENV LIBRARY_PATH /opt/amdgpu/lib64
|
2024-03-26 20:04:17 +00:00
|
|
|
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
|
|
|
|
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
|
2024-01-21 20:57:13 +00:00
|
|
|
ARG CGO_CFLAGS
|
|
|
|
ARG AMDGPU_TARGETS
|
2024-07-08 19:50:11 +00:00
|
|
|
ENV GOARCH amd64
|
2024-08-09 14:21:40 +00:00
|
|
|
RUN --mount=type=cache,target=/root/.ccache \
|
|
|
|
OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_SKIP_CPU_GENERATE=1 bash gen_linux.sh
|
2024-08-14 23:32:57 +00:00
|
|
|
RUN mkdir -p ../../dist/linux-amd64/lib/ollama && \
|
|
|
|
(cd /opt/rocm/lib && tar cf - rocblas/library) | (cd ../../dist/linux-amd64/lib/ollama && tar xf - )
|
2024-01-21 19:37:11 +00:00
|
|
|
|
2024-01-21 20:57:13 +00:00
|
|
|
FROM --platform=linux/amd64 centos:7 AS cpu-builder-amd64
|
2024-01-21 19:37:11 +00:00
|
|
|
ARG CMAKE_VERSION
|
|
|
|
ARG GOLANG_VERSION
|
|
|
|
COPY ./scripts/rh_linux_deps.sh /
|
|
|
|
RUN CMAKE_VERSION=${CMAKE_VERSION} GOLANG_VERSION=${GOLANG_VERSION} sh /rh_linux_deps.sh
|
|
|
|
ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
|
2024-03-26 20:04:17 +00:00
|
|
|
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
|
2024-01-21 20:57:13 +00:00
|
|
|
ARG OLLAMA_CUSTOM_CPU_DEFS
|
|
|
|
ARG CGO_CFLAGS
|
2024-07-08 19:50:11 +00:00
|
|
|
ENV GOARCH amd64
|
2024-03-26 20:04:17 +00:00
|
|
|
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
|
2024-01-21 20:57:13 +00:00
|
|
|
|
2024-03-14 17:24:13 +00:00
|
|
|
FROM --platform=linux/amd64 cpu-builder-amd64 AS static-build-amd64
|
2024-08-09 14:21:40 +00:00
|
|
|
RUN --mount=type=cache,target=/root/.ccache \
|
|
|
|
OLLAMA_CPU_TARGET="static" bash gen_linux.sh
|
2024-01-21 20:57:13 +00:00
|
|
|
FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu-build-amd64
|
2024-08-09 14:21:40 +00:00
|
|
|
RUN --mount=type=cache,target=/root/.ccache \
|
|
|
|
OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu" bash gen_linux.sh
|
2024-01-21 20:57:13 +00:00
|
|
|
FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx-build-amd64
|
2024-08-09 14:21:40 +00:00
|
|
|
RUN --mount=type=cache,target=/root/.ccache \
|
|
|
|
OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu_avx" bash gen_linux.sh
|
2024-01-21 20:57:13 +00:00
|
|
|
FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx2-build-amd64
|
2024-08-09 14:21:40 +00:00
|
|
|
RUN --mount=type=cache,target=/root/.ccache \
|
|
|
|
OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu_avx2" bash gen_linux.sh
|
2024-01-21 19:37:11 +00:00
|
|
|
|
2024-07-02 17:23:05 +00:00
|
|
|
FROM --platform=linux/arm64 rockylinux:8 AS cpu-builder-arm64
|
2024-01-21 19:37:11 +00:00
|
|
|
ARG CMAKE_VERSION
|
|
|
|
ARG GOLANG_VERSION
|
|
|
|
COPY ./scripts/rh_linux_deps.sh /
|
|
|
|
RUN CMAKE_VERSION=${CMAKE_VERSION} GOLANG_VERSION=${GOLANG_VERSION} sh /rh_linux_deps.sh
|
2024-07-02 17:23:05 +00:00
|
|
|
ENV PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
|
2024-03-26 20:04:17 +00:00
|
|
|
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
|
2024-01-21 20:57:13 +00:00
|
|
|
ARG OLLAMA_CUSTOM_CPU_DEFS
|
|
|
|
ARG CGO_CFLAGS
|
2024-07-08 19:50:11 +00:00
|
|
|
ENV GOARCH arm64
|
2024-03-14 17:24:13 +00:00
|
|
|
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
|
|
|
|
|
|
|
|
FROM --platform=linux/arm64 cpu-builder-arm64 AS static-build-arm64
|
2024-08-09 14:21:40 +00:00
|
|
|
RUN --mount=type=cache,target=/root/.ccache \
|
|
|
|
OLLAMA_CPU_TARGET="static" bash gen_linux.sh
|
2024-03-14 17:24:13 +00:00
|
|
|
FROM --platform=linux/arm64 cpu-builder-arm64 AS cpu-build-arm64
|
2024-08-09 14:21:40 +00:00
|
|
|
RUN --mount=type=cache,target=/root/.ccache \
|
|
|
|
OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu" bash gen_linux.sh
|
2024-01-21 19:37:11 +00:00
|
|
|
|
2024-03-14 17:24:13 +00:00
|
|
|
|
2024-01-21 19:37:11 +00:00
|
|
|
# Intermediate stage used for ./scripts/build_linux.sh
|
|
|
|
FROM --platform=linux/amd64 cpu-build-amd64 AS build-amd64
|
|
|
|
ENV CGO_ENABLED 1
|
2024-03-26 20:04:17 +00:00
|
|
|
WORKDIR /go/src/github.com/ollama/ollama
|
2024-01-21 19:37:11 +00:00
|
|
|
COPY . .
|
2024-03-14 17:24:13 +00:00
|
|
|
COPY --from=static-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
|
|
|
|
COPY --from=cpu_avx-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
|
|
|
|
COPY --from=cpu_avx2-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
|
2024-06-14 03:46:14 +00:00
|
|
|
COPY --from=cuda-11-build-amd64 /go/src/github.com/ollama/ollama/dist/ dist/
|
|
|
|
COPY --from=cuda-11-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
|
|
|
|
COPY --from=cuda-12-build-amd64 /go/src/github.com/ollama/ollama/dist/ dist/
|
|
|
|
COPY --from=cuda-12-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
|
2024-07-08 19:50:11 +00:00
|
|
|
COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/dist/ dist/
|
2024-03-14 17:24:13 +00:00
|
|
|
COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
|
2024-01-21 20:57:13 +00:00
|
|
|
ARG GOFLAGS
|
|
|
|
ARG CGO_CFLAGS
|
2024-08-09 14:21:40 +00:00
|
|
|
RUN --mount=type=cache,target=/root/.ccache \
|
2024-08-14 23:32:57 +00:00
|
|
|
go build -trimpath -o dist/linux-amd64/bin/ollama .
|
2023-09-06 21:14:20 +00:00
|
|
|
|
2024-01-21 19:37:11 +00:00
|
|
|
# Intermediate stage used for ./scripts/build_linux.sh
|
|
|
|
FROM --platform=linux/arm64 cpu-build-arm64 AS build-arm64
|
|
|
|
ENV CGO_ENABLED 1
|
|
|
|
ARG GOLANG_VERSION
|
2024-03-26 20:04:17 +00:00
|
|
|
WORKDIR /go/src/github.com/ollama/ollama
|
2023-07-03 22:56:17 +00:00
|
|
|
COPY . .
|
2024-03-14 17:24:13 +00:00
|
|
|
COPY --from=static-build-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
|
2024-06-14 03:46:14 +00:00
|
|
|
COPY --from=cuda-11-build-server-arm64 /go/src/github.com/ollama/ollama/dist/ dist/
|
|
|
|
COPY --from=cuda-11-build-server-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
|
2024-07-12 18:35:41 +00:00
|
|
|
COPY --from=cuda-12-build-server-arm64 /go/src/github.com/ollama/ollama/dist/ dist/
|
|
|
|
COPY --from=cuda-12-build-server-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
|
2024-01-21 20:57:13 +00:00
|
|
|
ARG GOFLAGS
|
|
|
|
ARG CGO_CFLAGS
|
2024-08-09 14:21:40 +00:00
|
|
|
RUN --mount=type=cache,target=/root/.ccache \
|
2024-08-14 23:32:57 +00:00
|
|
|
go build -trimpath -o dist/linux-arm64/bin/ollama .
|
|
|
|
|
|
|
|
# Strip out ROCm dependencies to keep the primary image lean
|
|
|
|
FROM --platform=linux/amd64 ubuntu:22.04 as amd64-libs-without-rocm
|
|
|
|
COPY --from=build-amd64 /go/src/github.com/ollama/ollama/dist/linux-amd64/lib/ /scratch/
|
|
|
|
RUN cd /scratch/ollama/ && rm -rf rocblas libamd* libdrm* libroc* libhip* libhsa*
|
2023-07-03 22:56:17 +00:00
|
|
|
|
2024-01-21 19:37:11 +00:00
|
|
|
# Runtime stages
|
2024-01-26 00:46:01 +00:00
|
|
|
FROM --platform=linux/amd64 ubuntu:22.04 as runtime-amd64
|
2024-08-14 23:32:57 +00:00
|
|
|
COPY --from=amd64-libs-without-rocm /scratch/ /lib/
|
2024-01-26 00:46:01 +00:00
|
|
|
RUN apt-get update && apt-get install -y ca-certificates
|
2024-08-14 23:32:57 +00:00
|
|
|
COPY --from=build-amd64 /go/src/github.com/ollama/ollama/dist/linux-amd64/bin/ /bin/
|
|
|
|
|
2024-01-21 19:37:11 +00:00
|
|
|
FROM --platform=linux/arm64 ubuntu:22.04 as runtime-arm64
|
2024-08-14 23:32:57 +00:00
|
|
|
COPY --from=build-arm64 /go/src/github.com/ollama/ollama/dist/linux-arm64/lib/ /lib/
|
2023-09-22 18:57:31 +00:00
|
|
|
RUN apt-get update && apt-get install -y ca-certificates
|
2024-08-14 23:32:57 +00:00
|
|
|
COPY --from=build-arm64 /go/src/github.com/ollama/ollama/dist/linux-arm64/bin/ /bin/
|
2024-01-21 19:37:11 +00:00
|
|
|
|
2024-01-26 00:58:05 +00:00
|
|
|
# Radeon images are much larger so we keep it distinct from the CPU/CUDA image
|
2024-02-16 01:15:09 +00:00
|
|
|
FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete as runtime-rocm
|
2024-01-26 00:58:05 +00:00
|
|
|
RUN update-pciids
|
2024-08-14 23:32:57 +00:00
|
|
|
COPY --from=build-amd64 /go/src/github.com/ollama/ollama/dist/linux-amd64/bin/ /bin/
|
|
|
|
RUN ln -s /opt/rocm/lib /lib/ollama
|
2024-01-26 00:58:05 +00:00
|
|
|
EXPOSE 11434
|
|
|
|
ENV OLLAMA_HOST 0.0.0.0
|
|
|
|
|
|
|
|
ENTRYPOINT ["/bin/ollama"]
|
|
|
|
CMD ["serve"]
|
|
|
|
|
2024-01-21 19:37:11 +00:00
|
|
|
FROM runtime-$TARGETARCH
|
2023-09-30 19:32:06 +00:00
|
|
|
EXPOSE 11434
|
|
|
|
ENV OLLAMA_HOST 0.0.0.0
|
2024-01-21 19:37:11 +00:00
|
|
|
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
2024-01-26 00:58:05 +00:00
|
|
|
ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64
|
2023-12-01 05:16:56 +00:00
|
|
|
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
|
2024-02-29 16:43:08 +00:00
|
|
|
ENV NVIDIA_VISIBLE_DEVICES=all
|
2023-12-01 05:16:56 +00:00
|
|
|
|
2023-07-03 22:56:17 +00:00
|
|
|
ENTRYPOINT ["/bin/ollama"]
|
2023-07-06 20:34:14 +00:00
|
|
|
CMD ["serve"]
|