Skip to content

Commit c28d618

Browse files
davanstrienclaude
andauthored
Document reusing image-baked libraries with hf jobs uv run (#2517)
* Document reusing image-baked libraries with `hf jobs uv run` Add a "Reusing image-baked libraries with uv run" section to the Popular Images page. By default `hf jobs uv run` resolves a script's dependencies from PyPI and does not use the libraries already in the image; for images that ship prebuilt, CUDA-matched builds (vLLM, PyTorch, FlashInfer) you usually want to reuse them via `--python` + `PYTHONPATH`. The section covers: - the two-flag recipe, with vLLM as the worked example - a cpu-basic probe to discover the interpreter / site-packages paths per image - the `RuntimeError: Could not find nvcc` symptom (FlashInfer JIT) as one example - that this applies only to `uv run`, not generic `hf jobs run`, plus the upstream uv issue (astral-sh/uv#7999) Also adds a short cross-link tip in the vLLM section. * Move image-baked libraries section to bottom, add top warning Address review: relocate the detailed "Reusing image-baked libraries with uv run" section to the end of the page, and add a warning callout near the top so the naive `hf jobs uv run` failure mode is flagged before the framework list. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Reframe around using a framework image; demote Python-package reuse GPU-tested the claims on HF Jobs (l4x1/a100, Qwen2.5-0.5B): - Reproduced `Could not find nvcc` ONLY on the default uv image (no CUDA toolkit). With --image vllm/vllm-openai it works, because the image provides nvcc + the CUDA system stack. - So the real fix is using the framework image, not the --python + PYTHONPATH recipe; "usually all you need" is just --image. - Reuse via PYTHONPATH does not skip the PyPI install (same ~3.5GB downloaded), so it's not a speed-up — demoted to an optional sub-section for ABI/CUDA-mismatch cases. Lead the section with the system-stack point and the nvcc repro; keep the probe (paths/uv vary per image, verified across vLLM, sglang, unsloth, trl, transformers, axolotl). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Apply suggestion from @davanstrien * Apply suggestion from @davanstrien --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ce1364d commit c28d618

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

docs/hub/jobs-popular-images.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Here is the list of ready-to-use Docker images from popular frameworks that you
44

55
These Docker images already have uv installed but if you want to use an image + uv for an image without uv installed you’ll need to make sure uv is installed first. This will work well in many cases but for LLM inference libraries which can have quite specific requirements, it can be useful to use a specific image that has the library installed.
66

7+
> [!TIP]
8+
> For GPU inference libraries, pass `--image` so the run gets a matching CUDA system stack
9+
> (toolkit, `nvcc`, libraries) — see [Using framework images for GPU
10+
> libraries](#using-framework-images-for-gpu-libraries) below.
11+
712
## vLLM
813

914
vLLM is a very well known and heavily used inference engine. It is known for its ability to scale inference for LLMs.
@@ -15,6 +20,11 @@ Use the `--image` argument to use this Docker image:
1520
>>> hf jobs uv run --image vllm/vllm-openai --flavor l4x4 generate-responses.py
1621
```
1722

23+
> [!TIP]
24+
> The `vllm/vllm-openai` image bundles the CUDA toolkit and prebuilt vLLM/FlashInfer kernels.
25+
> Using it is usually all you need; you can also reuse its prebuilt Python builds — see [Using
26+
> framework images for GPU libraries](#using-framework-images-for-gpu-libraries) below.
27+
1828
You can find more information on vLLM batch inference on Jobs in [Daniel Van Strien's blog post](https://danielvanstrien.xyz/posts/2025/hf-jobs/vllm-batch-inference.html).
1929

2030
## TRL
@@ -26,3 +36,67 @@ Use the `--image` argument to use this Docker image:
2636
```bash
2737
>>> hf jobs uv run --image huggingface/trl --flavor a100-large -s HF_TOKEN train.py
2838
```
39+
40+
## Using framework images for GPU libraries
41+
42+
GPU libraries like vLLM need more than their Python package — they need a matching system
43+
environment: the CUDA toolkit (including `nvcc`), system libraries like NCCL and cuDNN, and so
44+
on. If you omit `--image`, `hf jobs uv run` uses the default uv image
45+
(`ghcr.io/astral-sh/uv:python3.12-bookworm`), a bare Python base with no CUDA toolkit. Your
46+
dependencies still install from PyPI, but at runtime a library that needs the toolkit can fail —
47+
for example FlashInfer's sampler JIT-compiles a kernel and aborts with:
48+
49+
```text
50+
RuntimeError: Could not find nvcc and default cuda_home='/usr/local/cuda' doesn't exist
51+
```
52+
53+
Passing the framework image fixes this — it provides the CUDA toolkit, `nvcc`, and matched
54+
libraries — and this is usually all you need:
55+
56+
```bash
57+
hf jobs uv run --image vllm/vllm-openai --flavor l4x4 -s HF_TOKEN generate-responses.py
58+
```
59+
60+
UV still reinstalls your script dependencies from PyPI, but they now run against the
61+
image's system stack, so the framework works.
62+
63+
### Optionally: reuse the image's prebuilt Python builds
64+
65+
These images also ship prebuilt, CUDA-matched builds of the framework itself. To import those
66+
instead of UV's fresh PyPI install — handy if a PyPI build and the image's CUDA stack disagree
67+
(an ABI mismatch, or a kernel that won't build) — point UV at the image's interpreter and add
68+
its site-packages to the import path:
69+
70+
```bash
71+
hf jobs uv run \
72+
--image vllm/vllm-openai \
73+
--flavor l4x4 \
74+
--python /usr/bin/python3 \
75+
-e PYTHONPATH=/usr/local/lib/python3.12/dist-packages \
76+
-s HF_TOKEN \
77+
generate-responses.py
78+
```
79+
80+
- `--python` uses the **image's** interpreter, keeping ABI compatibility with its compiled extensions.
81+
- `-e PYTHONPATH=...` makes `import vllm` resolve to the image's prebuilt build for that run.
82+
83+
Paths differ per image, so probe them on `cpu-basic` rather than hardcoding:
84+
85+
```bash
86+
hf jobs run --flavor cpu-basic vllm/vllm-openai bash -c 'which python3; which uv; python3 -m pip show vllm | grep Location'
87+
```
88+
89+
```text
90+
/usr/bin/python3 # pass to --python
91+
/usr/local/bin/uv # uv is present, so `uv run` works
92+
Location: /usr/local/lib/python3.12/dist-packages # pass to PYTHONPATH
93+
```
94+
95+
Swap `vllm` for whichever library you're reusing. Layouts vary — `vllm/vllm-openai` and
96+
`lmsysorg/sglang` use the system `dist-packages` above, while `unsloth/unsloth` uses a
97+
virtualenv (`/opt/venv/...`).
98+
99+
> [!TIP]
100+
> This pins imports to the image's build; UV still installs your declared dependencies, so it
101+
> isn't a speed-up. A `uv run --system-site-packages` that would reuse the image's packages and
102+
> skip the reinstall is [requested upstream](https://github.com/astral-sh/uv/issues/7999).

0 commit comments

Comments
 (0)