Views
No views yet
transformers>=4.40.0, or you might encounter the following error:KeyError: 'qwen2_moe'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-57B-A14B-Instruct",
6 torch_dtype="auto",
7 device_map="auto"
8)
9tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-57B-A14B-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]config.json file by including the below snippet:1 {
2 "architectures": [
3 "Qwen2MoeForCausalLM"
4 ],
5 // ...
6 "vocab_size": 152064,
7
8 // adding the following snippets
9 "rope_scaling": {
10 "factor": 2.0,
11 "original_max_position_embeddings": 32768,
12 "type": "yarn"
13 }
14 }python -m vllm.entrypoints.openai.api_server --served-model-name Qwen2-57B-A14B-Instruct --model path/to/weights1curl http://localhost:8000/v1/chat/completions \
2 -H "Content-Type: application/json" \
3 -d '{
4 "model": "Qwen2-57B-A14B-Instruct",
5 "messages": [
6 {"role": "system", "content": "You are a helpful assistant."},
7 {"role": "user", "content": "Your Long Input Here."}
8 ]
9 }'rope_scaling configuration only when processing long contexts is required.| Datasets | Mixtral-8x7B-Instruct-v0.1 | Yi-1.5-34B-Chat | Qwen1.5-32B-Chat | Qwen2-57B-A14B-Instruct |
|---|---|---|---|---|
| Architecture | MoE | Dense | Dense | MoE |
| #Activated Params | 12B | 34B | 32B | 14B |
| #Params | 47B | 34B | 32B | 57B |
| English | ||||
| MMLU | 71.4 | 76.8 | 74.8 | 75.4 |
| MMLU-Pro | 43.3 | 52.3 | 46.4 | 52.8 |
| GPQA | - | - | 30.8 | 34.3 |
| TheroemQA | - | - | 30.9 | 33.1 |
| MT-Bench | 8.30 | 8.50 | 8.30 | 8.55 |
| Coding | ||||
| HumanEval | 45.1 | 75.2 | 68.3 | 79.9 |
| MBPP | 59.5 | 74.6 | 67.9 | 70.9 |
| MultiPL-E | - | - | 50.7 | 66.4 |
| EvalPlus | 48.5 | - | 63.6 | 71.6 |
| LiveCodeBench | 12.3 | - | 15.2 | 25.5 |
| Mathematics | ||||
| GSM8K | 65.7 | 90.2 | 83.6 | 79.6 |
| MATH | 30.7 | 50.1 | 42.4 | 49.1 |
| Chinese | ||||
| C-Eval | - | - | 76.7 | 80.5 |
| AlignBench | 5.70 | 7.20 | 7.19 | 7.36 |
@article{qwen2,
title={Qwen2 Technical Report},
year={2024}
}