Views
No views yet
| Task | Metric | Value |
|---|---|---|
| arc_easy | acc,none | 0.4659 |
| arc_easy | acc_stderr,none | 0.0102 |
| arc_easy | acc_norm,none | 0.4423 |
| arc_easy | acc_norm_stderr,none | 0.0102 |
| arc_challenge | acc,none | 0.2287 |
| arc_challenge | acc_stderr,none | 0.0123 |
| arc_challenge | acc_norm,none | 0.2756 |
| arc_challenge | acc_norm_stderr,none | 0.0131 |
| hellaswag | acc,none | 0.2794 |
| hellaswag | acc_stderr,none | 0.0045 |
| hellaswag | acc_norm,none | 0.2922 |
| hellaswag | acc_norm_stderr,none | 0.0045 |
| winogrande | acc,none | 0.5154 |
| winogrande | acc_stderr,none | 0.0140 |
| piqa | acc,none | 0.5558 |
| piqa | acc_stderr,none | 0.0114 |
| piqa | acc_norm,none | 0.5952 |
| piqa | acc_norm_stderr,none | 0.0115 |
| openbookqa | acc,none | 0.1580 |
| openbookqa | acc_stderr,none | 0.0163 |
| openbookqa | acc_norm,none | 0.2860 |
| openbookqa | acc_norm_stderr,none | 0.0202 |
| boolq | acc,none | 0.4205 |
| boolq | acc_stderr,none | 0.0086 |
1import os
2import warnings
3import time
4
5os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
6os.environ["CUDA_VISIBLE_DEVICES"] = "0"
7warnings.filterwarnings("ignore", category=UserWarning, module="transformers")
8
9import torch
10from transformers import pipeline, AutoTokenizer, logging
11
12logging.set_verbosity_error()
13
14# ── Global variables ──────────────────────────────────────────────────────────
15
16end = time.time()
17start = time.time()
18tokens = []
19
20
21# ── Config ────────────────────────────────────────────────────────────────────
22
23MODEL_ID = "SupraLabs/Supra-50M-Instruct"
24MAX_NEW_TOKENS = 512
25
26# ── Load pipeline directly from HF ────────────────────────────────────────────
27
28print(f"[*] Loading SFT model and tokenizer from HF Hub ({MODEL_ID})...")
29
30tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, clean_up_tokenization_spaces=False)
31
32pipe = pipeline(
33 "text-generation",
34 model=MODEL_ID,
35 tokenizer=tokenizer,
36 device_map="auto",
37 torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32
38)
39
40print(f"[+] Pipeline ready — Model loaded using {pipe.model.device}")
41
42# ── Prompt template (must match sft.py exactly) ───────────────────────────────
43
44def build_prompt(instruction: str, input_text: str = "") -> str:
45 if input_text.strip():
46 return (
47 "Below is an instruction that describes a task, paired with an input "
48 "that provides further context. Write a response that appropriately "
49 "completes the request.\n\n"
50 f"### Instruction:\n{instruction}\n\n"
51 f"### Input:\n{input_text}\n\n"
52 "### Response:\n"
53 )
54 return (
55 "Below is an instruction that describes a task. Write a response that "
56 "appropriately completes the request.\n\n"
57 f"### Instruction:\n{instruction}\n\n"
58 "### Response:\n"
59 )
60
61# ── Generate ──────────────────────────────────────────────────────────────────
62
63def generate(instruction: str, input_text: str = "", max_new_tokens: int = MAX_NEW_TOKENS) -> str:
64 prompt = build_prompt(instruction, input_text)
65 start = time.time()
66 result = pipe(
67 prompt,
68 max_new_tokens=max_new_tokens,
69 do_sample=True,
70 temperature=0.7,
71 top_k=50,
72 top_p=0.9,
73 repetition_penalty=1.15,
74 pad_token_id=pipe.tokenizer.pad_token_id,
75 eos_token_id=pipe.tokenizer.eos_token_id,
76 return_full_text=False,
77 generation_config=None
78 )
79 end = time.time()
80
81 generated_text = result[0]["generated_text"]
82 tokens = pipe.tokenizer(generated_text)["input_ids"]
83
84 return generated_text, tokens, end, start
85
86# ── Interactive loop ──────────────────────────────────────────────────────────
87
88if __name__ == "__main__":
89 print("\n[+] Ready. Type 'quit' to exit.\n")
90
91 while True:
92 instruction = input("Instruction: ").strip()
93 if instruction.lower() == "quit":
94 break
95
96 inp = input("Input (optional, Enter to skip): ").strip()
97
98 print("-" * 50)
99 text, tokens, end, start = generate(instruction, inp)
100 print(text)
101 print()
102
103 print(f"Generated tokens: {len(tokens)}")
104 print(f"Time: {end - start:.2f}s")
105 print(f"Speed: {len(tokens) / (end - start):.2f} tokens/sec")temperature=0.7, top_k=50, top_p=0.9, repetition_penalty=1.15