cuda.Dockerfile 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ARG UBUNTU_VERSION=22.04
  2. # This needs to generally match the container host's environment.
  3. ARG CUDA_VERSION=12.4.0
  4. # Target the CUDA build image
  5. ARG BASE_CUDA_DEV_CONTAINER=nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION}
  6. ARG BASE_CUDA_RUN_CONTAINER=nvidia/cuda:${CUDA_VERSION}-runtime-ubuntu${UBUNTU_VERSION}
  7. FROM ${BASE_CUDA_DEV_CONTAINER} AS build
  8. # CUDA architecture to build for (defaults to all supported archs)
  9. ARG CUDA_DOCKER_ARCH=default
  10. RUN apt-get update && \
  11. apt-get install -y build-essential cmake python3 python3-pip git libcurl4-openssl-dev libgomp1
  12. WORKDIR /app
  13. COPY . .
  14. RUN if [ "${CUDA_DOCKER_ARCH}" != "default" ]; then \
  15. export CMAKE_ARGS="-DCMAKE_CUDA_ARCHITECTURES=${CUDA_DOCKER_ARCH}"; \
  16. fi && \
  17. cmake -B build -DGGML_NATIVE=OFF -DGGML_CUDA=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON -DLLAMA_BUILD_TESTS=OFF ${CMAKE_ARGS} -DCMAKE_EXE_LINKER_FLAGS=-Wl,--allow-shlib-undefined . && \
  18. cmake --build build --config Release -j$(nproc)
  19. RUN mkdir -p /app/lib && \
  20. find build -name "*.so" -exec cp {} /app/lib \;
  21. RUN mkdir -p /app/full \
  22. && cp build/bin/* /app/full \
  23. && cp *.py /app/full \
  24. && cp -r gguf-py /app/full \
  25. && cp -r requirements /app/full \
  26. && cp requirements.txt /app/full \
  27. && cp .devops/tools.sh /app/full/tools.sh
  28. ## Base image
  29. FROM ${BASE_CUDA_RUN_CONTAINER} AS base
  30. RUN apt-get update \
  31. && apt-get install -y libgomp1 curl\
  32. && apt autoremove -y \
  33. && apt clean -y \
  34. && rm -rf /tmp/* /var/tmp/* \
  35. && find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete \
  36. && find /var/cache -type f -delete
  37. COPY --from=build /app/lib/ /app
  38. ### Full
  39. FROM base AS full
  40. COPY --from=build /app/full /app
  41. WORKDIR /app
  42. RUN apt-get update \
  43. && apt-get install -y \
  44. git \
  45. python3 \
  46. python3-pip \
  47. && pip install --break-system-packages -r requirements.txt \
  48. && apt autoremove -y \
  49. && apt clean -y \
  50. && rm -rf /tmp/* /var/tmp/* \
  51. && find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete \
  52. && find /var/cache -type f -delete
  53. ENTRYPOINT ["/app/tools.sh"]
  54. ### Light, CLI only
  55. FROM base AS light
  56. COPY --from=build /app/full/llama-cli /app
  57. WORKDIR /app
  58. ENTRYPOINT [ "/app/llama-cli" ]
  59. ### Server, Server only
  60. FROM base AS server
  61. ENV LLAMA_ARG_HOST=0.0.0.0
  62. COPY --from=build /app/full/llama-server /app
  63. WORKDIR /app
  64. HEALTHCHECK CMD [ "curl", "-f", "http://localhost:8080/health" ]
  65. ENTRYPOINT [ "/app/llama-server" ]