高效运行 QwQ-32B + 错误修复

文章目录

    • QwQ-32B 错误修复
    • ⚙️ 官方推荐设置
    • 👍 推荐的 llama.cpp 设置
    • 📖 教程:运行和修复的 QwQ-32B
      • 1、对于 llama.cpp 及使用 llama.cpp 的引擎:
      • 2、下载模型 + 测试
      • 3、测试/评估
      • 4、尝试不使用我们的修复方案:
    • 💡 `<think>` 令牌未显示?
    • 🧪 实验结果 + 备注
    • 🦥 动态 4 位量化
    • 🛠️ 微调 QwQ-32B
    • 性能基准测试


本文翻译整理自:Run QwQ-32B effectively + Bug Fixes (Mar 7, 2025 • By Daniel & Michael
https://unsloth.ai/blog/qwq-32b


Qwen发布了QwQ-32B,这是一个性能可与DeepSeek-R1相媲美的强大推理模型。你可能遇到过诸如无限循环、重复、令牌错误以及微调挑战等问题,这些问题并不能反映模型的真实质量。我们希望这篇博客能帮助你调试和修复大多数问题![查看教程](https://unsloth.ai/blog/qwq-32b#Tutorial QwQ)
我们的模型上传包含错误修复和对微调、vLLM 和 Transformers 的工作,但是如果你在使用 llama.cpp 以及作为后端使用 llama.cpp 的引擎,你可能已经遇到了问题。要解决问题,请遵循下面的教程,或阅读我们文档中的详细指南和分析。
查看所有Unsloth修复的QwQ-32B上传,包括GGUF和动态4位,在此处。


QwQ-32B 错误修复

我们发现了一些问题,尤其是影响了微调的部分!EOS令牌是正确的,但PAD令牌可能更应该被 “<|vision_pad|>” 替代。我们已经在 这里 更新了它。

"eos_token": "<|im_end|>",
"pad_token": "<|endoftext|>",

⚙️ 官方推荐设置

根据Qwen,这些是推荐的推理设置:

  • Temperature of 0.6
    Top_K of 40 (or 20 to 40)
    Min_P of 0.0
    Top_P of 0.95
  • 重复惩罚为1.0。(1.0表示在llama.cpp和transformers中禁用)
  • 聊天模板: <|im_start|>user\nCreate a Flappy Bird game in Python.<|im_end|>\n<|im_start|>assistant\n<think>\n

👍 推荐的 llama.cpp 设置

我们注意到很多人使用大于1.0的重复惩罚系数。例如1.1到1.5。这实际上干扰了llama.cpp的采样机制。重复惩罚的目标是惩罚重复的生成,但我们发现这并没有按预期工作。

关闭重复惩罚(即将其设置为1.0)也有效,但我们发现使用它来惩罚无限生成是有用的。

要使用它,我们发现您还必须编辑 llama.cpp 中采样器的顺序,在应用重复惩罚之前,否则将会有无尽的生成。所以添加这个:

--samplers "top_k;top_p;min_p;temperature;dry;typ_p;xtc"

默认情况下,llama.cpp 使用以下排序顺序:

--samplers "dry;top_k;typ_p;top_p;min_p;xtc;temperature"

我们重新排序了基本温度和干燥,并将 min_p 前移。这意味着我们按照以下顺序应用采样器:

top_k=40
top_p=0.95
min_p=0.0
temperature=0.6
dry
typ_p
xtc

📖 教程:运行和修复的 QwQ-32B


1、对于 llama.cpp 及使用 llama.cpp 的引擎:

您可以在我们的这里阅读我们的完整指南。获取最新的 llama.cpp 在:github.com/ggml-org/llama.cpp。

您也可以按照下面的构建说明进行操作。如果您没有 GPU 或者只想使用 CPU 推理,将 -DGGML_CUDA=ON 改为 -DGGML_CUDA=OFF。

apt-get update
apt-get install build-essential cmake curl libcurl4-openssl-dev -y
git clone https://github.com/ggerganov/llama.cpp
cmake llama.cpp -B llama.cpp/build \-DBUILD_SHARED_LIBS=ON -DGGML_CUDA=ON -DLLAMA_CURL=ON
cmake --build llama.cpp/build --config Release -j --clean-first --target llama-quantize llama-cli llama-gguf-split
cp llama.cpp/build/bin/llama-* llama.cpp

2、下载模型 + 测试

下载模型通过(在安装 pip install huggingface_hub hf_transfer 后)。您可以选择 Q4_K_M,或其他量化版本(如 BF16 全精度)。其他变体:huggingface.co/unsloth/QwQ-32B-GGUF
然后运行Unsloth的Flappy Bird测试,该测试会将输出保存到 Q4_K_M_yes_samplers.txt

# !pip install huggingface_hub hf_transfer
import os
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
from huggingface_hub import snapshot_download
snapshot_download(repo_id = "unsloth/QwQ-32B-GGUF",local_dir = "unsloth-QwQ-32B-GGUF",allow_patterns = ["*Q4_K_M*"], # For Q4_K_M
)

3、测试/评估

编辑 --threads 32 以设置 CPU 线程数,--ctx-size 16384 以设置上下文长度,--n-gpu-layers 99 以设置在多少层上进行 GPU 负载卸载。

如果您的 GPU 内存不足,请尝试调整它。如果您只有 CPU 推理,也请将其删除。
我们使用 --repeat-penalty 1.1--dry-multiplier 0.5,这些值你可以调整。

./llama.cpp/llama-cli \--model unsloth-QwQ-32B-GGUF/QwQ-32B-Q4_K_M.gguf \--threads 32 \--ctx-size 16384 \--n-gpu-layers 99 \--seed 3407 \--prio 2 \--temp 0.6 \--repeat-penalty 1.5 \--repeat-penalty 1.1 \--dry-multiplier 0.5 \--min-p 0.0 \--top-k 40 \--top-p 0.95 \-no-cnv \--samplers "top_k;top_p;min_p;temperature;dry;typ_p;xtc" \--prompt "<|im_start|>user\nCreate a Flappy Bird game in Python. You must include these things:\n1. You must use pygame.\n2. The background color should be randomly chosen and is a light shade. Start with a light blue color.\n3. Pressing SPACE multiple times will accelerate the bird.\n4. The bird's shape should be randomly chosen as a square, circle or triangle. The color should be randomly chosen as a dark color.\n5. Place on the bottom some land colored as dark brown or yellow chosen randomly.\n6. Make a score shown on the top right side. Increment if you pass pipes and don't hit them.\n7. Make randomly spaced pipes with enough space. Color them randomly as dark green or light brown or a dark gray shade.\n8. When you lose, show the best score. Make the text inside the screen. Pressing q or Esc will quit the game. Restarting is pressing SPACE again.\nThe final game should be inside a markdown section in Python. Check your code for errors and fix them before the final markdown section.<|im_end|>\n<|im_start|>assistant\n<think>\n"  \2>&1 | tee Q4_K_M_yes_samplers.txt

查看示例最终 Python 输出在此. 完整输入为:

<|im_start|>user
Create a Flappy Bird game in Python. You must include these things:
1. You must use pygame.
2. The background color should be randomly chosen and is a light shade. Start with a light blue color.
3. Pressing SPACE multiple times will accelerate the bird.
4. The bird's shape should be randomly chosen as a square, circle or triangle. The color should be randomly chosen as a dark color.
5. Place on the bottom some land colored as dark brown or yellow chosen randomly.
6. Make a score shown on the top right side. Increment if you pass pipes and don't hit them.
7. Make randomly spaced pipes with enough space. Color them randomly as dark green or light brown or a dark gray shade.
8. When you lose, show the best score. Make the text inside the screen. Pressing q or Esc will quit the game. Restarting is pressing SPACE again.
The final game should be inside a markdown section in Python. Check your code for errors and fix them before the final markdown section.<|im_end|>
<|im_start|>assistant
<think>

运行它时,我们得到一个可执行的游戏!

在这里插入图片描述


4、尝试不使用我们的修复方案:

现在尝试不使用我们的修复方法!所以移除 --samplers "top_k;top_p;min_p;temperature;dry;typ_p;xtc" 这将保存输出到 Q4_K_M_no_samplers.txt

./llama.cpp/llama-cli \--model unsloth-QwQ-32B-GGUF/QwQ-32B-Q4_K_M.gguf \--threads 32 \--ctx-size 16384 \--n-gpu-layers 99 \--seed 3407 \--prio 2 \--temp 0.6 \--repeat-penalty 1.5 \--repeat-penalty 1.1 \--dry-multiplier 0.5 \--min-p 0.1 \--top-k 40 \--top-p 0.95 \-no-cnv \--prompt "<|im_start|>user\nCreate a Flappy Bird game in Python. You must include these things:\n1. You must use pygame.\n2. The background color should be randomly chosen and is a light shade. Start with a light blue color.\n3. Pressing SPACE multiple times will accelerate the bird.\n4. The bird's shape should be randomly chosen as a square, circle or triangle. The color should be randomly chosen as a dark color.\n5. Place on the bottom some land colored as dark brown or yellow chosen randomly.\n6. Make a score shown on the top right side. Increment if you pass pipes and don't hit them.\n7. Make randomly spaced pipes with enough space. Color them randomly as dark green or light brown or a dark gray shade.\n8. When you lose, show the best score. Make the text inside the screen. Pressing q or Esc will quit the game. Restarting is pressing SPACE again.\nThe final game should be inside a markdown section in Python. Check your code for errors and fix them before the final markdown section.<|im_end|>\n<|im_start|>assistant\n<think>\n"  \2>&1 | tee Q4_K_M_no_samplers.txt

您将遇到一些循环问题,但 问题性的不正确 Python 语法 和许多其他问题。例如下面看起来是正确的,但实际上是错误的!

即第39行 pipes.clear() 抛出错误:NameError: name 'pipes' is not defined. 你忘记导入 ‘pipes’ 了吗?请参考我们的示例,它展示了完全 错误的结果在这里。

如果您使用 --repeat-penalty 1.5,情况会更糟,并且更加明显,实际上语法完全错误。

你可能想知道,也许是 Q4_K_M?B16 即全精度应该可以正常工作吧?不正确 - 如果我们不在使用重复惩罚时使用我们的修复方案 --samplers "top_k;top_p;min_p;temperature;dry;typ_p;xtc",输出又会失败。


💡 <think> 令牌未显示?

有些人报告说,由于在聊天模板中默认添加了 <think>,一些系统无法正确输出思维跟踪。您将需要手动编辑 Jinja 模板,从:

{%- if tools %} {{- '<|im_start|>system\n' }} {%- if messages[0]['role'] == 'system' %} {{- messages[0]['content'] }} {%- else %} {{- '' }} {%- endif %} {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }} {%- for tool in tools %} {{- "\n" }} {{- tool | tojson }} {%- endfor %} {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }} {%- else %} {%- if messages[0]['role'] == 'system' %} {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }} {%- endif %} {%- endif %} {%- for message in messages %} {%- if (message.role == "user") or (message.role == "system" and not loop.first) %} {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }} {%- elif message.role == "assistant" and not message.tool_calls %} {%- set content = message.content.split('</think>')[-1].lstrip('\n') %} {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }} {%- elif message.role == "assistant" %} {%- set content = message.content.split('</think>')[-1].lstrip('\n') %} {{- '<|im_start|>' + message.role }} {%- if message.content %} {{- '\n' + content }} {%- endif %} {%- for tool_call in message.tool_calls %} {%- if tool_call.function is defined %} {%- set tool_call = tool_call.function %} {%- endif %} {{- '\n<tool_call>\n{"name": "' }} {{- tool_call.name }} {{- '", "arguments": ' }} {{- tool_call.arguments | tojson }} {{- '}\n</tool_call>' }} {%- endfor %} {{- '<|im_end|>\n' }} {%- elif message.role == "tool" %} {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %} {{- '<|im_start|>user' }} {%- endif %} {{- '\n<tool_response>\n' }} {{- message.content }} {{- '\n</tool_response>' }} {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %} {{- '<|im_end|>\n' }} {%- endif %} {%- endif %} {%- endfor %} {%- if add_generation_prompt %} {{- '<|im_start|>assistant\n<think>\n' }} {%- endif %}

