高效运行 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(日)

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

R 语言科研绘图 --- 直方图-汇总

在发表科研论文的过程中&#xff0c;科研绘图是必不可少的&#xff0c;一张好看的图形会是文章很大的加分项。 为了便于使用&#xff0c;本系列文章介绍的所有绘图都已收录到了 sciRplot 项目中&#xff0c;获取方式&#xff1a; R 语言科研绘图模板 --- sciRplothttps://mp.…

1.5.1 掌握Scala内建控制结构 - 条件表达式

本文介绍了 Scala 中条件表达式的使用及其在实际任务中的应用。条件表达式的语法为 if (条件) 值1 else 值2&#xff0c;其结果类型取决于值1和值2的类型。如果类型相同&#xff0c;结果类型与它们相同&#xff1b;如果不同&#xff0c;则结果类型为 Any。通过两个任务展示了条…

Linux rootfs:如何开机就自动添加某个用户?

前言 项目开发需求&#xff0c;需要开机后就自动创建某个用户密码 厂家提供的sdk&#xff0c;只有adduser命令&#xff0c; 该命令添加用户时&#xff0c;会有终端交互&#xff0c; 需要手动输入2次密码&#xff0c; 所以无法通过简单脚本方式创建。 要实现自动填充密码&…

计算机三级网络技术知识点汇总【7】

第七章 路由器配置及使用 1. 路由器的基础知识 1.1 路由器的基本概念 路由器是工作在网络层的设备&#xff0c;负责将数据分组从源端主机经最佳路径传送到目的端主机&#xff0c;实现在网络层的互联。路由器工作在 TCP/IP 网络模型的网络层&#xff0c;对应于 OSI 网络参考模…

Compounding Geometric Operations for Knowledge Graph Completion(论文笔记)

CCF等级&#xff1a;A 发布时间&#xff1a;2023年7月 25年3月10日交 一、简介 使用知识图谱嵌入模型&#xff0c;将三元组&#xff08;h,r,t&#xff09;中关系 r 转化为平移、旋转、缩放矩阵对头节点以及尾节点进行运算&#xff0c;判定三元组的真实性。 二、原理 1.整…

mac系统安装

目录 准备工作 一、安装虚拟机 二、解锁系统 三、安装系统 四、部署系统 五、安装VMware Tools(选做) 为什么要安装VMware Tools,这是啥玩意? 六、配置共享文件夹(选做) 为什么要共享文件夹? 注意事项: 七、安装完成 准备工作 一、安装说明: 本教程分为7个部…

DNASimCLR:一种基于对比学习的基因序列数据分类的深度学习方法

摘要 DNASimCLR利用卷积神经网络和基于对比学习的SimCLR框架&#xff0c;从不同的微生物基因序列中提取复杂的特征。在包含宏基因组和病毒基因序列的两个经典的大规模未标记数据集上进行了预训练。后续的分类任务通过使用先前获得的模型对预训练的模型进行微调来完成。我们的实…

Ae 效果详解:VR 旋转球面

Ae菜单&#xff1a;效果/沉浸式视频/VR 旋转球面 Immersive Video/VR Rotate Sphere VR 旋转球面 VR Rotate Sphere效果用于对 VR 视频进行三轴旋转&#xff0c;以调整视频的视角方向。可用于校正拍摄时的角度偏差&#xff0c;或者根据创意需求模拟摄像机旋转。 本效果适用于所…

南开提出1Prompt1Story,无需训练,可通过单个连接提示实现一致的文本到图像生成。

&#xff08;1Prompt1Story&#xff09;是一种无训练的文本到图像生成方法&#xff0c;通过整合多个提示为一个长句子&#xff0c;并结合奇异值重加权&#xff08;SVR&#xff09;和身份保持交叉注意力&#xff08;IPCA&#xff09;技术&#xff0c;解决了生成图像中身份不一致…

Python----数据可视化(Seaborn二:绘图一)

常见方法 barplot方法 单独绘制条形图 catplot方法 可以条形图、散点图、盒图、小提亲图、等 countplot方法 统计数量 一、柱状图 seaborn.barplot(dataNone, xNone, yNone, hueNone, colorNone, paletteNone) 函数描述data用于绘图的数据集。x用于绘制长格式数据的输入。…

