s390x.Dockerfile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ARG GCC_VERSION=15.2.0
  2. ARG UBUNTU_VERSION=24.04
  3. ### Build Llama.cpp stage
  4. FROM gcc:${GCC_VERSION} AS build
  5. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
  6. --mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
  7. apt update -y && \
  8. apt upgrade -y && \
  9. apt install -y --no-install-recommends \
  10. git cmake ccache ninja-build \
  11. # WARNING: Do not use libopenblas-openmp-dev. libopenblas-dev is faster.
  12. libopenblas-dev libcurl4-openssl-dev && \
  13. rm -rf /var/lib/apt/lists/*
  14. WORKDIR /app
  15. COPY . .
  16. RUN --mount=type=cache,target=/root/.ccache \
  17. --mount=type=cache,target=/app/build \
  18. cmake -S . -B build -G Ninja \
  19. -DCMAKE_BUILD_TYPE=Release \
  20. -DCMAKE_C_COMPILER_LAUNCHER=ccache \
  21. -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
  22. -DLLAMA_BUILD_TESTS=OFF \
  23. -DGGML_NATIVE=OFF \
  24. -DGGML_BACKEND_DL=ON \
  25. -DGGML_CPU_ALL_VARIANTS=ON \
  26. -DGGML_BLAS=ON \
  27. -DGGML_BLAS_VENDOR=OpenBLAS && \
  28. cmake --build build --config Release -j $(nproc) && \
  29. cmake --install build --prefix /opt/llama.cpp
  30. COPY *.py /opt/llama.cpp/bin
  31. COPY .devops/tools.sh /opt/llama.cpp/bin
  32. COPY gguf-py /opt/llama.cpp/gguf-py
  33. COPY requirements.txt /opt/llama.cpp/gguf-py
  34. COPY requirements /opt/llama.cpp/gguf-py/requirements
  35. ### Collect all llama.cpp binaries, libraries and distro libraries
  36. FROM scratch AS collector
  37. # Copy llama.cpp binaries and libraries
  38. COPY --from=build /opt/llama.cpp/bin /llama.cpp/bin
  39. COPY --from=build /opt/llama.cpp/lib /llama.cpp/lib
  40. COPY --from=build /opt/llama.cpp/gguf-py /llama.cpp/gguf-py
  41. ### Base image
  42. FROM ubuntu:${UBUNTU_VERSION} AS base
  43. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
  44. --mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
  45. apt update -y && \
  46. apt install -y --no-install-recommends \
  47. # WARNING: Do not use libopenblas-openmp-dev. libopenblas-dev is faster.
  48. # See: https://github.com/ggml-org/llama.cpp/pull/15915#issuecomment-3317166506
  49. curl libgomp1 libopenblas-dev && \
  50. apt autoremove -y && \
  51. apt clean -y && \
  52. rm -rf /tmp/* /var/tmp/* && \
  53. find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete && \
  54. find /var/cache -type f -delete
  55. # Copy llama.cpp libraries
  56. COPY --from=collector /llama.cpp/lib /usr/lib/s390x-linux-gnu
  57. ### Full
  58. FROM base AS full
  59. ENV PATH="/root/.cargo/bin:${PATH}"
  60. WORKDIR /app
  61. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
  62. --mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
  63. apt update -y && \
  64. apt install -y \
  65. git cmake libjpeg-dev \
  66. python3 python3-pip python3-dev && \
  67. apt autoremove -y && \
  68. apt clean -y && \
  69. rm -rf /tmp/* /var/tmp/* && \
  70. find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete && \
  71. find /var/cache -type f -delete
  72. RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
  73. COPY --from=collector /llama.cpp/bin /app
  74. COPY --from=collector /llama.cpp/gguf-py /app/gguf-py
  75. RUN pip install --no-cache-dir --break-system-packages \
  76. -r /app/gguf-py/requirements.txt
  77. ENTRYPOINT [ "/app/tools.sh" ]
  78. ### CLI Only
  79. FROM base AS light
  80. WORKDIR /llama.cpp/bin
  81. # Copy llama.cpp binaries and libraries
  82. COPY --from=collector /llama.cpp/bin/*.so /llama.cpp/bin
  83. COPY --from=collector /llama.cpp/bin/llama-cli /llama.cpp/bin/llama-completion /llama.cpp/bin
  84. ENTRYPOINT [ "/llama.cpp/bin/llama-cli" ]
  85. ### Server
  86. FROM base AS server
  87. ENV LLAMA_ARG_HOST=0.0.0.0
  88. WORKDIR /llama.cpp/bin
  89. # Copy llama.cpp binaries and libraries
  90. COPY --from=collector /llama.cpp/bin/*.so /llama.cpp/bin
  91. COPY --from=collector /llama.cpp/bin/llama-server /llama.cpp/bin
  92. EXPOSE 8080
  93. ENTRYPOINT [ "/llama.cpp/bin/llama-server" ]