Dockerfile 5.63 KB
Newer Older
1
ARG GOLANG_VERSION=1.22.1
2
ARG CMAKE_VERSION=3.22.1
3
# this CUDA_VERSION corresponds with the one specified in docs/gpu.md
4
ARG CUDA_VERSION=11.3.1
Daniel Hiltgen's avatar
Daniel Hiltgen committed
5
ARG ROCM_VERSION=6.0
Michael Yang's avatar
Michael Yang committed
6

7
8
9
10
11
# 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
Michael Yang's avatar
Michael Yang committed
12

13
14
15
16
17
18
19
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
COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/
WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate
20
ARG CGO_CFLAGS
21
22
RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh

23
FROM --platform=linux/arm64 nvidia/cuda:$CUDA_VERSION-devel-centos7 AS cuda-build-arm64
24
25
26
ARG CMAKE_VERSION
COPY ./scripts/rh_linux_deps.sh /
RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
27
ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
28
29
COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/
WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate
30
ARG CGO_CFLAGS
31
32
RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh

Daniel Hiltgen's avatar
Daniel Hiltgen committed
33
FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete AS rocm-build-amd64
34
35
36
37
38
39
40
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
COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/
WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate
41
42
ARG CGO_CFLAGS
ARG AMDGPU_TARGETS
43
RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
Daniel Hiltgen's avatar
Daniel Hiltgen committed
44
45
46
47
48
49
RUN mkdir /tmp/scratch && \
    for dep in $(cat /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/x86_64/rocm*/lib/deps.txt) ; do \
        cp ${dep} /tmp/scratch/ || exit 1 ; \
    done && \
    (cd /opt/rocm/lib && tar cf - rocblas/library) | (cd /tmp/scratch/ && tar xf - ) && \
    mkdir -p /go/src/github.com/jmorganca/ollama/dist/deps/ && \
50
    (cd /tmp/scratch/ && tar czvf /go/src/github.com/jmorganca/ollama/dist/deps/ollama-linux-amd64-rocm.tgz . )
51
52


53
FROM --platform=linux/amd64 centos:7 AS cpu-builder-amd64
54
55
56
57
58
59
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
COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/
60
61
ARG OLLAMA_CUSTOM_CPU_DEFS
ARG CGO_CFLAGS
62
WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate
63
64
65
66
67
68
69

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
70
71
72
73
74
75
76
77
78

FROM --platform=linux/arm64 centos:7 AS cpu-build-arm64
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
COPY --from=llm-code / /go/src/github.com/jmorganca/ollama/
WORKDIR /go/src/github.com/jmorganca/ollama/llm/generate
79
80
81
82
# Note, we only build the "base" CPU variant on arm since avx/avx2 are x86 features
ARG OLLAMA_CUSTOM_CPU_DEFS
ARG CGO_CFLAGS
RUN OLLAMA_CPU_TARGET="cpu" sh gen_linux.sh
83
84
85
86

# Intermediate stage used for ./scripts/build_linux.sh
FROM --platform=linux/amd64 cpu-build-amd64 AS build-amd64
ENV CGO_ENABLED 1
Jeffrey Morgan's avatar
Jeffrey Morgan committed
87
WORKDIR /go/src/github.com/jmorganca/ollama
88
COPY . .
89
90
COPY --from=cpu_avx-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
COPY --from=cpu_avx2-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
91
COPY --from=cuda-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
Daniel Hiltgen's avatar
Daniel Hiltgen committed
92
93
COPY --from=rocm-build-amd64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
COPY --from=rocm-build-amd64 /go/src/github.com/jmorganca/ollama/dist/deps/ ./dist/deps/
94
95
ARG GOFLAGS
ARG CGO_CFLAGS
96
RUN go build -trimpath .
Michael Yang's avatar
Michael Yang committed
97

98
99
100
101
102
# 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
WORKDIR /go/src/github.com/jmorganca/ollama
Jeffrey Morgan's avatar
Jeffrey Morgan committed
103
COPY . .
104
COPY --from=cuda-build-arm64 /go/src/github.com/jmorganca/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
105
RUN mkdir -p /go/src/github.com/jmorganca/ollama/dist/deps/
106
107
ARG GOFLAGS
ARG CGO_CFLAGS
108
RUN go build -trimpath .
Jeffrey Morgan's avatar
Jeffrey Morgan committed
109

110
# Runtime stages
Daniel Hiltgen's avatar
Daniel Hiltgen committed
111
112
FROM --platform=linux/amd64 ubuntu:22.04 as runtime-amd64
RUN apt-get update && apt-get install -y ca-certificates
113
114
COPY --from=build-amd64 /go/src/github.com/jmorganca/ollama/ollama /bin/ollama
FROM --platform=linux/arm64 ubuntu:22.04 as runtime-arm64
Michael Yang's avatar
Michael Yang committed
115
RUN apt-get update && apt-get install -y ca-certificates
116
117
COPY --from=build-arm64 /go/src/github.com/jmorganca/ollama/ollama /bin/ollama

118
# Radeon images are much larger so we keep it distinct from the CPU/CUDA image
Daniel Hiltgen's avatar
Daniel Hiltgen committed
119
FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete as runtime-rocm
120
121
122
123
124
125
126
127
RUN update-pciids
COPY --from=build-amd64 /go/src/github.com/jmorganca/ollama/ollama /bin/ollama
EXPOSE 11434
ENV OLLAMA_HOST 0.0.0.0

ENTRYPOINT ["/bin/ollama"]
CMD ["serve"]

128
FROM runtime-$TARGETARCH
129
130
EXPOSE 11434
ENV OLLAMA_HOST 0.0.0.0
131
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
132
ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64
133
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
134
ENV NVIDIA_VISIBLE_DEVICES=all
135

Jeffrey Morgan's avatar
Jeffrey Morgan committed
136
ENTRYPOINT ["/bin/ollama"]
Jeffrey Morgan's avatar
Jeffrey Morgan committed
137
CMD ["serve"]