| |
| |
| |
| |
| |
| |
| 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()) |
|
|