要将以下英文 markdown 文档内容翻译成中文,并保留原本的 markdown 格式,斜体字不翻译,代码也不翻译,内容如下:

通过删除末尾的 <think>\n 来将其移动到另一个位置。现在模型在推理时将需要手动添加 <think>\n,这可能并不总是成功。

DeepSeek 还编辑了所有模型,以默认添加一个 <think> 令牌来强制模型进入推理模式。

因此,将 {%- if add_generation_prompt %}{{- '<|im_start|>assistant\n<think>\n' }} {%- endif %} 更改为 {%- if add_generation_prompt %} {{- '<|im_start|>assistant\n' }} {%- endif %},即删除 <think>\n

查看移除 <think> 部分(此处)的完整 Jinga 模板 在此.


🧪 实验结果 + 备注

我们首先想的是:

1、QwQ的上下文长度并非原生128K,而是32K,通过YaRN扩展实现。我们尝试了覆盖llama.cpp中的YaRN处理,但没有任何变化。例如,在QwQ-32B的readme文件中我们看到以下内容:

{...,"rope_scaling": {"factor": 4.0,"original_max_position_embeddings": 32768,"type": "yarn"}
}

2、我们也认为可能是 RMS Layernorm 的 epsilon 值不正确——不是 1e-5,而是可能是 1e-6。例如 这个 有 rms_norm_eps=1e-06,而 这个 有 rms_norm_eps=1e-05。我们也将它覆盖了,但并没有起作用:

