Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
Combine the 2 Dockerfiles and add ROCm
Daniel Hiltgenda72235ebf55
diff --git a/Dockerfile b/Dockerfileindex c50665b6b..8e8b6d2af 100644--- a/Dockerfile+++ b/Dockerfile@@ -1,28 +1,114 @@-FROM nvidia/cuda:11.8.0-devel-ubuntu22.04+ARG GOLANG_VERSION=1.21.3+ARG CMAKE_VERSION=3.22.1+ARG CUDA_VERSION=11.3.1-ARG TARGETARCH-ARG GOFLAGS="'-ldflags=-w -s'"+# 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+FROM --platform=linux/amd64 nvidia/cuda:$CUDA_VERSION-devel-centos7 AS cuda-build-amd64+ARG CMAKE_VERSION+ARG CGO_CFLAGS+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/jmorganca/ollama/+WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate+RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh++FROM --platform=linux/arm64 nvidia/cuda:$CUDA_VERSION-devel-rockylinux8 AS cuda-build-arm64+ARG CMAKE_VERSION+ARG CGO_CFLAGS+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/jmorganca/ollama/+WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate+RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh++FROM --platform=linux/amd64 rocm/dev-centos-7:5.7.1-complete AS rocm-5-build-amd64+ARG CMAKE_VERSION+ARG CGO_CFLAGS+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+COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/+WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate+RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh++FROM --platform=linux/amd64 rocm/dev-centos-7:6.0-complete AS rocm-6-build-amd64+ARG CMAKE_VERSION+ARG CGO_CFLAGS+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+COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/+WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate+RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh++FROM --platform=linux/amd64 centos:7 AS cpu-build-amd64+ARG CMAKE_VERSION+ARG GOLANG_VERSION+ARG OLLAMA_CUSTOM_CPU_DEFS+ARG CGO_CFLAGS+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+COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/+WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate+RUN sh gen_linux.sh++FROM --platform=linux/arm64 centos:7 AS cpu-build-arm64+ARG CMAKE_VERSION+ARG GOLANG_VERSION+ARG OLLAMA_CUSTOM_CPU_DEFS+ARG CGO_CFLAGS+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+COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/+WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate+RUN sh gen_linux.sh++# Intermediate stage used for ./scripts/build_linux.sh+FROM --platform=linux/amd64 cpu-build-amd64 AS build-amd64+ENV CGO_ENABLED 1+ARG GOFLAGS+ARG CGO_CFLAGSWORKDIR /go/src/github.com/jmorganca/ollama-RUN apt-get update && apt-get install -y git build-essential cmake-ADD https://dl.google.com/go/go1.21.3.linux-$TARGETARCH.tar.gz /tmp/go1.21.3.tar.gz-RUN mkdir -p /usr/local && tar xz -C /usr/local </tmp/go1.21.3.tar.gz+COPY . .+COPY --from=cuda-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/+COPY --from=rocm-5-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/+COPY --from=rocm-6-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/+RUN go build .+# 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+ARG GOFLAGS+ARG CGO_CFLAGS+WORKDIR /go/src/github.com/jmorganca/ollamaCOPY . .-ENV GOARCH=$TARGETARCH-ENV GOFLAGS=$GOFLAGS-RUN /usr/local/go/bin/go generate ./... \- && /usr/local/go/bin/go build .+COPY --from=cuda-build-arm64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/+RUN go build .-FROM ubuntu:22.04+# Runtime stages+FROM --platform=linux/amd64 rocm/dev-centos-7:6.0-complete as runtime-amd64+COPY --from=build-amd64 /go/src/github.com/jmorganca/ollama/ollama /bin/ollama+FROM --platform=linux/arm64 ubuntu:22.04 as runtime-arm64RUN apt-get update && apt-get install -y ca-certificates-COPY --from=0 /go/src/github.com/jmorganca/ollama/ollama /bin/ollama+COPY --from=build-arm64 /go/src/github.com/jmorganca/ollama/ollama /bin/ollama++FROM runtime-$TARGETARCHEXPOSE 11434ENV OLLAMA_HOST 0.0.0.0--# set some environment variable for better NVIDIA compatibility-ENV PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/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 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:/opt/rocm/lib:ENV NVIDIA_DRIVER_CAPABILITIES=compute,utilityENTRYPOINT ["/bin/ollama"]diff --git a/Dockerfile.build b/Dockerfile.builddeleted file mode 100644index 6b52322b8..000000000--- a/Dockerfile.build+++ /dev/null@@ -1,99 +0,0 @@-ARG GOLANG_VERSION=1.21.3-ARG CMAKE_VERSION=3.22.1-ARG CUDA_VERSION=11.3.1--# 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--FROM --platform=linux/amd64 nvidia/cuda:$CUDA_VERSION-devel-centos7 AS cuda-build-amd64-ARG CMAKE_VERSION-ARG CGO_CFLAGS-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/jmorganca/ollama/-WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate-RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh--FROM --platform=linux/arm64 nvidia/cuda:$CUDA_VERSION-devel-rockylinux8 AS cuda-build-arm64-ARG CMAKE_VERSION-ARG CGO_CFLAGS-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/jmorganca/ollama/-WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate-RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh--FROM --platform=linux/amd64 rocm/dev-centos-7:5.7.1-complete AS rocm-5-build-amd64-ARG CMAKE_VERSION-ARG CGO_CFLAGS-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-COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/-WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate-RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh--FROM --platform=linux/amd64 rocm/dev-centos-7:6.0-complete AS rocm-6-build-amd64-ARG CMAKE_VERSION-ARG CGO_CFLAGS-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-COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/-WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate-RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh--FROM --platform=linux/amd64 centos:7 AS cpu-build-amd64-ARG CMAKE_VERSION-ARG GOLANG_VERSION-ARG OLLAMA_CUSTOM_CPU_DEFS-ARG CGO_CFLAGS-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-COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/-WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate-RUN sh gen_linux.sh--FROM --platform=linux/arm64 centos:7 AS cpu-build-arm64-ARG CMAKE_VERSION-ARG GOLANG_VERSION-ARG OLLAMA_CUSTOM_CPU_DEFS-ARG CGO_CFLAGS-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-COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/-WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate-RUN sh gen_linux.sh---FROM --platform=linux/amd64 cpu-build-amd64 AS build-amd64-ENV CGO_ENABLED 1-ARG GOFLAGS-ARG CGO_CFLAGS-WORKDIR /go/src/github.com/jmorganca/ollama-COPY . .-COPY --from=cuda-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/-COPY --from=rocm-5-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/-COPY --from=rocm-6-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/-RUN go build .--FROM --platform=linux/arm64 cpu-build-arm64 AS build-arm64-ENV CGO_ENABLED 1-ARG GOLANG_VERSION-ARG GOFLAGS-ARG CGO_CFLAGS-WORKDIR /go/src/github.com/jmorganca/ollama-COPY . .-COPY --from=cuda-build-arm64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/-RUN go build .--FROM build-$TARGETARCHdiff --git a/scripts/build_linux.sh b/scripts/build_linux.shindex 582899f7c..6a2492391 100755--- a/scripts/build_linux.sh+++ b/scripts/build_linux.sh@@ -9,7 +9,15 @@ BUILD_ARCH=${BUILD_ARCH:-"amd64 arm64"}mkdir -p distfor TARGETARCH in ${BUILD_ARCH}; do- docker build --platform=linux/$TARGETARCH --build-arg=GOFLAGS --build-arg=CGO_CFLAGS --build-arg=OLLAMA_CUSTOM_CPU_DEFS -f Dockerfile.build -t builder:$TARGETARCH .+ docker build \+ --platform=linux/$TARGETARCH \+ --build-arg=GOFLAGS \+ --build-arg=CGO_CFLAGS \+ --build-arg=OLLAMA_CUSTOM_CPU_DEFS \+ --target build-$TARGETARCH \+ -f Dockerfile \+ -t builder:$TARGETARCH \+ .docker create --platform linux/$TARGETARCH --name builder-$TARGETARCH builder:$TARGETARCHdocker cp builder-$TARGETARCH:/go/src/github.com/jmorganca/ollama/ollama ./dist/ollama-linux-$TARGETARCHdocker rm builder-$TARGETARCH