cuda.Dockerfile 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 --upgrade pip setuptools wheel \
  48. && pip install -r requirements.txt \
  49. && apt autoremove -y \
  50. && apt clean -y \
  51. && rm -rf /tmp/* /var/tmp/* \
  52. && find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete \
  53. && find /var/cache -type f -delete
  54. ENTRYPOINT ["/app/tools.sh"]
  55. ### Light, CLI only
  56. FROM base AS light
  57. COPY --from=build /app/full/llama-cli /app
  58. WORKDIR /app
  59. ENTRYPOINT [ "/app/llama-cli" ]
  60. ### Server, Server only
  61. FROM base AS server
  62. ENV LLAMA_ARG_HOST=0.0.0.0
  63. COPY --from=build /app/full/llama-server /app
  64. WORKDIR /app
  65. HEALTHCHECK CMD [ "curl", "-f", "http://localhost:8080/health" ]
  66. ENTRYPOINT [ "/app/llama-server" ]