3、我们还测试了在 llama.cpp 和普通 Transformers 之间分词器 ID 是否匹配,归功于 @kalomaze。它们匹配了,所以这并非罪魁祸首。

我们提供了我们的实验结果在 我们的文档 中。


🦥 动态 4 位量化

我们还上传了动态 4 位量化,与简单的 4 位量化相比提高了准确性!我们将动态 4 位量化上传到了这里。下面附上了 QwQ 量化误差分析图,包括激活和权重量化误差:
自vLLM 0.7.3(2025年2月20日)起,vLLM现在支持加载Unsloth动态4位量化!


在这里插入图片描述


在这里插入图片描述


🛠️ 微调 QwQ-32B


QwQ-32B 调优在不到 20GB 的 VRAM 中与 Unsloth 兼容!它还快了 2 倍,并且默认使用我们动态的 4 位量化来提升 QLoRA 的准确性。
由于模型大小,很遗憾模型无法适应免费的Google Colab 16GB VRAM GPU,因此您需要至少20GB VRAM的GPU。要查看我们其他笔记本和模型上传,请访问我们的文档。


性能基准测试

我们使用Alpaca数据集进行了测试,批大小为2,梯度累积步骤为4,排名=32,并在所有线性层(q, k, v, o, gate, up, down)上应用了QLoRA。


