davanstrien HF Staff commited on
Commit
8cba5fe
·
verified ·
1 Parent(s): 403d2c6

Sync from GitHub via hub-sync

Browse files
Files changed (5) hide show
  1. .gitignore +0 -6
  2. CLAUDE.md +5 -1
  3. classify-dataset.py +6 -12
  4. generate-responses.py +2 -5
  5. vlm-classify.py +9 -7
.gitignore DELETED
@@ -1,6 +0,0 @@
1
- .DS_Store
2
- __pycache__/
3
- *.pyc
4
- .ruff_cache/
5
- .venv/
6
- *.log
 
 
 
 
 
 
 
CLAUDE.md CHANGED
@@ -14,7 +14,11 @@ if not torch.cuda.is_available():
14
  ```
15
 
16
  ### 2. vLLM Docker Image
17
- Always use `vllm/vllm-openai:latest` for HF Jobs - it has all dependencies pre-installed.
 
 
 
 
18
 
19
  ### 3. Dependencies
20
  Include custom PyPI indexes for vLLM and FlashInfer:
 
14
  ```
15
 
16
  ### 2. vLLM Docker Image
17
+ Run on the pinned **`vllm/vllm-openai:0.22.1`** image for HF Jobs (ships vLLM + the CUDA toolkit, so FlashInfer works) with `--python /usr/bin/python3 -e PYTHONPATH=/usr/local/lib/python3.12/dist-packages`. **Pin the tag (test-then-pin), not `:latest`.** Tested 2026-06-05 on `l4x1` (vLLM 0.22.1).
18
+
19
+ The custom nightly / FlashInfer `[[tool.uv.index]]` blocks (§3) are **no longer needed** — the image provides vLLM; keep a `vllm>=0.11.0` floor in the PEP 723 header for the local path.
20
+
21
+ **APIs (verified):** structured outputs use `StructuredOutputsParams` (`structured_outputs=`, ≥0.11.0 — `GuidedDecodingParams`/`guided_decoding=` removed in 0.12.0); classification auto-detects the pooling runner from the model architecture (the old `LLM(..., task="classify")` arg was removed → use `LLM(model)`).
22
 
23
  ### 3. Dependencies
24
  Include custom PyPI indexes for vLLM and FlashInfer:
classify-dataset.py CHANGED
@@ -2,21 +2,14 @@
2
  # requires-python = ">=3.10"
3
  # dependencies = [
4
  # "datasets",
5
- # "flashinfer-python",
6
  # "httpx",
7
- # "huggingface-hub[hf_transfer]",
8
  # "setuptools",
9
  # "toolz",
10
  # "torch",
11
  # "transformers",
12
- # "vllm",
13
  # ]
14
- #
15
- # [[tool.uv.index]]
16
- # url = "https://flashinfer.ai/whl/cu126/torch2.6"
17
- #
18
- # [[tool.uv.index]]
19
- # url = "https://wheels.vllm.ai/nightly"
20
  # ///
21
  """
22
  Batch text classification using vLLM for efficient GPU inference.
@@ -155,9 +148,10 @@ def main(
155
  )
156
  sys.exit(1)
157
 
158
- # Initialize vLLM with classification task
 
159
  logger.info(f"Loading model: {hub_model_id}")
160
- llm = LLM(model=hub_model_id, task="classify")
161
 
162
  # Get label mapping if available
163
  id2label = get_model_id2label(hub_model_id)
@@ -277,7 +271,7 @@ This script requires arguments. For usage information:
277
  Example HF Jobs command:
278
  hfjobs run \\
279
  --flavor l4x1 \\
280
- --secret HF_TOKEN=\$(python -c "from huggingface_hub import HfFolder; print(HfFolder.get_token())") \\
281
  vllm/vllm-openai:latest \\
282
  /bin/bash -c '
283
  uv run https://huggingface.co/datasets/uv-scripts/vllm/resolve/main/classify-dataset.py \\
 
2
  # requires-python = ">=3.10"
3
  # dependencies = [
4
  # "datasets",
 
5
  # "httpx",
6
+ # "huggingface-hub",
7
  # "setuptools",
8
  # "toolz",
9
  # "torch",
10
  # "transformers",
11
+ # "vllm>=0.11.0",
12
  # ]
 
 
 
 
 
 
13
  # ///
14
  """
15
  Batch text classification using vLLM for efficient GPU inference.
 
148
  )
149
  sys.exit(1)
150
 
151
+ # vLLM auto-detects the sequence-classification runner from the model
152
+ # architecture (*ForSequenceClassification); the task= arg was removed in 0.12.0.
153
  logger.info(f"Loading model: {hub_model_id}")
154
+ llm = LLM(model=hub_model_id)
155
 
156
  # Get label mapping if available
