Dockerfile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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
  5. ARG ROCM_VERSION=6.0
  6. # Copy the minimal context we need to run the generate scripts
  7. FROM scratch AS llm-code
  8. COPY .git .git
  9. COPY .gitmodules .gitmodules
  10. COPY llm llm
  11. FROM --platform=linux/amd64 nvidia/cuda:$CUDA_VERSION-devel-centos7 AS cuda-build-amd64
  12. ARG CMAKE_VERSION
  13. COPY ./scripts/rh_linux_deps.sh /
  14. RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
  15. ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
  16. COPY --from=llm-code / /go/src/github.com/ollama/ollama/
  17. WORKDIR /go/src/github.com/ollama/ollama/llm/generate
  18. ARG CGO_CFLAGS
  19. RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
  20. FROM --platform=linux/arm64 nvidia/cuda:$CUDA_VERSION-devel-rockylinux8 AS cuda-build-arm64
  21. ARG CMAKE_VERSION
  22. COPY ./scripts/rh_linux_deps.sh /
  23. RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
  24. ENV PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
  25. COPY --from=llm-code / /go/src/github.com/ollama/ollama/
  26. WORKDIR /go/src/github.com/ollama/ollama/llm/generate
  27. ARG CGO_CFLAGS
  28. RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
  29. FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete AS rocm-build-amd64
  30. ARG CMAKE_VERSION
  31. COPY ./scripts/rh_linux_deps.sh /
  32. RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
  33. ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
  34. ENV LIBRARY_PATH /opt/amdgpu/lib64
  35. COPY --from=llm-code / /go/src/github.com/ollama/ollama/
  36. WORKDIR /go/src/github.com/ollama/ollama/llm/generate
  37. ARG CGO_CFLAGS
  38. ARG AMDGPU_TARGETS
  39. RUN OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
  40. RUN mkdir /tmp/scratch && \
  41. for dep in $(cat /go/src/github.com/ollama/ollama/llm/llama.cpp/build/linux/x86_64/rocm*/lib/deps.txt) ; do \
  42. cp ${dep} /tmp/scratch/ || exit 1 ; \
  43. done && \
  44. (cd /opt/rocm/lib && tar cf - rocblas/library) | (cd /tmp/scratch/ && tar xf - ) && \
  45. mkdir -p /go/src/github.com/ollama/ollama/dist/deps/ && \
  46. (cd /tmp/scratch/ && tar czvf /go/src/github.com/ollama/ollama/dist/deps/ollama-linux-amd64-rocm.tgz . )
  47. FROM --platform=linux/amd64 centos:7 AS cpu-builder-amd64
  48. ARG CMAKE_VERSION
  49. ARG GOLANG_VERSION
  50. COPY ./scripts/rh_linux_deps.sh /
  51. RUN CMAKE_VERSION=${CMAKE_VERSION} GOLANG_VERSION=${GOLANG_VERSION} sh /rh_linux_deps.sh
  52. ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
  53. COPY --from=llm-code / /go/src/github.com/ollama/ollama/
  54. ARG OLLAMA_CUSTOM_CPU_DEFS
  55. ARG CGO_CFLAGS
  56. WORKDIR /go/src/github.com/ollama/ollama/llm/generate
  57. FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu-build-amd64
  58. RUN OLLAMA_CPU_TARGET="cpu" sh gen_linux.sh
  59. FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx-build-amd64
  60. RUN OLLAMA_CPU_TARGET="cpu_avx" sh gen_linux.sh
  61. FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx2-build-amd64
  62. RUN OLLAMA_CPU_TARGET="cpu_avx2" sh gen_linux.sh
  63. FROM --platform=linux/arm64 centos:7 AS cpu-build-arm64
  64. ARG CMAKE_VERSION
  65. ARG GOLANG_VERSION
  66. COPY ./scripts/rh_linux_deps.sh /
  67. RUN CMAKE_VERSION=${CMAKE_VERSION} GOLANG_VERSION=${GOLANG_VERSION} sh /rh_linux_deps.sh
  68. ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
  69. COPY --from=llm-code / /go/src/github.com/ollama/ollama/
  70. WORKDIR /go/src/github.com/ollama/ollama/llm/generate
  71. # Note, we only build the "base" CPU variant on arm since avx/avx2 are x86 features
  72. ARG OLLAMA_CUSTOM_CPU_DEFS
  73. ARG CGO_CFLAGS
  74. RUN OLLAMA_CPU_TARGET="cpu" sh gen_linux.sh
  75. # Intermediate stage used for ./scripts/build_linux.sh
  76. FROM --platform=linux/amd64 cpu-build-amd64 AS build-amd64
  77. ENV CGO_ENABLED 1
  78. WORKDIR /go/src/github.com/ollama/ollama
  79. COPY . .
  80. COPY --from=cpu_avx-build-amd64 /go/src/github.com/ollama/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
  81. COPY --from=cpu_avx2-build-amd64 /go/src/github.com/ollama/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
  82. COPY --from=cuda-build-amd64 /go/src/github.com/ollama/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
  83. COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
  84. COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/dist/deps/ ./dist/deps/
  85. ARG GOFLAGS
  86. ARG CGO_CFLAGS
  87. RUN go build -trimpath .
  88. # Intermediate stage used for ./scripts/build_linux.sh
  89. FROM --platform=linux/arm64 cpu-build-arm64 AS build-arm64
  90. ENV CGO_ENABLED 1
  91. ARG GOLANG_VERSION
  92. WORKDIR /go/src/github.com/ollama/ollama
  93. COPY . .
  94. COPY --from=cuda-build-arm64 /go/src/github.com/ollama/ollama/llm/llama.cpp/build/linux/ llm/llama.cpp/build/linux/
  95. RUN mkdir -p /go/src/github.com/ollama/ollama/dist/deps/
  96. ARG GOFLAGS
  97. ARG CGO_CFLAGS
  98. RUN go build -trimpath .
  99. # Runtime stages
  100. FROM --platform=linux/amd64 ubuntu:22.04 as runtime-amd64
  101. RUN apt-get update && apt-get install -y ca-certificates
  102. COPY --from=build-amd64 /go/src/github.com/ollama/ollama/ollama /bin/ollama
  103. FROM --platform=linux/arm64 ubuntu:22.04 as runtime-arm64
  104. RUN apt-get update && apt-get install -y ca-certificates
  105. COPY --from=build-arm64 /go/src/github.com/ollama/ollama/ollama /bin/ollama
  106. # Radeon images are much larger so we keep it distinct from the CPU/CUDA image
  107. FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete as runtime-rocm
  108. RUN update-pciids
  109. COPY --from=build-amd64 /go/src/github.com/ollama/ollama/ollama /bin/ollama
  110. EXPOSE 11434
  111. ENV OLLAMA_HOST 0.0.0.0
  112. ENTRYPOINT ["/bin/ollama"]
  113. CMD ["serve"]
  114. FROM runtime-$TARGETARCH
  115. EXPOSE 11434
  116. ENV OLLAMA_HOST 0.0.0.0
  117. ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  118. ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64
  119. ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
  120. ENV NVIDIA_VISIBLE_DEVICES=all
  121. ENTRYPOINT ["/bin/ollama"]
  122. CMD ["serve"]