2025-03-09(日)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/72826.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Jump( 2015-2016 ACM-ICPC Northeastern European Regional Contest (NEERC 15). )

Jump( 2015-2016 ACM-ICPC Northeastern European Regional Contest (NEERC 15). ) 题目大意&#xff1a; 在这个交互式问题中&#xff0c;你需要通过查询系统&#xff0c;逐步找出隐藏的位字符串 S。给定一个偶数 n&#xff0c;表示目标位字符串 S 的长度&#xff0c;你需要通…

Leetcode 刷题记录 06 —— 矩阵

本系列为笔者的 Leetcode 刷题记录&#xff0c;顺序为 Hot 100 题官方顺序&#xff0c;根据标签命名&#xff0c;记录笔者总结的做题思路&#xff0c;附部分代码解释和疑问解答。 目录 01 矩阵置零 方法一&#xff1a;标记数组 方法二&#xff1a;两个标记变量 02 螺旋矩阵…

Java【网络原理】(3)网络编程续

目录 1.前言 2.正文 2.1ServerSocket类 2.2Socket类 2.3Tcp回显服务器 2.3.1TcpEchoServer 2.3.2TcpEchoClient 3.小结 1.前言 哈喽大家好&#xff0c;今天继续进行计算机网络的初阶学习&#xff0c;今天学习的是tcp回显服务器的实现&#xff0c;正文开始 2.正文 在…