只音 1.2.0 |纯净无广告,畅听全网音乐,支持无损下载和批量下载

只音是一款全网音乐一网打尽的听歌利器&#xff0c;无需登录即可搜索抖音、网易云、QQ音乐等平台资源&#xff0c;无损音质直连播放。内置智能推荐算法&#xff0c;每日更新热门榜单与个性化歌单&#xff0c;轻松发现小众优质音乐。支持批量下载功能&#xff0c;一次性打包30首…

Python从入门到精通1:FastAPI

引言 在现代 Web 开发中&#xff0c;API 是前后端分离架构的核心。FastAPI 凭借其高性能、简洁的语法和自动文档生成功能&#xff0c;成为 Python 开发者的首选框架。本文将从零开始&#xff0c;详细讲解 FastAPI 的核心概念、安装配置、路由设计、请求处理以及实际应用案例&a…

Service与Ingress:如何将你的应用暴露给世界

引言&#xff1a;从“内部通讯”到“对外开放” 想象Kubernetes集群是一座繁忙的办公楼&#xff0c;每个Pod&#xff08;容器&#xff09;是楼内的员工。 Service 就像前台的接待员&#xff0c;负责将外部电话&#xff08;请求&#xff09;转接到正确的员工&#xff08;Pod&am…

【Linux学习篇】--开发工具第一期

目录 1. Linux编辑器的使用--vim使用 1.1 vim的基本概念 1.2 vim基本操作 1.3 vim正常模式&#xff08;指令模式&#xff09;命令集 1.4 vim末行模式命令集 1.5 vim配置 2. Linux编译器-gcc/g使用 2.1 背景知识 2.2 gcc如何完成 2.3 gcc选择项 1. Linux编…

Elastic:AI 会开始取代网络安全工作吗?

作者&#xff1a;来自 Elastic Joe DeFever 不会&#xff0c;但它正在从根本上改变这些工作。 生成式 AI (GenAI) 正迅速成为日常安全工作流程中的一个重要组成部分。那么&#xff0c;它是合作伙伴还是竞争对手&#xff1f; GenAI 技术在安全堆栈几乎每个方面的广泛应用&#…

Windows 11 IoT 企业版 LTSC 2025 特制适度 22635.5025

文件: Windows 11 IoT 企业版 LTSC 2025 特制适度 22635.5025 install.esd 大小: 2.57G&#xff08;2768694310 字节&#xff09; 修改时间: 2025年3月9日, 星期日, 11 : 40 : 15 MD5: BFCB23BC2F78CA9243FFA68D5DDDDFC1 SHA1: C4D8BBF8B8D8E0E8E49DE5E9CC8D7F77385A745A CRC32…

Lab18_ SQL injection with filter bypass via XML encoding

文章目录 前言&#xff1a;进入实验室构造 payload 前言&#xff1a; 实验室标题为&#xff1a; 通关 XML 编码绕过过滤器的 SQL 注入 简介&#xff1a; 此实验室的库存检查功能中存在 SQL 注入漏洞。查询结果在应用程序的响应中返回&#xff0c;因此您可以使用 UNION 攻击…

kali虚拟机登录页面发癫 大写锁定输入不了密码

不知道怎么了 总是发癫 重启切换太麻烦了 还有时候不成功 kali其实可以开启虚拟键盘 如下 就解决的 发癫kali 发癫 发癫

【汇编语言】单片机程序执行过程

一、任务需求 指示灯LED4闪烁&#xff0c;亮0.5秒&#xff0c;灭0.5秒&#xff0c;无限循环 二、针对硬件的编程 1、确定原理图2、确定硬件的物理关系 三、设计步骤 1.用自己的语言描述工作流程 1.1指示灯LED4亮1.2延时0.5秒1.3指示灯LED4灭1.4延时0.5秒1.5跳转到1.1步 …

【Linux篇】调试器-gdb/cgdb使用

&#x1f4cc; 个人主页&#xff1a; 孙同学_ &#x1f527; 文章专栏&#xff1a;Liunx &#x1f4a1; 关注我&#xff0c;分享经验&#xff0c;助你少走弯路&#xff01; 文章目录 1. 前言2.关于gdb2.1 快速认识gdb2.2 安装cgdb2.3 gdb命令2.4 调试 & 断点 3.常见技巧3.…