介绍
QwQ 是 Qwen 系列的推理模型。与传统的指令调优模型相比,具备思考和推理能力的 QwQ 在下游任务中,尤其是在解决难题时,能够显著提升性能。QwQ-32B 是一款中等规模的推理模型,其性能可以与最先进的推理模型(如 DeepSeek-R1、o1-mini)相媲美。
此仓库包含 QwQ 32B 模型,具有以下特点:
类型:因果语言模型
训练阶段:预训练 & 后训练(监督微调和强化学习)
架构:带有 RoPE、SwiGLU、RMSNorm 和注意力 QKV 偏置的 transformers
参数数量:325 亿
非嵌入参数数量:310 亿
层数:64 层
注意力头数(GQA):Q 为 40 个,KV 为 8 个
上下文长度:完整 131,072 个 tokens
对于超过 8,192 个 tokens 的提示,必须按照使用指南中的说明启用 YaRN。
**注意:**为了获得最佳体验,请在部署 QwQ 模型之前查阅使用指南。
您可以尝试我们的演示,或通过 QwenChat 访问 QwQ 模型。
更多详情,请参阅我们的博客、GitHub 和文档。
要求
QwQ 基于 Qwen2.5,其代码已在最新的 Hugging Face transformers
中提供。我们建议您使用最新版本的 transformers
。
如果使用 transformers<4.37.0
,将会遇到以下错误:
KeyError: ‘qwen2’
快速开始
这里提供了一个使用 apply_chat_template
的代码片段,展示了如何加载分词器和模型以及如何生成内容。
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "Qwen/QwQ-32B"
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
prompt = "How many r's are in the word \"strawberry\""
messages = [
{"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=32768
)
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]
print(response)
使用指南
为了达到最佳性能,我们推荐以下设置:
-
确保有深度的输出: 确保模型以”<think>\n”开始,以防止生成空的思考内容,这可能会降低输出质量。如果你使用
apply_chat_template
并设置add_generation_prompt=True
,这已经被自动实现,但这可能导致响应在开头缺少<think>标签。这是正常的行为。 -
采样参数:
- 使用Temperature=0.6, TopP=0.95, MinP=0来代替贪婪解码,以避免无尽重复。
- 使用TopK在20到40之间,以过滤掉罕见的token出现同时保持生成输出的多样性。
- 对于支持的框架,你可以将
presence_penalty
参数调整在0到2之间,以减少无尽重复。然而,使用较高的值可能会偶尔导致语言混合和性能轻微下降。
-
历史记录中不含思考内容: 在多轮对话中,历史模型输出应该只包括最终输出部分,不需要包含思考内容。这一特性已经在
apply_chat_template
中实现。 -
标准化输出格式: 我们建议在基准测试时通过提示来标准化模型输出。
- 数学问题: 在提示中加入”请逐步推理,并将你的最终答案放在\boxed{}内。”
- 选择题: 在提示中添加以下JSON结构以标准化回答:”请在
answer
字段中仅用选项字母显示你的选择,例如,\"answer\": \"C\"
。”
-
处理长输入: 对于超过8,192个token的输入,启用YARN可以有效提高模型捕捉长序列信息的能力。
对于支持的框架,你可以在
config.json
中添加如下配置以启用YARN:{ ..., "rope_scaling": { "factor": 4.0, "original_max_position_embeddings": 32768, "type": "yarn" } }
部署时,我们推荐使用vLLM。如果不熟悉vLLM,请参考我们的文档了解如何使用。 目前,vLLM仅支持静态YARN,这意味着缩放因子不会根据输入长度变化而改变,可能会影响较短文本上的表现。 我们建议仅在需要处理长上下文时才添加
rope_scaling
配置。评估与性能
详细的评估结果报告在此📑博客中。
关于GPU内存需求以及相应的吞吐量,请参见这里的结果。
引用
如果觉得我们的工作对您有所帮助,请随意引用。
@misc{qwq32b, title = {QwQ-32B: Embracing the Power of Reinforcement Learning}, url = {https://qwenlm.github.io/blog/qwq-32b/}, author = {Qwen Team}, month = {March}, year = {2025} } @article{qwen2.5, title={Qwen2.5 Technical Report}, author={An Yang and Baosong Yang and Beichen Zhang and Binyuan Hui and Bo Zheng and Bowen Yu and Chengyuan Li and Dayiheng Liu and Fei Huang and Haoran Wei and Huan Lin and Jian Yang and Jianhong Tu and Jianwei Zhang and Jianxin Yang and Jiaxi Yang and Jingren Zhou and Junyang Lin and Kai Dang and Keming Lu and Keqin Bao and Kexin Yang and Le Yu and Mei Li and Mingfeng Xue and Pei Zhang and Qin Zhu and Rui Men and Runji Lin and Tianhao Li and Tianyi Tang and Tingyu Xia and Xingzhang Ren and Xuancheng Ren and Yang Fan and Yang Su and Yichang Zhang and Yu Wan and Yuqiong Liu and Zeyu Cui and Zhenru Zhang and Zihan Qiu}, journal={arXiv preprint arXiv:2412.15115}, year={2024} }
暂无评论内容