高效運行 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.pswp.cn/diannao/72826.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/72826.shtml
英文地址,請注明出處:http://en.pswp.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七層模型分為物理層、數據鏈路層、網絡層、傳輸層、會話層、表示層、應用…