Skip to content

Commit 1b94070

Browse files
davanstrienclaude
andauthored
docs: local folder mounts — hf jobs uv run -v ./dir:/mnt (hub >= 1.22) (#91)
Document the new sync-to-job local volume mounts across the skill and recipe docs: buckets.md gets a 'Mount a local folder' section (jobs-artifacts bucket, incremental re-sync, copy-not-live, :rw + pull-back), SKILL.md and the contributor rules get the input/output split, and the README, ocr, iiif-tiles, transcription, gliner, and vlm-object-detection docs each show the local-mount path next to the existing bucket-first instructions. Verified end-to-end on cpu-basic Jobs: initial sync, incremental re-sync (2 uploads / 2 skips), :rw write-back + hf buckets sync pull-back, and tile_iiif.py --source-dir reading straight from a mounted local folder (no script change needed). Claude-Session: https://claude.ai/code/session_01SMtzN4P4ussA5EmSfZBWmW Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent d9e6188 commit 1b94070

11 files changed

Lines changed: 67 additions & 5 deletions

File tree

‎AGENTS.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ workflow's optional `repo_id` / `repo_type` inputs.)
7878
plus **`hf-jobs` when `JOB_ID` is set** — these are the adoption meters
7979
(`list_datasets(tags="uv-script")` / `tags="hf-jobs"` count stamped public outputs).
8080
- GPU scripts check `torch.cuda.is_available()` and exit with a clear message. Write outputs to the Hub
81-
(`push_to_hub`) or a bucket (`-v hf://…`), never local paths (Jobs disk is ephemeral). Name by task, not tool.
81+
(`push_to_hub`) or a bucket (`-v hf://…`), never bare local paths (Jobs disk is ephemeral; local *input*
82+
dirs can be mounted with `-v ./dir:/mnt`, which syncs them to a bucket). Name by task, not tool.
8283

8384
## The mirror — how it works
8485

‎CONTRIBUTING.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ if __name__ == "__main__":
5151

5252
- **Self-contained:** declare all deps inline; no `requirements.txt`, no shared importable modules.
5353
- **Hub-native I/O:** read inputs from and write outputs to the Hub (`push_to_hub`) or a bucket (`-v hf://…`).
54-
Job disk is ephemeral — never rely on local output paths.
54+
Job disk is ephemeral — never rely on local output paths. (Users can mount a local *input* folder with
55+
`-v ./dir:/mnt`, which syncs it to a bucket — scripts just see a mounted directory.)
5556
- **GPU scripts:** check `torch.cuda.is_available()` and exit with a clear message if a GPU is required.
5657
- **Fast downloads:** prefer `huggingface-hub[hf_transfer]`.
5758
- **Naming:** name by task, not tool (`classify-dataset.py`, not `bert-classify.py`).

‎README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ hf jobs uv run --flavor l4x1 --secrets HF_TOKEN \
2929

3030
No `pip install`, no local setup. `--secrets HF_TOKEN` forwards your token so the job can write the output dataset back to the Hub. (Jobs needs the `hf` CLI — `uv tool install huggingface_hub` — and a Hugging Face account with [pay-as-you-go credit](https://huggingface.co/pricing) — no subscription needed; it's billed by the second, and a small CPU job costs ~$0.01/hr. Run `hf jobs hardware` for current flavors and prices.)
3131

32+
**Got local files instead of a Hub dataset?** Mount a folder straight into the job with `-v` — the CLI syncs it to a private bucket automatically, and re-runs only sync what changed (no "upload to a repo first" step; `huggingface_hub` ≥ 1.22):
33+
34+
```bash
35+
hf jobs uv run --flavor l4x1 --secrets HF_TOKEN \
36+
-v ./my-scans:/input -v ./ocr-output:/output:rw \
37+
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr-bucket.py \
38+
/input /output
39+
```
40+
41+
Mounts are read-only unless you add `:rw`; for a read-write mount the CLI prints the `hf buckets sync` command that pulls the job's output back down when it's done.
42+
3243
**Prefer your own machine?** A recipe is just a UV script, so on a box with the hardware it needs — most recipes here want a CUDA GPU — you can run it (or inspect it with `--help`) directly, no Jobs required:
3344

3445
```bash

‎gliner/extract-entities.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def parse_args():
6868
help=(
6969
"Input. Either a HF dataset ID (e.g. 'org/dataset') or a local path "
7070
"to parquet/jsonl file(s) — useful when running in HF Jobs with a mounted "
71-
"bucket: '-v hf://buckets/<ns>/<bucket>:/input' then pass '/input/cards.parquet'."
71+
"bucket ('-v hf://buckets/<ns>/<bucket>:/input') or a local folder synced "
72+
"automatically ('-v ./data:/input', hub >= 1.22), then pass '/input/cards.parquet'."
7273
),
7374
)
7475
p.add_argument(

‎iiif-tiles/README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ hf jobs uv run tile_iiif.py \
6565
--collection-name "Historic Manuscripts"
6666
```
6767

68+
Scans still on your machine? Mount the folder straight into the job — the CLI syncs it to a private bucket automatically (re-runs only sync changed files; `huggingface_hub` ≥ 1.22), so there's no separate upload step:
69+
70+
```bash
71+
hf jobs uv run -v ./my-scans:/input tile_iiif.py \
72+
--source-dir /input \
73+
--output-bucket myorg/iiif-tiles \
74+
--collection-name "Historic Manuscripts"
75+
```
76+
6877
## View the results
6978

7079
Once tiles are in a bucket, open the manifest in any IIIF viewer:

‎ocr/AGENTS.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ A couple of scripts have `-bucket.py` variants (currently `falcon-ocr-bucket.py`
7777
`ls` the repo to check whether a `-bucket.py` variant exists for the model you want
7878
before assuming it's available.
7979

80+
The `-v` source can also be a **local directory** (`huggingface_hub` ≥ 1.22) — the CLI
81+
syncs it to a private bucket and mounts it, so local images/PDFs need no upload step:
82+
83+
hf jobs uv run --flavor l4x1 -s HF_TOKEN \
84+
-v ./pages:/input \
85+
-v hf://buckets/<user>/<output>:/output \
86+
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/<script>-bucket.py \
87+
/input /output
88+
89+
Re-runs only sync new/changed files. Local mounts are read-only by default; a local
90+
*output* dir works too with `:rw` — pull results back with the `hf buckets sync`
91+
command the CLI prints at launch.
92+
8093
## Common flags across dataset-mode scripts
8194

8295
Most scripts support: `--max-samples`, `--shuffle`, `--seed`, `--split`, `--image-column`,

‎ocr/CLAUDE.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ planned **self-review skill** (see [Deferred](#deferred--tracked)) just enforces
2626
dep (e.g. bucket I/O → `bucketbag`, [#67](https://github.com/davanstrien/uv-scripts-for-ai/issues/67)),
2727
never a local import. Recipes = inline; internal tooling may share freely.
2828
- **GPU + output.** Check `torch.cuda.is_available()` and exit clearly if absent. Write to the Hub
29-
(`push_to_hub`) or a bucket (`-v hf://…`), never local paths (Jobs disk is ephemeral).
29+
(`push_to_hub`) or a bucket (`-v hf://…`), never bare local paths (Jobs disk is ephemeral; local *input*
30+
dirs mount via `-v ./dir:/mnt`, synced to a bucket automatically).
3031
- **vLLM image + fail-fast preflight.** If the model's arch isn't in a stable vLLM wheel, **omit
3132
`vllm`/`torch` from deps** and run on the pinned `vllm/vllm-openai` image via
3233
`--image … --python … -e PYTHONPATH=…`; add a preflight that `sys.exit(1)`s naming the exact flags

‎skills/uv-recipes/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ To spend review effort well (active learning), order the queue by informativenes
7272

7373
## Rules that keep jobs working
7474

75-
- Jobs disk is ephemeral — write to the Hub, never local paths. The default pattern is **a dataset in, a dataset out** (`push_to_hub`). For data you rewrite often (mutable, incremental writes, checkpoints, one file per item), use a [storage bucket](https://huggingface.co/docs/hub/storage-buckets) instead — mount one with `-v hf://buckets/<user>/<bucket>:/mnt`, or read/write `hf://buckets/…` paths via fsspec. See [buckets.md](buckets.md).
75+
- Jobs disk is ephemeral — write outputs to the Hub, never local paths. The default pattern is **a dataset in, a dataset out** (`push_to_hub`). **Local input files** don't need an upload step: `-v ./scans:/input` syncs the folder to a private bucket and mounts it in the Job (re-runs only sync changed files; `huggingface_hub` ≥ 1.22). For data you rewrite often (mutable, incremental writes, checkpoints, one file per item), use a [storage bucket](https://huggingface.co/docs/hub/storage-buckets) — mount one with `-v hf://buckets/<user>/<bucket>:/mnt`, or read/write `hf://buckets/…` paths via fsspec. See [buckets.md](buckets.md).
7676
- GPU recipes check `torch.cuda.is_available()` and exit clearly if missing — match `--flavor` to the recipe.
7777
- Test on `--max-samples 10` first.
7878

‎skills/uv-recipes/buckets.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ hf jobs uv run --flavor l4x1 --secrets HF_TOKEN \
2323

2424
The `ocr` family already ships bucket-aware recipes — **`glm-ocr-bucket.py`** and **`falcon-ocr-bucket.py`** read images/PDFs from a mounted bucket and write one `.md` per page. Read the recipe's `--help` for exact arguments.
2525

26+
## Mount a local folder (no upload step)
27+
28+
The `-v` source can also be a **local directory** (requires `huggingface_hub` ≥ 1.22). The CLI syncs it to a bucket and mounts it in the Job — no "upload to a repo first" step:
29+
30+
```bash
31+
hf jobs uv run --flavor l4x1 --secrets HF_TOKEN \
32+
-v ./scans:/input \
33+
-v hf://buckets/<user>/<bucket>:/output \
34+
https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr-bucket.py \
35+
/input /output
36+
```
37+
38+
How it behaves:
39+
40+
- Files sync to a **private** `<namespace>/jobs-artifacts` bucket (auto-created), into a subfolder derived from the directory path — **re-running only syncs new or changed files**.
41+
- It's a **copy, not a live mount**: local edits after launch aren't visible to the Job; re-run the command to re-sync.
42+
- **Read-only by default.** Append `:rw` (e.g. `-v ./out:/output:rw`) to let the Job write back; pull results down afterwards with the `hf buckets sync` command the CLI prints at launch.
43+
- Python API equivalent: `sync_job_volume("./scans", "/input")` returns a `Volume` to pass in `run_uv_job(..., volumes=[...])`.
44+
45+
Prefer a **named bucket** (previous section) when the data is large or has thousands of files — bulk reads over the FUSE mount are slow, so at that scale copy from the mount to the Job's local disk first, or use a bucket you populate once — or when several machines/jobs share it.
46+
2647
## Write to a bucket from Python (fsspec)
2748

2849
A recipe that writes incrementally can use `hf://buckets/…` paths directly:

‎transcription/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ hf jobs uv run --flavor l4x1 -s HF_TOKEN \
4242

4343
No download/upload step. Buckets are mounted directly as volumes via [hf-mount](https://github.com/huggingface/hf-mount).
4444

45+
Audio already on your machine? Mount the folder directly — `-v ./audio:/input` syncs it to a private bucket and mounts it in the job (re-runs only sync changed files; `huggingface_hub` ≥ 1.22), so you can skip the `download-ia`/bucket step.
46+
4547
> **Local dev**: if you've cloned this repo, swap the URL for the local filename (e.g. `cohere-transcribe.py /input /output ...`).
4648
4749
## Scripts

0 commit comments

Comments
 (0)