C++11新特性 8.final关键字、override关键字

一.final 用法&#xff1a; 1.修饰函数 只能修饰虚函数&#xff0c;阻止子类重写这个函数&#xff0c;final关键字写在函数名的后面。 即该虚函数不可以再被重写。 注意&#xff1a;一般不会在基类中使用&#xff0c;不然没有意义&#xff0c;因为只能修饰虚函数。 2.修饰…

Python实现网络通信:Socket模块与TCP/IP协议全解析

Langchain系列文章目录 01-玩转LangChain&#xff1a;从模型调用到Prompt模板与输出解析的完整指南 02-玩转 LangChain Memory 模块&#xff1a;四种记忆类型详解及应用场景全覆盖 03-全面掌握 LangChain&#xff1a;从核心链条构建到动态任务分配的实战指南 04-玩转 LangChai…

click house扩容方案

《ClickHouse扩容方案解析》 当我们谈论数据库的时候&#xff0c;尤其是像ClickHouse这样专为处理大规模数据分析而设计的列式存储数据库时&#xff0c;扩容是一个不可避免的话题。随着数据量的增长和查询复杂度的提升&#xff0c;原有的硬件资源可能不足以支撑高效的查询响应…

【AGI】智谱开源2025:一场AI技术民主化的革命正在到来

智谱开源2025&#xff1a;一场AI技术民主化的革命正在到来 引言&#xff1a;开源&#xff0c;一场技术平权的革命一、CogView4&#xff1a;中文AI生成的里程碑1. 破解汉字生成的“AI魔咒”2. 开源协议与生态赋能 二、AutoGLM&#xff1a;人机交互的范式跃迁1. 自然语言驱动的跨…

java8中young gc的垃圾回收器选型,您了解嘛

在 Java 8 的 Young GC&#xff08;新生代垃圾回收&#xff09;场景中&#xff0c;对于 ToC的场景&#xff0c;即需要尽可能减少垃圾回收停顿时间以满足业务响应要求的场景&#xff0c;以下几种收集器各有特点&#xff0c;通常 Parnew和 G1 young表现较为出色&#xff0c;下面详…

【数学 矩阵快速幂】P7108 移花接木|普及+

本文涉及知识点 数学 移花接木 题目背景 遥远的圣地生长着一棵不为人知的灵树&#xff0c;或有万山之高。 但有一日&#xff0c;藏匿于根系的腐朽力量爆发&#xff0c;灵树已无法支撑往日屹立冲天的高度。 题目描述 灵树最初的形态可以看作一棵高度为 10 10 10 10 {10}…

2025-03-09 学习记录--C/C++-PTA 习题10-7 十进制转换二进制

合抱之木&#xff0c;生于毫末&#xff1b;九层之台&#xff0c;起于累土&#xff1b;千里之行&#xff0c;始于足下。&#x1f4aa;&#x1f3fb; 一、题目描述 ⭐️ 裁判测试程序样例&#xff1a; #include <stdio.h>void dectobin( int n );int main() {int n;scanf(…

前端 | CORS 跨域问题解决

