Add verify_model.py to check pipeline without training
Browse files- verify_model.py +23 -0
verify_model.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Quick check that the pipeline works: load base BLOOM from Hub and generate.
|
| 3 |
+
Run: pip install -q transformers torch && python verify_model.py
|
| 4 |
+
No training required. Use test_model.py after training for your fine-tuned model.
|
| 5 |
+
"""
|
| 6 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
model_id = "bigscience/bloom-560m"
|
| 10 |
+
print("Loading model and tokenizer from Hub...")
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 12 |
+
if tokenizer.pad_token is None:
|
| 13 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 14 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 15 |
+
device = 0 if torch.cuda.is_available() else -1
|
| 16 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, device=device)
|
| 17 |
+
|
| 18 |
+
prompt = "User: Explícame este documento:\nLa IA mejora la productividad.\nAssistant:"
|
| 19 |
+
print("Generating...")
|
| 20 |
+
out = pipe(prompt, max_new_tokens=60, do_sample=True, temperature=0.7, pad_token_id=tokenizer.pad_token_id)
|
| 21 |
+
print("\n--- Full output ---")
|
| 22 |
+
print(out[0]["generated_text"])
|
| 23 |
+
print("\n--- Model works: pipeline ran and produced text. ---")
|