Views
No views yet
text-generation: https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.TextGenerationPipelinetransformers>=4.37.0, or you might encounter the following error:KeyError: 'qwen2'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 "Qwen/Qwen2-0.5B-Instruct",
6 torch_dtype="auto",
7 device_map="auto"
8)
9tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-0.5B-Instruct")
10
11prompt = "Give me a short introduction to large language model."
12messages = [
13 {"role": "system", "content": "You are a helpful assistant."},
14 {"role": "user", "content": prompt}
15]
16text = tokenizer.apply_chat_template(
17 messages,
18 tokenize=False,
19 add_generation_prompt=True
20)
21model_inputs = tokenizer([text], return_tensors="pt").to(device)
22
23generated_ids = model.generate(
24 model_inputs.input_ids,
25 max_new_tokens=512
26)
27generated_ids = [
28 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
29]
30
31response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]| Datasets | Qwen1.5-0.5B-Chat | Qwen2-0.5B-Instruct | Qwen1.5-1.8B-Chat | Qwen2-1.5B-Instruct |
|---|---|---|---|---|
| MMLU | 35.0 | 37.9 | 43.7 | 52.4 |
| HumanEval | 9.1 | 17.1 | 25.0 | 37.8 |
| GSM8K | 11.3 | 40.1 | 35.3 | 61.6 |
| C-Eval | 37.2 | 45.2 | 55.3 | 63.8 |
| IFEval (Prompt Strict-Acc.) | 14.6 | 20.0 | 16.8 | 29.0 |
@article{qwen2,
title={Qwen2 Technical Report},
year={2024}
}