Sync from GitHub via hub-sync
Browse files- classify-dataset.py +16 -8
classify-dataset.py
CHANGED
|
@@ -2,12 +2,20 @@
|
|
| 2 |
# /// script
|
| 3 |
# requires-python = ">=3.10"
|
| 4 |
# dependencies = [
|
| 5 |
-
# "vllm>=0.
|
| 6 |
# "transformers>=4.53.0",
|
| 7 |
# "torch",
|
| 8 |
# "datasets",
|
| 9 |
# "huggingface-hub[hf_transfer]",
|
| 10 |
# ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# ///
|
| 12 |
|
| 13 |
"""
|
|
@@ -24,12 +32,12 @@ Example:
|
|
| 24 |
--output-dataset user/imdb-classified
|
| 25 |
|
| 26 |
HF Jobs example:
|
| 27 |
-
|
| 28 |
--input-dataset user/emails \\
|
| 29 |
--column content \\
|
| 30 |
--labels "spam,ham" \\
|
| 31 |
--output-dataset user/emails-classified \\
|
| 32 |
-
--
|
| 33 |
"""
|
| 34 |
|
| 35 |
import argparse
|
|
@@ -43,7 +51,7 @@ from datasets import load_dataset
|
|
| 43 |
from huggingface_hub import HfApi, get_token
|
| 44 |
from transformers import AutoTokenizer
|
| 45 |
from vllm import LLM, SamplingParams
|
| 46 |
-
from vllm.sampling_params import
|
| 47 |
|
| 48 |
# Default model - SmolLM3 for good balance of speed and quality
|
| 49 |
DEFAULT_MODEL = "HuggingFaceTB/SmolLM3-3B"
|
|
@@ -448,7 +456,7 @@ def main():
|
|
| 448 |
trust_remote_code=True,
|
| 449 |
dtype="auto",
|
| 450 |
gpu_memory_utilization=0.95,
|
| 451 |
-
|
| 452 |
)
|
| 453 |
except Exception as e:
|
| 454 |
logger.error(f"Failed to initialize vLLM: {e}")
|
|
@@ -464,9 +472,9 @@ def main():
|
|
| 464 |
logger.info("Using reasoning mode - model will generate thinking traces with JSON output")
|
| 465 |
else:
|
| 466 |
# Structured output mode: guided decoding
|
| 467 |
-
|
| 468 |
sampling_params = SamplingParams(
|
| 469 |
-
|
| 470 |
temperature=args.temperature,
|
| 471 |
max_tokens=args.max_tokens,
|
| 472 |
)
|
|
@@ -617,7 +625,7 @@ if __name__ == "__main__":
|
|
| 617 |
print("\n# HF Jobs example:")
|
| 618 |
print("hf jobs uv run \\")
|
| 619 |
print(" --flavor l4x1 \\")
|
| 620 |
-
print(" --image vllm/vllm-openai:
|
| 621 |
print(" classify-dataset.py \\")
|
| 622 |
print(" --input-dataset stanfordnlp/imdb \\")
|
| 623 |
print(" --column text \\")
|
|
|
|
| 2 |
# /// script
|
| 3 |
# requires-python = ">=3.10"
|
| 4 |
# dependencies = [
|
| 5 |
+
# "vllm>=0.12.0", # StructuredOutputsParams API (guided_decoding removed in 0.12.0)
|
| 6 |
# "transformers>=4.53.0",
|
| 7 |
# "torch",
|
| 8 |
# "datasets",
|
| 9 |
# "huggingface-hub[hf_transfer]",
|
| 10 |
# ]
|
| 11 |
+
#
|
| 12 |
+
# [tool.hf-jobs]
|
| 13 |
+
# image = "vllm/vllm-openai:v0.32.0"
|
| 14 |
+
# python = "/usr/bin/python3"
|
| 15 |
+
# env = { PYTHONPATH = "/usr/local/lib/python3.12/dist-packages" }
|
| 16 |
+
# flavor = "l4x1"
|
| 17 |
+
# secrets = ["HF_TOKEN"]
|
| 18 |
+
# timeout = "1h"
|
| 19 |
# ///
|
| 20 |
|
| 21 |
"""
|
|
|
|
| 32 |
--output-dataset user/imdb-classified
|
| 33 |
|
| 34 |
HF Jobs example:
|
| 35 |
+
hf jobs uv run classify-dataset.py \\
|
| 36 |
--input-dataset user/emails \\
|
| 37 |
--column content \\
|
| 38 |
--labels "spam,ham" \\
|
| 39 |
--output-dataset user/emails-classified \\
|
| 40 |
+
--enable-reasoning
|
| 41 |
"""
|
| 42 |
|
| 43 |
import argparse
|
|
|
|
| 51 |
from huggingface_hub import HfApi, get_token
|
| 52 |
from transformers import AutoTokenizer
|
| 53 |
from vllm import LLM, SamplingParams
|
| 54 |
+
from vllm.sampling_params import StructuredOutputsParams
|
| 55 |
|
| 56 |
# Default model - SmolLM3 for good balance of speed and quality
|
| 57 |
DEFAULT_MODEL = "HuggingFaceTB/SmolLM3-3B"
|
|
|
|
| 456 |
trust_remote_code=True,
|
| 457 |
dtype="auto",
|
| 458 |
gpu_memory_utilization=0.95,
|
| 459 |
+
structured_outputs_config={"backend": args.guided_backend},
|
| 460 |
)
|
| 461 |
except Exception as e:
|
| 462 |
logger.error(f"Failed to initialize vLLM: {e}")
|
|
|
|
| 472 |
logger.info("Using reasoning mode - model will generate thinking traces with JSON output")
|
| 473 |
else:
|
| 474 |
# Structured output mode: guided decoding
|
| 475 |
+
structured = StructuredOutputsParams(choice=labels)
|
| 476 |
sampling_params = SamplingParams(
|
| 477 |
+
structured_outputs=structured,
|
| 478 |
temperature=args.temperature,
|
| 479 |
max_tokens=args.max_tokens,
|
| 480 |
)
|
|
|
|
| 625 |
print("\n# HF Jobs example:")
|
| 626 |
print("hf jobs uv run \\")
|
| 627 |
print(" --flavor l4x1 \\")
|
| 628 |
+
print(" --image vllm/vllm-openai:v0.32.0 \\")
|
| 629 |
print(" classify-dataset.py \\")
|
| 630 |
print(" --input-dataset stanfordnlp/imdb \\")
|
| 631 |
print(" --column text \\")
|