🚀 Qwen/QwQ-32B(量化版)
本项目是Qwen/QwQ-32B的量化版本模型,借助量化技术在保持一定性能的同时,有效减少了模型的存储需求和计算资源消耗,提升了模型的部署效率和推理速度。
🚀 快速开始
以下代码片段展示了如何使用 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 代替贪心解码,以避免无限重复。
- 使用 20 到 40 之间的 TopK 来过滤掉罕见的标记出现,同时保持生成输出的多样性。
- 对于支持的框架,可以将
presence_penalty
参数调整在 0 到 2 之间,以减少无限重复。但是,使用较高的值可能会导致偶尔的语言混合和性能略有下降。
- 历史记录中无思考内容:在多轮对话中,历史模型输出应仅包括最终输出部分,不需要包括思考内容。此功能已在
apply_chat_template
中实现。
- 标准化输出格式:在进行基准测试时,建议使用提示来标准化模型输出:
- 数学问题:在提示中包含 "Please reason step by step, and put your final answer within \boxed{}."。
- 多项选择题:在提示中添加以下 JSON 结构以标准化响应:"Please show your choice in the
answer
field with only the choice letter, e.g.,\"answer\": \"C\"
."。
- 处理长输入:对于超过 8192 个标记的输入,启用 YaRN 以有效提高模型捕获长序列信息的能力。
对于支持的框架,可以在 config.json
中添加以下内容以启用 YaRN:
{
...,
"rope_scaling": {
"factor": 4.0,
"original_max_position_embeddings": 32768,
"type": "yarn"
}
}
对于部署,建议使用 vLLM。如果不熟悉 vLLM,请参考文档。目前,vLLM 仅支持静态 YARN,这意味着无论输入长度如何,缩放因子都保持不变,可能会影响短文本的性能。建议仅在处理长上下文时添加 rope_scaling
配置。
✨ 主要特性
量化版本特性
量化详情
- 量化类型:int4
- bnb_4bit_quant_type:nf4
- bnb_4bit_use_double_quant:True
- bnb_4bit_compute_dtype:bfloat16
- bnb_4bit_quant_storage:uint8
QwQ-32B 模型特性
QwQ 是通义系列的推理模型。与传统的指令调优模型相比,具备思考和推理能力的 QwQ 在下游任务,尤其是难题上,可以显著提升性能。QwQ-32B 是中等规模的推理模型,能够与最先进的推理模型(如 DeepSeek-R1、o1-mini)相媲美。
本仓库包含 QwQ 32B 模型,具有以下特点:
- 类型:因果语言模型
- 训练阶段:预训练和后训练(监督微调与强化学习)
- 架构:带有 RoPE、SwiGLU、RMSNorm 和注意力 QKV 偏置的 Transformer
- 参数数量:325 亿
- 非嵌入参数数量:310 亿
- 层数:64
- 注意力头数量(GQA):Q 为 40,KV 为 8
- 上下文长度:完整的 131072 个标记
- 对于长度超过 8192 个标记的提示,必须按照此部分所述启用 YaRN。
📚 详细文档
评估与性能
详细的评估结果见此📑 博客。
有关 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}
}
📄 许可证
本项目采用 apache-2.0 许可证。
📦 模型信息