VladKha commited on
Commit
b631052
·
verified ·
1 Parent(s): 6b8f3e3

public CUDA + llama.cpp inference base image

Browse files
Files changed (5) hide show
  1. Dockerfile +70 -0
  2. README.md +13 -5
  3. dataset_reviewer/__init__.py +4 -0
  4. pyproject.toml +47 -0
  5. run-job.sh +35 -0
Dockerfile ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # syntax=docker/dockerfile:1.6
2
+ # PUBLIC base image for GPU inference jobs (HF Jobs).
3
+ #
4
+ # Contains ONLY open-source, generic ML/runtime dependencies (CUDA, cu124 torch,
5
+ # the precompiled llama.cpp server, ...) — NO proprietary code, and no names that
6
+ # reveal which models/techniques the pipeline uses. The Job's bootstrap
7
+ # (/opt/run-job.sh) pulls the private wheel + demo modules + the remaining runtime
8
+ # dependencies at startup and runs run_job.py. Mirrors the old single-Space
9
+ # Dockerfile's proven CUDA/torch/llama sequence.
10
+
11
+ FROM ghcr.io/ggml-org/llama.cpp:server-cuda AS llama_bin
12
+
13
+ FROM nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04
14
+
15
+ ENV DEBIAN_FRONTEND=noninteractive \
16
+ PIP_NO_CACHE_DIR=0 \
17
+ PYTHONUNBUFFERED=1 \
18
+ HF_HUB_ENABLE_HF_TRANSFER=1 \
19
+ LD_LIBRARY_PATH=/opt/llama.cpp/build/bin:/usr/local/cuda/lib64 \
20
+ PATH=/usr/local/cuda/bin:$PATH \
21
+ PIP_BREAK_SYSTEM_PACKAGES=1
22
+
23
+ # libgomp1 is required by the per-microarch libggml-cpu-*.so variants from the
24
+ # upstream server-cuda image (without it llama-server finds no CPU backend).
25
+ RUN apt-get update && apt-get install -y --no-install-recommends \
26
+ python3.12 python3.12-dev python3.12-venv python3-pip \
27
+ git curl ca-certificates \
28
+ libgomp1 \
29
+ && rm -rf /var/lib/apt/lists/*
30
+
31
+ # Precompiled CUDA llama-server (binary + shared libs) from the upstream image.
32
+ RUN mkdir -p /opt/llama.cpp/build/bin
33
+ COPY --from=llama_bin /app/ /opt/llama.cpp/build/bin/
34
+ RUN chmod +x /opt/llama.cpp/build/bin/llama-server
35
+
36
+ WORKDIR /app
37
+
38
+ # CUDA torch first, so the dependency install picks it up instead of the CPU wheel.
39
+ RUN --mount=type=cache,target=/root/.cache/pip \
40
+ pip install --index-url https://download.pytorch.org/whl/cu124 torch
41
+
42
+ # Install the generic DEPENDENCIES only. A stub package (empty
43
+ # dataset_reviewer/__init__.py) lets `pip install .` resolve the deps listed in the
44
+ # generated slim pyproject WITHOUT shipping any proprietary source into this public
45
+ # image. At runtime the Job replaces the stub with the real wheel and installs the
46
+ # remaining (technique-revealing) deps (see run-job.sh).
47
+ COPY pyproject.toml /app/pyproject.toml
48
+ COPY dataset_reviewer /app/dataset_reviewer
49
+ RUN --mount=type=cache,target=/root/.cache/pip pip install /app
50
+
51
+ # Explicit pins for the bootstrap + demo modules. huggingface_hub/python-dotenv are
52
+ # already transitive; telethon is the Telegram client (MTProto) the Job uses to
53
+ # resolve a submitter's @username and DM them — not a dataset_reviewer dep.
54
+ RUN --mount=type=cache,target=/root/.cache/pip \
55
+ pip install "huggingface_hub[hf_transfer]" python-dotenv "telethon==1.43.2"
56
+
57
+ COPY run-job.sh /opt/run-job.sh
58
+ RUN chmod +x /opt/run-job.sh
59
+
60
+ ENV LLAMA_CPP_DIR=/opt/llama.cpp \
61
+ LLAMA_SERVER_BIN=/opt/llama.cpp/build/bin/llama-server \
62
+ GGUF_DIR=/models \
63
+ LLM_PORT=8080 \
64
+ LLM_CTX=32768 \
65
+ LLM_PARALLEL=4
66
+
67
+ # Default command keeps the Space itself idle+RUNNING (so the image publishes
68
+ # cleanly); HF Jobs override this with `bash /opt/run-job.sh`.
69
+ EXPOSE 7860
70
+ CMD ["python3", "-m", "http.server", "7860"]
README.md CHANGED
@@ -1,10 +1,18 @@
1
  ---
2
- title: Cuda Llm Inference Base
3
- emoji: 📈
4
- colorFrom: blue
5
- colorTo: blue
6
  sdk: docker
 
7
  pinned: false
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
1
  ---
2
+ title: CUDA LLM Inference Base
3
+ emoji: 🧱
4
+ colorFrom: gray
5
+ colorTo: indigo
6
  sdk: docker
7
+ app_port: 7860
8
  pinned: false
9
+ short_description: CUDA + llama.cpp inference base image.
10
  ---
11
 
12
+ Public base image: CUDA + cu124 torch + a precompiled llama.cpp server + generic
13
+ ML/runtime dependencies, for running GPU inference jobs on HF Jobs. It contains
14
+ **no proprietary code**; application code and any remaining dependencies are
15
+ installed at runtime from a private repo.
16
+
17
+ This Space exists only to build + publish the image; it serves a trivial idle
18
+ endpoint.
dataset_reviewer/__init__.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ """Stub package — present only so `pip install .` resolves dataset-reviewer's
2
+ dependencies into this public base image WITHOUT shipping any proprietary source.
3
+ The real dataset_reviewer wheel is force-reinstalled over this stub at Job runtime
4
+ (see /opt/run-job.sh)."""
pyproject.toml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "dataset-reviewer"
3
+ version = "0.1.0"
4
+ requires-python = ">=3.12"
5
+ dependencies = [
6
+ "datasets>=4.5.0",
7
+ "datatrove[io]>=0.9.0",
8
+ "duckdb>=1.4.4",
9
+ "ddgs",
10
+ "httpx",
11
+ "jinja2>=3.1.6",
12
+ "lancedb>=0.29.2",
13
+ "langchain>=1.2",
14
+ "langchain-community",
15
+ "langchain-huggingface",
16
+ "langchain-mcp-adapters",
17
+ "langchain-openai",
18
+ "langchain-tavily",
19
+ "openai>=1.0",
20
+ "markdownify",
21
+ "pyarrow>=23.0.1",
22
+ "pydantic>=2.12.5",
23
+ "markdown-it-py>=4.0.0",
24
+ "playwright>=1.58.0",
25
+ "rich>=14.3.3",
26
+ "langgraph",
27
+ "loguru",
28
+ "python-dotenv",
29
+ "huggingface-hub",
30
+ "pandas",
31
+ "requests",
32
+ "markupsafe",
33
+ "fsspec",
34
+ "transformers>=4.40",
35
+ "torch>=2.11.0",
36
+ "tiktoken>=0.12.0",
37
+ "tenacity>=9.1.4",
38
+ "pillow>=12.2.0",
39
+ "nh3>=0.2",
40
+ ]
41
+
42
+ [build-system]
43
+ requires = ["setuptools>=61"]
44
+ build-backend = "setuptools.build_meta"
45
+
46
+ [tool.setuptools.packages.find]
47
+ include = ["dataset_reviewer*"]
run-job.sh ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # HF Job bootstrap: pull the private dataset_reviewer wheel + demo modules +
3
+ # runtime requirements from JOB_CODE_REPO (authenticated by HF_TOKEN), install the
4
+ # wheel over the baked stub, install the technique-revealing deps kept out of the
5
+ # public image, then run the headless pipeline. Each phase is timed so its cost is
6
+ # visible in the Job log. Keeps proprietary code + model/technique names OUT of the
7
+ # public base image.
8
+ set -euo pipefail
9
+
10
+ : "${JOB_CODE_REPO:?JOB_CODE_REPO is required}"
11
+
12
+ t=$SECONDS
13
+ echo "[bootstrap] downloading job code from ${JOB_CODE_REPO}"
14
+ python3 - <<'PY'
15
+ import os
16
+ from huggingface_hub import snapshot_download
17
+ snapshot_download(repo_id=os.environ["JOB_CODE_REPO"], repo_type="model", local_dir="/code")
18
+ PY
19
+ echo "[bootstrap] job code downloaded in $((SECONDS - t))s"
20
+
21
+ t=$SECONDS
22
+ echo "[bootstrap] installing dataset_reviewer wheel over the baked stub"
23
+ pip install --no-deps --force-reinstall --no-index /code/wheels/*.whl
24
+ echo "[bootstrap] wheel installed in $((SECONDS - t))s"
25
+
26
+ if [ -f /code/requirements-runtime.txt ]; then
27
+ t=$SECONDS
28
+ echo "[bootstrap] installing runtime ML dependencies"
29
+ pip install -r /code/requirements-runtime.txt
30
+ echo "[bootstrap] runtime deps installed in $((SECONDS - t))s"
31
+ fi
32
+
33
+ echo "[bootstrap] launching run_job.py"
34
+ cd /code
35
+ exec python3 -u run_job.py