Spaces:
Running
Running
build: use prebuilt llama.cpp CPU binary (b9895) instead of source compile — fixes mtmd OOM hang, ~20x faster build
Browse files- Dockerfile +29 -20
Dockerfile
CHANGED
|
@@ -1,30 +1,20 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
RUN apt-get update && apt-get install -y \
|
| 5 |
-
git \
|
| 6 |
-
cmake \
|
| 7 |
-
build-essential \
|
| 8 |
curl \
|
| 9 |
-
|
| 10 |
libgomp1 \
|
|
|
|
| 11 |
python3 \
|
| 12 |
python3-pip \
|
| 13 |
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
|
| 15 |
-
# Install HuggingFace CLI
|
| 16 |
-
RUN pip install --no-cache-dir --break-system-packages huggingface_hub
|
| 17 |
-
|
| 18 |
-
# Build llama.cpp (CPU, native SIMD auto-detected: AVX2/AVX512, OpenMP threading)
|
| 19 |
-
RUN git clone --depth 1 https://github.com/ggerganov/llama.cpp.git /llama.cpp \
|
| 20 |
-
&& cmake -S /llama.cpp -B /llama.cpp/build \
|
| 21 |
-
-DCMAKE_BUILD_TYPE=Release \
|
| 22 |
-
-DGGML_NATIVE=ON \
|
| 23 |
-
-DGGML_OPENMP=ON \
|
| 24 |
-
-DLLAMA_CURL=ON \
|
| 25 |
-
-DLLAMA_BUILD_SERVER=ON \
|
| 26 |
-
&& cmake --build /llama.cpp/build --config Release -j "$(nproc)" --target llama-server
|
| 27 |
-
|
| 28 |
# Python runtime deps (thin FastAPI proxy)
|
| 29 |
RUN pip install --no-cache-dir --break-system-packages \
|
| 30 |
fastapi \
|
|
@@ -32,6 +22,24 @@ RUN pip install --no-cache-dir --break-system-packages \
|
|
| 32 |
httpx \
|
| 33 |
huggingface_hub
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
WORKDIR /app
|
| 36 |
|
| 37 |
# Models directory (model is pulled at container startup by app.py, not baked
|
|
@@ -43,7 +51,8 @@ COPY . .
|
|
| 43 |
# Single instance: main proxy (7860) + one llama.cpp server (8081)
|
| 44 |
EXPOSE 7860 8081
|
| 45 |
|
| 46 |
-
|
|
|
|
| 47 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 48 |
|
| 49 |
CMD ["python3", "app.py"]
|
|
|
|
| 1 |
+
# Ubuntu 24.04 base to match the glibc of the official llama.cpp release binary.
|
| 2 |
+
FROM ubuntu:24.04
|
| 3 |
|
| 4 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 5 |
+
|
| 6 |
+
# Runtime deps only (no compiler/cmake — we use the prebuilt binary).
|
| 7 |
+
# libgomp1 : OpenMP threading used by ggml-cpu
|
| 8 |
+
# libcurl4 : llama-server is built with curl support
|
| 9 |
RUN apt-get update && apt-get install -y \
|
|
|
|
|
|
|
|
|
|
| 10 |
curl \
|
| 11 |
+
ca-certificates \
|
| 12 |
libgomp1 \
|
| 13 |
+
libcurl4 \
|
| 14 |
python3 \
|
| 15 |
python3-pip \
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# Python runtime deps (thin FastAPI proxy)
|
| 19 |
RUN pip install --no-cache-dir --break-system-packages \
|
| 20 |
fastapi \
|
|
|
|
| 22 |
httpx \
|
| 23 |
huggingface_hub
|
| 24 |
|
| 25 |
+
# ---------------------------------------------------------------------------
|
| 26 |
+
# Prebuilt llama.cpp CPU server — NO source compile (avoids the multimodal/mtmd
|
| 27 |
+
# OOM that hangs a from-source build on a 2-vCPU builder). The ubuntu-x64 build
|
| 28 |
+
# ships per-microarch CPU variants (haswell/skylakex/icelake/...) and selects the
|
| 29 |
+
# best one at RUNTIME, so it is portable and safe on cpu-basic.
|
| 30 |
+
# ---------------------------------------------------------------------------
|
| 31 |
+
ARG LLAMA_TAG=b9895
|
| 32 |
+
RUN mkdir -p /llama.cpp/build/bin \
|
| 33 |
+
&& curl -fsSL -o /tmp/llama.tar.gz \
|
| 34 |
+
"https://github.com/ggml-org/llama.cpp/releases/download/${LLAMA_TAG}/llama-${LLAMA_TAG}-bin-ubuntu-x64.tar.gz" \
|
| 35 |
+
&& tar -xzf /tmp/llama.tar.gz -C /llama.cpp/build/bin --strip-components=1 \
|
| 36 |
+
&& rm /tmp/llama.tar.gz \
|
| 37 |
+
&& chmod +x /llama.cpp/build/bin/llama-server \
|
| 38 |
+
&& /llama.cpp/build/bin/llama-server --version 2>&1 | head -5
|
| 39 |
+
|
| 40 |
+
# llama-server finds its sibling .so files here.
|
| 41 |
+
ENV LD_LIBRARY_PATH=/llama.cpp/build/bin
|
| 42 |
+
|
| 43 |
WORKDIR /app
|
| 44 |
|
| 45 |
# Models directory (model is pulled at container startup by app.py, not baked
|
|
|
|
| 51 |
# Single instance: main proxy (7860) + one llama.cpp server (8081)
|
| 52 |
EXPOSE 7860 8081
|
| 53 |
|
| 54 |
+
# Longer start-period: the model (~5.5GB) is pulled on first container start.
|
| 55 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=420s --retries=3 \
|
| 56 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 57 |
|
| 58 |
CMD ["python3", "app.py"]
|