🚀 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 許可證。
📦 模型信息