File size: 1,410 Bytes
ab428fd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # /// script
# dependencies = ["transformers>=4.46", "accelerate", "torch", "huggingface_hub", "hf-transfer"]
# requires-python = ">=3.11,<3.13"
# ///
# Ask the trained Handicate policy a question, on an HF GPU Job.
# hf jobs uv run -d --flavor a10g-large --timeout 30m --python 3.11 -s HF_TOKEN ./jobs/ask.py
import os
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
MODEL = "AmongTheCouch23/handicate-policy"
QUESTIONS = [
"Write a Python function that retries an HTTP GET with exponential backoff, and explain it in one line.",
"How do I cancel a runaway Hugging Face training job and confirm billing has stopped?",
"Write a bash one-liner to find the 5 largest files under the current directory.",
]
tok = AutoTokenizer.from_pretrained(MODEL)
model = AutoModelForCausalLM.from_pretrained(MODEL, torch_dtype=torch.bfloat16, device_map="cuda")
for q in QUESTIONS:
enc = tok.apply_chat_template([{"role": "user", "content": q}],
add_generation_prompt=True, return_tensors="pt", return_dict=True)
enc = {k: v.to(model.device) for k, v in enc.items()}
out = model.generate(**enc, max_new_tokens=400, do_sample=False)
ans = tok.decode(out[0][enc["input_ids"].shape[1]:], skip_special_tokens=True)
print("\n" + "=" * 70)
print("Q:", q)
print("A:", ans.strip())
|