oExz commited on
Commit
1e646bc
·
verified ·
1 Parent(s): 54c1b43

Upload eval_gsm8k_custom.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. eval_gsm8k_custom.py +4 -4
eval_gsm8k_custom.py CHANGED
@@ -6,7 +6,6 @@
6
  # "torch>=2.0.0",
7
  # "huggingface-hub",
8
  # "accelerate",
9
- # "bitsandbytes",
10
  # ]
11
  # ///
12
 
@@ -27,7 +26,7 @@ import torch
27
 
28
  tok = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=True)
29
  m = AutoModelForCausalLM.from_pretrained(
30
- MODEL, trust_remote_code=True, device_map="auto", torch_dtype=torch.bfloat16
31
  )
32
 
33
  sys_msg = "You are a helpful assistant that solves math problems step by step."
@@ -41,7 +40,8 @@ for i, ex in enumerate(ds):
41
  ]
42
  inp = tok.apply_chat_template(msgs, tokenize=True, return_tensors="pt", add_generation_prompt=True)
43
  inp = {k: v.to(m.device) for k, v in inp.items()}
44
- out = m.generate(**inp, max_new_tokens=512, do_sample=False)
 
45
  gen = tok.decode(out[0][inp["input_ids"].shape[1]:], skip_special_tokens=True)
46
 
47
  gt_match = re.search(r"####\s*(-?\d[\d,]*\.?\d*)", ex["answer"])
@@ -56,7 +56,7 @@ for i, ex in enumerate(ds):
56
 
57
  if pred == gt:
58
  correct += 1
59
- if i < 5:
60
  print(f"Q{i+1}: GT={gt} Pred={pred} OK={pred==gt}")
61
 
62
  accuracy = correct / total * 100
 
6
  # "torch>=2.0.0",
7
  # "huggingface-hub",
8
  # "accelerate",
 
9
  # ]
10
  # ///
11
 
 
26
 
27
  tok = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=True)
28
  m = AutoModelForCausalLM.from_pretrained(
29
+ MODEL, trust_remote_code=True, device_map="auto", torch_dtype=torch.float16
30
  )
31
 
32
  sys_msg = "You are a helpful assistant that solves math problems step by step."
 
40
  ]
41
  inp = tok.apply_chat_template(msgs, tokenize=True, return_tensors="pt", add_generation_prompt=True)
42
  inp = {k: v.to(m.device) for k, v in inp.items()}
43
+ with torch.no_grad():
44
+ out = m.generate(**inp, max_new_tokens=512, do_sample=False)
45
  gen = tok.decode(out[0][inp["input_ids"].shape[1]:], skip_special_tokens=True)
46
 
47
  gt_match = re.search(r"####\s*(-?\d[\d,]*\.?\d*)", ex["answer"])
 
56
 
57
  if pred == gt:
58
  correct += 1
59
+ if i < 5 or i % 50 == 0:
60
  print(f"Q{i+1}: GT={gt} Pred={pred} OK={pred==gt}")
61
 
62
  accuracy = correct / total * 100