File size: 2,391 Bytes
31edbe3 c53d936 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
---
license: apache-2.0
---
# QwQ-Math-1.5B-Persona
## Introduction
QwQ-Math-1.5B-Persona is finetuned from Qwen2.5-Math-1.5B-Instruct on 1 million math persona data (see [this paper](https://arxiv.org/abs/2406.20094) for details about how to construct the data).
Currently QwQ-Math-1.5B-Persona is meant to serve as a draft model for losslessly accelerating the inference of QwQ-32B, but you may also use it as a standalone model.
## Quickstart
Here is a code snippet for using QwQ-Math-1.5B-Persona to accelerate the inference of QwQ 32B:
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained(
"Qwen/QwQ-32B-Preview",
torch_dtype="auto",
device_map={'': 0}
)
draft_model = AutoModelForCausalLM.from_pretrained(
"Geralt-Targaryen/QwQ-Math-1.5B-Persona",
torch_dtype="auto",
device_map={'': 0}
)
tokenizer = AutoTokenizer.from_pretrained("Qwen/QwQ-32B-Preview")
prompt = "How many r in strawberry."
messages = [
{"role": "system", "content": "You are a helpful and harmless assistant. You are Qwen developed by Alibaba. You should think step-by-step."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=512,
assistant_model=draft_model
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
```
For the more advanced SVIP draft length policy, please refer to [this GitHub repo](https://github.com/Geralt-Targaryen/SVIP).
## Citation
If you find QwQ-Math-1.5B-Persona to be helpful, please cite the following paper.
```
@misc{zhang2024svip,
title={Draft Model Knows When to Stop: A Self-Verification Length Policy for Speculative Decoding},
author={Ziyin Zhang and Jiahao Xu and Tian Liang and Xingyu Chen and Zhiwei He and Rui Wang and Zhaopeng Tu},
year={2024},
eprint={2411.18462},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2411.18462},
}
```
|