Views
No views yet
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
3model_id="empirischtech/Llama-3.1-10B-Instruct"
4tokenizer = AutoTokenizer.from_pretrained(model_id)
5model = AutoModelForCausalLM.from_pretrained(
6 model_id,
7 device_map="auto",
8 torch_dtype=torch.float16
9)
10
11prompt = "### User:\nEmma feels perfectly fine, yet she still has an appointment at the hospital. What might be the reasons?\n\n### Assistant:\n"
12inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
13del inputs["token_type_ids"]
14streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
15
16output = model.generate(**inputs, streamer=streamer, use_cache=True, max_new_tokens=1024)
17output_text = tokenizer.decode(output[0], skip_special_tokens=True)ARC-Challenge, HellaSwag, MMLU and IFEval.
The library used is lm-evaluation-harness repository| Benchmark | Llama-3.1-8B-Instruct | Llama-3.1-10B-Instruct |
|---|---|---|
| ARC | 55.05 | 52.47 |
| HellaSwag | 79.28 | 77.08 |
| MMLU-Pro | 40.34 | 33.59 |
| IFEval | 59.95 | 54.80 |
| average | 58.66 | 54.49 |
1# install from https://github.com/EleutherAI/lm-evaluation-harness
2pip install lm-eval>=0.4.7
3
4from lm_eval import evaluator
5
6tasks_list = ["arc_challenge", "ifeval", "mmlu_pro", "hellaswag"] # Benchmark dataset
7
8model_path="empirischtech/Llama-3.1-10B-Instruct"
9
10# Run evaluation
11results = evaluator.simple_evaluate(
12 model="hf", # Hugging Face model
13 cache_requests=False,
14 model_args=f"pretrained={model_path}",
15 tasks=tasks_list,
16 batch_size=4,
17 device="cuda:0"
18)
19
20# Extract results
21results = results['results']
22json_string = json.dumps(results, indent=4)
23