问题&#xff1a;Access to fetch at http://localhost:3000/save from origin http://localhost:5174 has been blocked by CORS policy: Response to preflight request doesnt pass access control check: No Access-Control-Allow-Origin header is present on the request…

fastapi房产销售系统

说明&#xff1a; 我希望用fastapi写几个接口&#xff0c;查询房产交易系统的几条数据&#xff0c;然后在postman里面测试 查询客户所有预约记录&#xff08;含房源信息&#xff09;需要对应销售经理查询客户所有订单&#xff08;含房源信息&#xff09;统计销售经理名下所有房…

导轨式ARM工业控制器:组态软件平台的“神经中枢”

工业自动化领域&#xff0c;组态软件平台扮演着至关重要的角色。它不仅是工业控制系统的“大脑”&#xff0c;更是实现智能化、高效化生产的关键工具。而作为组态软件平台的硬件支撑&#xff0c;导轨式ARM工控机&#xff08;以下简称“工控机”&#xff09;凭借其紧凑的设计、强…

每日一题——矩阵置零问题的原地算法

矩阵置零问题的原地算法 问题描述示例约束条件进阶要求 问题分析难点分析解题思路 代码实现代码说明 测试用例测试用例 1测试用例 2测试用例 3 总结 问题描述 给定一个 m x n 的矩阵&#xff0c;如果矩阵中的某个元素为 0&#xff0c;则需要将其所在的行和列的所有元素都置为 …

Springboot中的@Value注解:用法与潜在问题探索

在Spring Boot开发中&#xff0c;有个非常实用的注解&#xff0c;那就是Value&#xff01;它可以帮助我们轻松地从配置文件中读取属性值。想象一下&#xff0c;在应用程序中管理各种配置&#xff0c;比如数据库连接信息、服务URL或者API密钥等&#xff0c;使用Value是多么方便呀…

C++后端服务器开发技术栈有哪些?有哪些资源或开源库拿来用?

一、 C后台服务器开发是一个涉及多方面技术选择的复杂领域&#xff0c;特别是在高性能、高并发的场景下。以下是C后台服务器开发的一种常见技术路线&#xff0c;涵盖了从基础到高级的技术栈。 1. 基础技术栈 C标准库 C11/C14/C17/C20&#xff1a;使用现代C特性&#xff0c;如…

25年携程校招社招求职能力北森测评材料计算部分:备考要点与误区解析

在求职过程中&#xff0c;能力测评是筛选候选人的重要环节之一。对于携程这样的知名企业&#xff0c;其能力测评中的材料计算部分尤为关键。许多求职者在备考时容易陷入误区&#xff0c;导致在考试中表现不佳。本文将深入解析材料计算部分的实际考察方向&#xff0c;并提供针对…

golang进阶知识专项-理解值传递

在 Go 语言中&#xff0c;所有函数的参数传递都是值传递&#xff08;Pass by Value&#xff09;。当你将一个变量作为参数传递给函数时&#xff0c;实际上传递的是该变量的副本&#xff0c;而不是变量本身。理解这一点对于避免常见的编程错误至关重要。根据不同的类型&#xff…

RuoYi框架添加自己的模块(学生管理系统CRUD)

RuoYi框架添加自己的模块&#xff08;学生管理系统&#xff09; 框架顺利运行 首先肯定要顺利运行框架了&#xff0c;这个我不多说了 设计数据库表 在ry数据库中添加表tb_student 表字段如图所示 如图所示 注意id字段是自增的 注释部分是后面成功后前端要展示的部分 导入…

中级网络工程师面试题参考示例(1)

一、基础理论 1. OSI七层模型与TCP/IP四层模型的区别是什么&#xff1f;请举例说明第三层&#xff08;网络层&#xff09;和第四层&#xff08;传输层&#xff09;的核心协议。 参考答案&#xff1a; OSI七层模型分为物理层、数据链路层、网络层、传输层、会话层、表示层、应用…