2024-03-07 07:39:49 -08:00
|
|
|
ARG GOLANG_VERSION=1.22.1
|
2024-01-21 11:37:11 -08:00
|
|
|
ARG CMAKE_VERSION=3.22.1
|
2024-03-21 05:21:34 -04:00
|
|
|
# this CUDA_VERSION corresponds with the one specified in docs/gpu.md
|
2024-01-21 11:37:11 -08:00
|
|
|
ARG CUDA_VERSION=11.3.1
|
2024-03-27 14:15:47 -07:00
|
|
|
ARG ROCM_VERSION=6.0.2
|
2023-09-22 11:57:31 -07:00
|
|
|
|
2024-01-21 11:37:11 -08: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 13:41:49 -07:00
|
|
|
|
2024-01-21 11:37:11 -08:00
|
|
|
FROM --platform=linux/amd64 nvidia/cuda:$CUDA_VERSION-devel-centos7 AS cuda-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
|
2024-03-26 13:04:17 -07:00
|
|
|
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
|
|
|
|
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
|
2024-01-21 12:57:13 -08:00
|
|
|
ARG CGO_CFLAGS
|
2024-01-21 11:37:11 -08:00
|
|
|
RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
|
|
|
|
|
2024-03-25 19:01:11 -07:00
|
|
|
FROM --platform=linux/arm64 nvidia/cuda:$CUDA_VERSION-devel-rockylinux8 AS cuda-build-arm64
|
2024-01-21 11:37:11 -08:00
|
|
|
ARG CMAKE_VERSION
|
|
|
|
COPY ./scripts/rh_linux_deps.sh /
|
|
|
|
RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
|
2024-03-25 19:01:11 -07:00
|
|
|
ENV PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
|
2024-03-26 13:04:17 -07:00
|
|
|
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
|
|
|
|
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
|
2024-01-21 12:57:13 -08:00
|
|
|
ARG CGO_CFLAGS
|
2024-01-21 11:37:11 -08:00
|
|
|
RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
|
|
|
|
|
2024-02-15 17:15:09 -08:00
|
|
|
FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete AS rocm-build-amd64
|
2024-01-21 11:37:11 -08: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 13:04:17 -07:00
|
|
|
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
|
|
|
|
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
|
2024-01-21 12:57:13 -08:00
|
|
|
ARG CGO_CFLAGS
|
|
|
|
ARG AMDGPU_TARGETS
|
2024-01-21 11:37:11 -08:00
|
|
|
RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
|
2024-02-15 17:15:09 -08:00
|
|
|
RUN mkdir /tmp/scratch && \
|
2024-03-26 13:04:17 -07:00
|
|
|
for dep in $(cat /go/src/github.com/ollama/ollama/llm/llama.cpp/build/linux/x86_64/rocm*/lib/deps.txt) ; do \
|
2024-02-15 17:15:09 -08:00
|
|
|
cp ${dep} /tmp/scratch/ || exit 1 ; \
|
|
|
|
done && \
|
|
|
|
(cd /opt/rocm/lib && tar cf - rocblas/library) | (cd /tmp/scratch/ && tar xf - ) && \
|
2024-03-26 13:04:17 -07:00
|
|
|
mkdir -p /go/src/github.com/ollama/ollama/dist/deps/ && \
|
|
|
|
(cd /tmp/scratch/ && tar czvf /go/src/github.com/ollama/ollama/dist/deps/ollama-linux-amd64-rocm.tgz . )
|
2024-01-21 11:37:11 -08:00
|
|
|
|
|
|
|
|
2024-01-21 12:57:13 -08:00
|
|
|
FROM --platform=linux/amd64 centos:7 AS cpu-builder-amd64
|
2024-01-21 11:37:11 -08: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 13:04:17 -07:00
|
|
|
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
|
2024-01-21 12:57:13 -08:00
|
|
|
ARG OLLAMA_CUSTOM_CPU_DEFS
|
|
|
|
ARG CGO_CFLAGS
|
2024-03-26 13:04:17 -07:00
|
|
|
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
|
2024-01-21 12:57:13 -08:00
|
|
|
|
2024-03-14 10:24:13 -07:00
|
|
|
FROM --platform=linux/amd64 cpu-builder-amd64 AS static-build-amd64
|
|
|
|
RUN OLLAMA_CPU_TARGET="static" sh gen_linux.sh
|
2024-01-21 12:57:13 -08:00
|
|
|
FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu-build-amd64
|
|
|
|
RUN OLLAMA_CPU_TARGET="cpu" sh gen_linux.sh
|
|
|
|
FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx-build-amd64
|
|
|
|
RUN OLLAMA_CPU_TARGET="cpu_avx" sh gen_linux.sh
|
|
|
|
FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx2-build-amd64
|
|
|
|
RUN OLLAMA_CPU_TARGET="cpu_avx2" sh gen_linux.sh
|
2024-01-21 11:37:11 -08:00
|
|
|
|
2024-03-14 10:24:13 -07:00
|
|
|
FROM --platform=linux/arm64 centos:7 AS cpu-builder-arm64
|
2024-01-21 11:37:11 -08: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 13:04:17 -07:00
|
|
|
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
|
2024-01-21 12:57:13 -08:00
|
|
|
ARG OLLAMA_CUSTOM_CPU_DEFS
|
|
|
|
ARG CGO_CFLAGS
|
2024-03-14 10:24:13 -07:00
|
|
|
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
|
|
|
|
|
|
|
|
FROM --platform=linux/arm64 cpu-builder-arm64 AS static-build-arm64
|
|
|
|
RUN OLLAMA_CPU_TARGET="static" sh gen_linux.sh
|
|
|
|
FROM --platform=linux/arm64 cpu-builder-arm64 AS cpu-build-arm64
|
2024-01-21 12:57:13 -08:00
|
|
|
RUN OLLAMA_CPU_TARGET="cpu" sh gen_linux.sh
|
2024-01-21 11:37:11 -08:00
|
|
|
|
2024-03-14 10:24:13 -07:00
|
|
|
|
2024-01-21 11:37:11 -08: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 13:04:17 -07:00
|
|
|
WORKDIR /go/src/github.com/ollama/ollama
|
2024-01-21 11:37:11 -08:00
|
|
|
COPY . .
|
2024-03-14 10:24:13 -07: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/
|
|
|
|
COPY --from=cuda-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
|
|
|
|
COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
|
2024-03-26 13:04:17 -07:00
|
|
|
COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/dist/deps/ ./dist/deps/
|
2024-01-21 12:57:13 -08:00
|
|
|
ARG GOFLAGS
|
|
|
|
ARG CGO_CFLAGS
|
2024-03-11 15:58:46 -07:00
|
|
|
RUN go build -trimpath .
|
2023-09-06 14:14:20 -07:00
|
|
|
|
2024-01-21 11:37:11 -08: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 13:04:17 -07:00
|
|
|
WORKDIR /go/src/github.com/ollama/ollama
|
2023-07-03 18:56:17 -04:00
|
|
|
COPY . .
|
2024-03-14 10:24:13 -07:00
|
|
|
COPY --from=static-build-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
|
|
|
|
COPY --from=cuda-build-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
|
2024-01-21 12:57:13 -08:00
|
|
|
ARG GOFLAGS
|
|
|
|
ARG CGO_CFLAGS
|
2024-03-11 15:58:46 -07:00
|
|
|
RUN go build -trimpath .
|
2023-07-03 18:56:17 -04:00
|
|
|
|
2024-01-21 11:37:11 -08:00
|
|
|
# Runtime stages
|
2024-01-25 16:46:01 -08:00
|
|
|
FROM --platform=linux/amd64 ubuntu:22.04 as runtime-amd64
|
|
|
|
RUN apt-get update && apt-get install -y ca-certificates
|
2024-03-26 13:04:17 -07:00
|
|
|
COPY --from=build-amd64 /go/src/github.com/ollama/ollama/ollama /bin/ollama
|
2024-01-21 11:37:11 -08:00
|
|
|
FROM --platform=linux/arm64 ubuntu:22.04 as runtime-arm64
|
2023-09-22 11:57:31 -07:00
|
|
|
RUN apt-get update && apt-get install -y ca-certificates
|
2024-03-26 13:04:17 -07:00
|
|
|
COPY --from=build-arm64 /go/src/github.com/ollama/ollama/ollama /bin/ollama
|
2024-01-21 11:37:11 -08:00
|
|
|
|
2024-01-25 16:58:05 -08:00
|
|
|
# Radeon images are much larger so we keep it distinct from the CPU/CUDA image
|
2024-02-15 17:15:09 -08:00
|
|
|
FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete as runtime-rocm
|
2024-01-25 16:58:05 -08:00
|
|
|
RUN update-pciids
|
2024-03-26 13:04:17 -07:00
|
|
|
COPY --from=build-amd64 /go/src/github.com/ollama/ollama/ollama /bin/ollama
|
2024-01-25 16:58:05 -08:00
|
|
|
EXPOSE 11434
|
|
|
|
ENV OLLAMA_HOST 0.0.0.0
|
|
|
|
|
|
|
|
ENTRYPOINT ["/bin/ollama"]
|
|
|
|
CMD ["serve"]
|
|
|
|
|
2024-01-21 11:37:11 -08:00
|
|
|
FROM runtime-$TARGETARCH
|
2023-09-30 12:32:06 -07:00
|
|
|
EXPOSE 11434
|
|
|
|
ENV OLLAMA_HOST 0.0.0.0
|
2024-01-21 11:37:11 -08:00
|
|
|
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
2024-01-25 16:58:05 -08:00
|
|
|
ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64
|
2023-11-30 21:16:56 -08:00
|
|
|
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
|
2024-02-29 08:43:08 -08:00
|
|
|
ENV NVIDIA_VISIBLE_DEVICES=all
|
2023-11-30 21:16:56 -08:00
|
|
|
|
2023-07-03 18:56:17 -04:00
|
|
|
ENTRYPOINT ["/bin/ollama"]
|
2023-07-06 16:34:14 -04:00
|
|
|
CMD ["serve"]
|