Views
No views yet
apply_chat_template to show you how to load the tokenizer and model and how to generate contents.1from transformers import AutoModelForCausalLM, AutoTokenizer
2device = "cuda" # the device to load the model onto
3
4model = AutoModelForCausalLM.from_pretrained(
5 "alibaba-pai/DistilQwen2-7B-Instruct",
6 torch_dtype="auto",
7 device_map="auto"
8)
9tokenizer = AutoTokenizer.from_pretrained("alibaba-pai/DistilQwen2-7B-Instruct")
10
11prompt = "Give me a short introduction to large language model."
12messages = [
13 {"role": "user", "content": prompt}
14]
15text = tokenizer.apply_chat_template(
16 messages,
17 tokenize=False,
18 add_generation_prompt=True
19)
20model_inputs = tokenizer([text], return_tensors="pt").to(device)
21
22generated_ids = model.generate(
23 model_inputs.input_ids,
24 max_new_tokens=2048,
25)
26generated_ids = [
27 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
28]
29
30response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]| Model | AlpacaEval 2.0 (length-controlled) | MT-Bench | MT-Bench (single) | IFEval (instruction-loose) | IFEval (strict-prompt) |
|---|---|---|---|---|---|
| Qwen2-1.5B-Instruct | 5.22 | 5.85 | 6.45 | 41.37 | 28.10 |
| DistilQwen2-1.5B-Instruct | 8.28 | 6.42 | 7.12 | 49.76 | 36.04 |
| Qwen2-7B-Instruct | 24.33 | 8.27 | 8.68 | 66.67 | 52.31 |
| DistilQwen2-7B-Instruct | 25.35 | 8.40 | 9.03 | 71.46 | 60.26 |
@misc{TAPIR,
title={Distilling Instruction-following Abilities of Large Language Models with Task-aware Curriculum Planning},
author={Yuanhao Yue and Chengyu Wang and Jun Huang and Peng Wang},
year={2024},
eprint={2405.13448},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2405.13448},
}