Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_id = "natong19/Qwen2-7B-Instruct-abliterated"
4device = "cuda" # the device to load the model onto
5
6model = AutoModelForCausalLM.from_pretrained(
7 model_id,
8 torch_dtype="auto",
9 device_map="auto"
10)
11tokenizer = AutoTokenizer.from_pretrained(model_id)
12
13prompt = "Give me a short introduction to large language model."
14messages = [
15 {"role": "system", "content": "You are a helpful assistant."},
16 {"role": "user", "content": prompt}
17]
18text = tokenizer.apply_chat_template(
19 messages,
20 tokenize=False,
21 add_generation_prompt=True
22)
23model_inputs = tokenizer([text], return_tensors="pt").to(device)
24
25generated_ids = model.generate(
26 model_inputs.input_ids,
27 max_new_tokens=256
28)
29generated_ids = [
30 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
31]
32
33response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
34print(response)| Datasets | Qwen2-7B-Instruct | Qwen2-7B-Instruct-abliterated |
|---|---|---|
| ARC (25-shot) | 62.5 | 62.5 |
| GSM8K (5-shot) | 73.0 | 72.2 |
| HellaSwag (10-shot) | 81.8 | 81.7 |
| MMLU (5-shot) | 70.7 | 70.5 |
| TruthfulQA (0-shot) | 57.3 | 55.0 |
| Winogrande (5-shot) | 76.2 | 77.4 |