157
  id2label = get_model_id2label(hub_model_id)
 
271
  Example HF Jobs command:
272
  hfjobs run \\
273
  --flavor l4x1 \\
274
+ --secret HF_TOKEN=$(python -c "from huggingface_hub import HfFolder; print(HfFolder.get_token())") \\
275
  vllm/vllm-openai:latest \\
276
  /bin/bash -c '
277
  uv run https://huggingface.co/datasets/uv-scripts/vllm/resolve/main/classify-dataset.py \\
generate-responses.py CHANGED
@@ -3,11 +3,11 @@
3
  # dependencies = [
4
  # "datasets",
5
  # "flashinfer-python",
6
- # "huggingface-hub[hf_transfer]",
7
  # "hf-xet>= 1.1.7",
8
  # "torch",
9
  # "transformers",
10
- # "vllm>=0.8.5",
11
  # ]
12
  #
13
  # ///
@@ -52,9 +52,6 @@ from tqdm.auto import tqdm
52
  from transformers import AutoTokenizer
53
  from vllm import LLM, SamplingParams
54
 
55
- # Enable HF Transfer for faster downloads
56
- os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
57
-
58
  logging.basicConfig(
59
  level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
60
  )
 
3
  # dependencies = [
4
  # "datasets",
5
  # "flashinfer-python",
6
+ # "huggingface-hub",
7
  # "hf-xet>= 1.1.7",
8
  # "torch",
9
  # "transformers",
10
+ # "vllm>=0.11.0",
11
  # ]
12
  #
13
  # ///
 
52
  from transformers import AutoTokenizer
53
  from vllm import LLM, SamplingParams
54
 
 
 
 
55
  logging.basicConfig(
56
  level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
57
  )
vlm-classify.py CHANGED
@@ -2,13 +2,13 @@
2
  # requires-python = ">=3.11"
3
  # dependencies = [
4
  # "datasets",
5
- # "huggingface-hub[hf_transfer]",
6
  # "pillow",
7
  # "toolz",
8
  # "torch",
9
  # "tqdm",
10
  # "transformers",
11
- # "vllm>=0.6.5",
12
  # ]
13
  # ///
14
 
@@ -52,12 +52,12 @@ from typing import List, Optional, Union, Dict, Any
52
 
53
  import torch
54
  from PIL import Image
55
- from datasets import load_dataset, Dataset
56
  from huggingface_hub import login
57
  from toolz import partition_all
58
  from tqdm.auto import tqdm
59
  from vllm import LLM, SamplingParams
60
- from vllm.sampling_params import GuidedDecodingParams
61
 
62
  logging.basicConfig(level=logging.INFO)
63
  logger = logging.getLogger(__name__)
@@ -194,12 +194,14 @@ def main(
194
 
195
  llm = LLM(**llm_kwargs)
196
 
197
- # Create guided decoding params for classification
198
- guided_decoding_params = GuidedDecodingParams(choice=class_list)
 
 
199
  sampling_params = SamplingParams(
200
  temperature=0.1, # Low temperature for consistent classification
201
  max_tokens=50, # Classifications are short
202
- guided_decoding=guided_decoding_params,
203
  )
204
 
205
  # Process images in batches to avoid memory issues
 
2
  # requires-python = ">=3.11"
3
  # dependencies = [
4
  # "datasets",
5
+ # "huggingface-hub",
6
  # "pillow",
7
  # "toolz",
8
  # "torch",
9
  # "tqdm",
10
  # "transformers",
11
+ # "vllm>=0.11.0", # StructuredOutputsParams API (guided_decoding removed in 0.12.0)
12
  # ]
13
  # ///
14
 
 
52
 
53
  import torch
54
  from PIL import Image
55
+ from datasets import load_dataset
56
  from huggingface_hub import login
57
  from toolz import partition_all
58
  from tqdm.auto import tqdm
59
  from vllm import LLM, SamplingParams
60
+ from vllm.sampling_params import StructuredOutputsParams
61
 
62
  logging.basicConfig(level=logging.INFO)
63
  logger = logging.getLogger(__name__)
 
194
 
195
  llm = LLM(**llm_kwargs)
196
 
197
+ # Constrain output to one of the class labels (vLLM structured outputs).
198
+ # StructuredOutputsParams + structured_outputs= is the API from vLLM 0.11.0+;
199
+ # the old GuidedDecodingParams/guided_decoding= was removed in 0.12.0.
200
+ structured = StructuredOutputsParams(choice=class_list)
201
  sampling_params = SamplingParams(
202
  temperature=0.1, # Low temperature for consistent classification
203
  max_tokens=50, # Classifications are short
204
+ structured_outputs=structured,
205
  )
206
 
207
  # Process images in batches to avoid memory issues