# QwQ-32B: 効果的な実行方法

QwenはQwQ-32Bをリリースしました - 多くのベンチマークでDeepSeek-R1と同等の性能を持つ推論モデルです、 [ベンチマーク](https://qwenlm.github.io/blog/qwq-32b/)。しかし、人々は経験しています **無限生成**, **多くの反復**、\<think>トークンの問題やファインチューニングの問題。私たちはこのガイドがほとんどの問題のデバッグと修正に役立つことを願っています！

{% hint style="info" %}
バグ修正を適用した私たちのモデルアップロードは、ファインチューニング、vLLM、Transformersでうまく機能します。llama.cppやllama.cppをバックエンドに使用するエンジンを使っている場合は、私たちの [ここでの手順](#tutorial-how-to-run-qwq-32b) に従って無限生成を修正してください。
{% endhint %}

**バグ修正を適用したUnsloth QwQ-32Bのアップロード：**

| [GGUF](https://huggingface.co/unsloth/QwQ-32B-GGUF) | [動的4ビット](https://huggingface.co/unsloth/QwQ-32B-unsloth-bnb-4bit) | [BnB 4ビット](https://huggingface.co/unsloth/QwQ-32B-bnb-4bit) | [16ビット](https://huggingface.co/unsloth/QwQ-32B) |
| --------------------------------------------------- | ----------------------------------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------- |

## :gear: 公式推奨設定

によれば [Qwen](https://huggingface.co/Qwen/QwQ-32B)、これらが推論の推奨設定です：

* 温度（Temperature）0.6
* Top\_Kを40に（または20〜40）
* Min\_Pを0.00（オプション、但し0.01がよく機能します。llama.cppのデフォルトは0.1）
* Top\_Pを0.95に
* 繰り返しペナルティを1.0に。（llama.cppおよびtransformersでは1.0は無効を意味します）
* チャットテンプレート： `<|im_start|>user\nPythonでFlappy Birdゲームを作成してください.<|im_end|>\n<|im_start|>assistant\n<think>\n`

{% hint style="warning" %}
`llama.cpp` 使用 `min_p = 0.1`がデフォルトであり、問題を引き起こす可能性があります。強制的に0.0にしてください。
{% endhint %}

## :thumbsup: llama.cppの推奨設定

私たちは多くの人が `繰り返しペナルティ` を1.0より大きく設定しているのを確認しました。例えば1.1〜1.5です。これは実際にはllama.cppのサンプリング機構と干渉します。繰り返しペナルティの目的は繰り返し生成を罰することですが、期待通りに機能しないことがわかりました。

オフにすること（例えば1.0に設定する） `繰り返しペナルティ` ことも機能しますが、無限生成を罰するために有用であると見なしました。

これを使用するには、llama.cppでサンプラーの並び順を適用する前に編集する必要があることがわかりました、 `繰り返しペナルティ`さもなければ無限生成が発生します。したがってこれを追加してください：

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

デフォルトでは、llama.cppは次の順序を使用します：

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

私たちは基本的にtemperatureとdryを入れ替え、min\_pを前に移動します。これは次の順序でサンプラーを適用することを意味します：

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

それでも問題が発生する場合は、`--repeat-penaltyを1.0から1.2または1.3に増やすことができます。`

感謝： [@krist486](https://x.com/krist486/status/1897885598196654180) がllama.cppのサンプリングに関する方向性を教えてくれました。

## :sunny: Dry繰り返しペナルティ

私たちは `dryペナルティ` の使用を調査しました（推奨されているように） <https://github.com/ggml-org/llama.cpp/blob/master/examples/main/README.md> 0.8の値を使用しましたが、実際にはこれは **むしろ特にコーディングに対して構文の問題を引き起こす**ことがわかりました。もしそれでも問題が発生する場合は、`dryペナルティを0.8に増やすことができます。`

並び替えたサンプリング順を利用することも、もし使うことを決めた場合に役立ちます、 `dryペナルティ`.

## :llama: チュートリアル：OllamaでQwQ-32Bを実行する方法

1. Ollamaで実行する `をインストールしてください` まだインストールしていない場合は！

```bash
apt-get update
こちらを参照してください
apt-get install pciutils -y
```

2. モデルを実行してください！失敗した場合は別のターミナルで `モデルを実行してください！失敗した場合は別のターミナルで`を呼び出すことができることに注意してください！私たちはすべての修正と推奨パラメータ（temperature、min\_pなど）を `param` params

```bash
ollama run hf.co/unsloth/QwQ-32B-GGUF:Q4_K_M
```

## 📖 チュートリアル：llama.cppでQwQ-32Bを実行する方法

1. 最新の `llama.cpp` を [GitHubで入手してください](https://github.com/ggml-org/llama.cpp)。以下のビルド手順にも従うことができます。を変更してください `-DGGML_CUDA=ON` に `-DGGML_CUDA=OFF` GPUを持っていない場合やCPUで推論したい場合は **Apple Mac / Metalデバイスの場合**、次を設定してください `-DGGML_CUDA=OFF` その後通常通り続行してください — Metalサポートはデフォルトで有効です。

```bash
apt-get update
apt-get install pciutils build-essential cmake curl libcurl4-openssl-dev -y
git clone https://github.com/ggml-org/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. モデルをダウンロードするには（をインストールした後） `モデルをダウンロードするには（` ）。Q4\_K\_Mや他の量子化バージョン（BF16フル精度など）を選択できます。その他のバージョンは： <https://huggingface.co/unsloth/QwQ-32B-GGUF>

```python
# !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*"], # Q4_K_M用
)
```

3. UnslothのFlappy Birdテストを実行すると、出力が次に保存されます： `Q4_K_M_yes_samplers.txt`
4. 編集 `次の` --threads 32 `はCPUスレッドの数、` --ctx-size 16384 `--n-gpu-layers 99` --n-gpu-layers 2
5. 私たちは使用します `--repeat-penalty 1.1` と `--dry-multiplier 0.5` これは調整可能です。

```bash
export LLAMA_CACHE="unsloth/GLM-4.7-GGUF"
    --model unsloth-QwQ-32B-GGUF/QwQ-32B-Q4_K_M.gguf \
    --threads 32 \
    --jinja \
    --n-gpu-layers 99 \
    --model unsloth/GLM-4.7-GGUF/UD-Q2_K_XL/GLM-4.7-UD-Q2_K_XL-00001-of-00003.gguf \
    --prio 2 \
    --temp 0.6 \
    --repeat-penalty 1.1 \
    --dry-multiplier 0.5 \
    --min-p 0.01 \
    --top-k 40 \
    --temp 1.0 \
    -no-cnv \
    --samplers "top_k;top_p;min_p;temperature;dry;typ_p;xtc" \
    --prompt "<|im_start|>user\nPythonでFlappy Birdゲームを作成してください。次のことを必ず含めてください：\n1. pygameを使用すること。\n2. 背景色はランダムに選ばれ、明るい色合いにすること。最初は薄い青色から始めること。\n3. SPACEを複数回押すと鳥が加速すること。\n4. 鳥の形は正方形、円、三角形のいずれかをランダムに選ぶこと。色は暗い色からランダムに選ぶこと。\n5. 下部に暗い茶色または黄色のいずれかをランダムに選んだ土地を配置すること。\n6. スコアを右上に表示すること。パイプを通過して当たらなければスコアを増やすこと。\n7. 十分な間隔のランダムな間隔でパイプを作ること。色は暗い緑、淡い茶色、または暗い灰色のいずれかをランダムに選ぶこと。\n8. ゲームオーバー時に最高スコアを表示すること。テキストは画面内に表示すること。qまたはEscを押すとゲームを終了すること。再開は再度SPACEを押すこと。\n最終ゲームはPythonのマークダウンセクション内に含めること。最終マークダウンセクションの前にコードのエラーを確認して修正してください。<|im_end|>\n<|im_start|>assistant\n<think>\n"  \
        2>&1 | tee Q4_K_M_yes_samplers.txt
```

私たちの <https://unsloth.ai/blog/deepseekr1-dynamic> 1.58bitブログからの完全な入力は：

```
<|im_start|>user
Heptagon
1. pygame を使用すること。
2. 背景色はランダムに選択され、淡い色合いにすること。最初は薄い青色から始めること。
3. SPACE を複数回押すと鳥が加速すること。
4. 鳥の形状はランダムに四角形、円、三角形のいずれかにし、色はランダムに暗い色にすること。
5. 画面下部に、ランダムに選ばれた暗い茶色または黄色の土地を配置すること。
6. スコアを右上に表示すること。パイプを通過して当たらなかった場合に増加させること。
7. 十分な間隔のランダムな間隔でパイプを配置すること。色はランダムに濃い緑、薄い茶色、または暗い灰色のいずれかにすること。
8. ゲームオーバー時にベストスコアを表示すること。テキストは画面内に表示すること。q または Esc を押すとゲームを終了すること。再開は再び SPACE を押すこと。
最終ゲームはPythonのマークダウンセクション内に含めること。最終マークダウンセクションの前にコードのエラーを確認して修正してください。<|im_end|>
<|im_start|>assistant
<think>
```

思考部分を除去した後の最終Python出力の始まりと終わり：

```python
import pygame
import random
import sys

pygame.init()
### 続く

class Bird:
    def __init__(self):
        ### 続く

def main():
    best_score = 0
    current_score = 0
    game_over = False
    pipes = []
    first_time = True  # 初回プレイを追跡

    # 初期設定
    background_color = (173, 216, 230)  # 最初は薄い青
    land_color = random.choice(land_colors)
    bird = Bird()

    while True:
        for event in pygame.event.get():
            ### 続く

        if not game_over:
            # 鳥とパイプを更新
            bird.update()
            ### 続く

        # 描画
        ### 続く
        pygame.display.flip()
        clock.tick(60)

if __name__ == "__main__":
    main()
```

<details>

<summary>最終的な完全なPython出力（思考部分を除去）：</summary>

{% code fullWidth="false" %}

```python
import pygame
import random
import sys

pygame.init()
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Flappy Bird Clone")
clock = pygame.time.Clock()

# 色
pipe_colors = [(0, 100, 0), (210, 180, 140), (50, 50, 50)]
land_colors = [(139, 69, 19), (255, 255, 0)]

# ゲーム定数
GRAVITY = 0.5
PIPE_SPEED = 5
BIRD_SIZE = 30
LAND_HEIGHT = 50
PIPE_WIDTH = 50
PIPE_GAP = 150

class Bird:
    def __init__(self):
        self.x = WIDTH // 2
        self.y = HEIGHT // 2
        self.velocity = 0
        self.shape = random.choice(['square', 'circle', 'triangle'])
        self.color = (random.randint(0, 100), random.randint(0, 100), random.randint(0, 100))
        self.rect = pygame.Rect(self.x - BIRD_SIZE//2, self.y - BIRD_SIZE//2, BIRD_SIZE, BIRD_SIZE)
    
    def update(self):
        self.velocity += GRAVITY
        self.y += self.velocity
        self.rect.y = self.y - BIRD_SIZE//2
        self.rect.x = self.x - BIRD_SIZE//2  # xを中央に保つ
    
    def draw(self):
        if self.shape == 'square':
            pygame.draw.rect(screen, self.color, self.rect)
        elif self.shape == 'circle':
            pygame.draw.circle(screen, self.color, (self.rect.centerx, self.rect.centery), BIRD_SIZE//2)
        elif self.shape == 'triangle':
            points = [
                (self.rect.centerx, self.rect.top),
                (self.rect.left, self.rect.bottom),
                (self.rect.right, self.rect.bottom)
            ]
            pygame.draw.polygon(screen, self.color, points)

def spawn_pipe():
    pipe_x = WIDTH
    top_height = random.randint(50, HEIGHT - PIPE_GAP - LAND_HEIGHT)
    rect_top = pygame.Rect(pipe_x, 0, PIPE_WIDTH, top_height)
    bottom_y = top_height + PIPE_GAP
    bottom_height = (HEIGHT - LAND_HEIGHT) - bottom_y
    rect_bottom = pygame.Rect(pipe_x, bottom_y, PIPE_WIDTH, bottom_height)
    color = random.choice(pipe_colors)
    return {
        'rect_top': rect_top,
        'rect_bottom': rect_bottom,
        'color': color,
        'scored': False
    }

def main():
    best_score = 0
    current_score = 0
    game_over = False
    pipes = []
    first_time = True  # 初回プレイを追跡

    # 初期設定
    background_color = (173, 216, 230)  # 最初は薄い青
    land_color = random.choice(land_colors)
    bird = Bird()

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE or event.key == pygame.K_q:
                    pygame.quit()
                    sys.exit()
                if event.key == pygame.K_SPACE:
                    if game_over:
                        # ゲームをリセット
                        bird = Bird()
                        pipes.clear()
                        current_score = 0
                        if first_time:
                            # 初回のゲームオーバー後の最初の再開
                            background_color = (random.randint(200, 255), random.randint(200, 255), random.randint(200, 255))
                            first_time = False
                        out = MAP_FN[fx](**json.loads(args))
                            background_color = (random.randint(200, 255), random.randint(200, 255), random.randint(200, 255))
                        land_color = random.choice(land_colors)
                        game_over = False
                    out = MAP_FN[fx](**json.loads(args))
                        # 鳥をジャンプさせる
                        bird.velocity = -15  # 初期の上向き速度

        if not game_over:
            # 鳥とパイプを更新
            bird.update()

            # パイプを左に移動
            remove_pipes = []
            for pipe in pipes:
                pipe['rect_top'].x -= PIPE_SPEED
                pipe['rect_bottom'].x -= PIPE_SPEED
                # 鳥がパイプを通過したか確認
                if not pipe['scored'] and bird.rect.x > pipe['rect_top'].right:
                    current_score += 1
                    pipe['scored'] = True
                # パイプが画面外か確認
                if pipe['rect_top'].right < 0:
                    remove_pipes.append(pipe)
            # 画面外のパイプを削除
            for p in remove_pipes:
                pipes.remove(p)

            # 必要なら新しいパイプを生成
            if not pipes or pipes[-1]['rect_top'].x < WIDTH - 200:
                pipes.append(spawn_pipe())

            # 衝突判定
            land_rect = pygame.Rect(0, HEIGHT - LAND_HEIGHT, WIDTH, LAND_HEIGHT)
            bird_rect = bird.rect
            # パイプを確認
            for pipe in pipes:
                if bird_rect.colliderect(pipe['rect_top']) or bird_rect.colliderect(pipe['rect_bottom']):
                    game_over = True
                    break
            # 地面と上端を確認
            if bird_rect.bottom >= land_rect.top or bird_rect.top <= 0:
                game_over = True

            if game_over:
                if current_score > best_score:
                    best_score = current_score

        # 描画
        screen.fill(background_color)
        # パイプを描画
        for pipe in pipes:
            pygame.draw.rect(screen, pipe['color'], pipe['rect_top'])
            pygame.draw.rect(screen, pipe['color'], pipe['rect_bottom'])
        # 地面を描画
        pygame.draw.rect(screen, land_color, (0, HEIGHT - LAND_HEIGHT, WIDTH, LAND_HEIGHT))
        # 鳥を描画
        bird.draw()
        # スコアを描画
        font = pygame.font.SysFont(None, 36)
        score_text = font.render(f'Score: {current_score}', True, (0, 0, 0))
        screen.blit(score_text, (WIDTH - 150, 10))
        # ゲームオーバー画面
        if game_over:
            over_text = font.render('Game Over!', True, (255, 0, 0))
            best_text = font.render(f'Best: {best_score}', True, (255, 0, 0))
            restart_text = font.render('Press SPACE to restart', True, (255, 0, 0))
            screen.blit(over_text, (WIDTH//2 - 70, HEIGHT//2 - 30))
            screen.blit(best_text, (WIDTH//2 - 50, HEIGHT//2 + 10))
            screen.blit(restart_text, (WIDTH//2 - 100, HEIGHT//2 + 50))
        
        pygame.display.flip()
        clock.tick(60)

if __name__ == "__main__":
    main()
```

{% endcode %}

</details>

6. 実行すると、実行可能なゲームが得られます！

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-1740ecd246c7f62c363bc0ba1e0f1099b2f9b2a4%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

7. 今度は私たちの修正なしで同じことを試してみてください！ つまり削除します `--samplers "top_k;top_p;min_p;temperature;dry;typ_p;xtc"` これは出力を次に保存します `Q4_K_M_no_samplers.txt`

```bash
export LLAMA_CACHE="unsloth/GLM-4.7-GGUF"
    --model unsloth-QwQ-32B-GGUF/QwQ-32B-Q4_K_M.gguf \
    --threads 32 \
    --jinja \
    --n-gpu-layers 99 \
    --model unsloth/GLM-4.7-GGUF/UD-Q2_K_XL/GLM-4.7-UD-Q2_K_XL-00001-of-00003.gguf \
    --prio 2 \
    --temp 0.6 \
    --repeat-penalty 1.1 \
    --dry-multiplier 0.5 \
    --min-p 0.01 \
    --top-k 40 \
    --temp 1.0 \
    -no-cnv \
    --prompt "<|im_start|>user\nPythonでFlappy Birdゲームを作成してください。次のことを必ず含めてください：\n1. pygameを使用すること。\n2. 背景色はランダムに選ばれ、明るい色合いにすること。最初は薄い青色から始めること。\n3. SPACEを複数回押すと鳥が加速すること。\n4. 鳥の形は正方形、円、三角形のいずれかをランダムに選ぶこと。色は暗い色からランダムに選ぶこと。\n5. 下部に暗い茶色または黄色のいずれかをランダムに選んだ土地を配置すること。\n6. スコアを右上に表示すること。パイプを通過して当たらなければスコアを増やすこと。\n7. 十分な間隔のランダムな間隔でパイプを作ること。色は暗い緑、淡い茶色、または暗い灰色のいずれかをランダムに選ぶこと。\n8. ゲームオーバー時に最高スコアを表示すること。テキストは画面内に表示すること。qまたはEscを押すとゲームを終了すること。再開は再度SPACEを押すこと。\n最終ゲームはPythonのマークダウンセクション内に含めること。最終マークダウンセクションの前にコードのエラーを確認して修正してください。<|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. Did you forget to import 'pipes'?`

{% code overflow="wrap" lineNumbers="true" %}

```python
import pygame
import random

pygame.init()

# 定数
WIDTH, HEIGHT = 800, 600
GROUND_HEIGHT = 20
GRAVITY = 0.7
PIPE_SPEED = -3
BIRD_SIZE = 45
MIN_GAP = 130
MAX_GAP = 200
PIPE_COLORS = [(0, 96, 0), (205, 133, 63), (89, 97, 107)]
DARK_BROWN = (94, 72, 4)
YELLOW = (252, 228, 6)

screen = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()

def random_light_color():
    return (
        random.randint(180, 230),
        random.randint(190, 300),
        random.randint(250, 255)
    )

def reset_game():
    global bird_x, bird_y
    global pipes, score
    global background_color, land_color
    global bird_shape, bird_color

    # 鳥のプロパティ
    bird_x = WIDTH * 0.3
    bird_y = HEIGHT // 2
    bird_vel = -5  # 初期の上向き推力

    pipes.clear() ### <<< NameError: name 'pipes' is not defined. Did you forget to import 'pipes'?
```

{% endcode %}

8. もしあなたが使うなら `--repeat-penalty 1.5`、さらに悪化しより明白になり、実際に完全に間違った構文になります。

```python
import pygame
from random import randint  # 色/形/位置をランダム生成するため 
pygame.init()

# 定数:
WIDTH, HEIGHT =456 ,702   #
BACKGROUND_COLOR_LIGHTS=['lightskyblue']
GAP_SIZE=189           #

BIRD_RADIUS=3.  
PIPE_SPEED=- ( )    ? 
class Game():
def __init__(self):
        self.screen_size=( )

def reset_game_vars():
    global current_scor e
   # 0に設定しその他の初期状態。

# メインゲームループ:
while running :
     for event in pygame.event.get() : 
        if quit ... etc

pygame.quit()
print("コードは簡略化されています。時間的制約のため、完全に動作するバージョンはさらに実装が必要です。")
```

9. あなたはおそらくQ4\_K\_Mかもしれないと思っているかもしれませんか？B16、つまりフル精度は問題なく動作するはずですよね？ いいえ — 出力は再び失敗します、もし私たちの「-」の修正を使わなければ`-samplers "top_k;top_p;min_p;temperature;dry;typ_p;xtc"` Repetition Penalty（繰り返しペナルティ）を使用する場合。

## :sunrise\_over\_mountains: まだ動作しませんか？ Min\_p = 0.1、Temperature = 1.5 を試してください

Min\_pの論文によると <https://arxiv.org/pdf/2407.01082>、より創造的で多様な出力のために、もしまだ繰り返しが見られるなら、top\_pとtop\_kを無効にしてみてください！

```bash
./llama.cpp/llama-cli --model unsloth-QwQ-32B-GGUF/QwQ-32B-Q4_K_M.gguf \
    --threads 32 --n-gpu-layers 99 \
    --jinja \
    --temp 1.5 \
    --min-p 0.1 \
    --top-k 0 \
    --top-p 1.0 \
    -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"
```

別のアプローチは無効にすることです `min_p` 直接、なぜなら llama.cpp はデフォルトで使用するからです `min_p = 0.1`!

```bash
./llama.cpp/llama-cli --model unsloth-QwQ-32B-GGUF/QwQ-32B-Q4_K_M.gguf \
    --threads 32 --n-gpu-layers 99 \
    --jinja \
    --temp 0.6 \
    --min-p 0.0 \\
    --top-k 40 \
    --temp 1.0 \
    -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"
```

## :thinking: \<think> トークンは表示されない？

一部の人々は、\<think> がチャットテンプレートにデフォルトで追加されるため、一部のシステムが思考トレースを正しく出力していないと報告しています。Jinjaテンプレートを手動で次から編集する必要があります：

{% code overflow="wrap" %}

```
```

{% endcode %}

末尾のを別のものに置き換えて。 `<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`

<details>

<summary>Removedされた&#x3C;think>を含まない完全なjinjaテンプレートの部分</summary>

{% code overflow="wrap" %}

```
```

{% endcode %}

</details>

## 追加の注意事項

最初はこう考えました：

1. QwQのコンテキスト長はネイティブで128Kではなく、YaRN拡張で32Kであるのではないかと。例えばリードミーファイルで <https://huggingface.co/Qwen/QwQ-32B>、次のように見られます：

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

llama.cppのYaRN処理を上書きしようとしましたが、何も変わりませんでした。

{% code overflow="wrap" %}

```bash
--override-kv qwen2.context_length=int:131072 \
--override-kv qwen2.rope.scaling.type=str:yarn \
--override-kv qwen2.rope.scaling.factor=float:4 \
--override-kv qwen2.rope.scaling.original_context_length=int:32768 \
--override-kv qwen2.rope.scaling.attn_factor=float:1.13862943649292 \
```

{% endcode %}

2. また、RMS Layernorm の epsilon が間違っているのではないかとも考えました — 1e-5 ではなく 1e-6 かもしれません。例えば [これ](https://huggingface.co/Qwen/Qwen2.5-32B-Instruct/blob/main/config.json) は持っています `rms_norm_eps=1e-06`、一方で [これ](https://huggingface.co/Qwen/Qwen2.5-32B/blob/main/config.json) は持っています `rms_norm_eps=1e-05` です。これも上書きしましたが、動作しませんでした：

{% code overflow="wrap" %}

```bash
--override-kv qwen2.attention.layer_norm_rms_epsilon=float:0.000001 \
```

{% endcode %}

3. また、tokenizerのIDがllama.cppと通常のTransformersで一致するかどうかを@kalomazeの助けを借りてテストしました。 [@kalomaze](https://x.com/kalomaze/status/1897875332230779138)それらは一致したので、原因ではありませんでした。

以下に実験結果を示します：

{% file src="<https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-daa99953e0628c36fd53745a4b786206907e7d9a%2Ffile_BF16_no_samplers.txt?alt=media>" %}
サンプリング修正なしのBF16フル精度
{% endfile %}

{% file src="<https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-52f35bdaa5b1d7c9c19e943f224f049de2f0555f%2Ffile_BF16_yes_samplers.txt?alt=media>" %}
サンプリング修正ありのBF16フル精度
{% endfile %}

{% file src="<https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-276ff61d8749856abacdd33f38e73f9782a516fd%2Ffinal_Q4_K_M_no_samplers.txt?alt=media>" %}
サンプリング修正なしのQ4\_K\_M精度
{% endfile %}

{% file src="<https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-ea3905fe9ce08d0fdf291ee2a32eaa6958759547%2Ffinal_Q4_K_M_yes_samplers.txt?alt=media>" %}
サンプリング修正ありのQ4\_K\_M精度
{% endfile %}

## :pencil2: Tokenizerのバグ修正

* ファインチューニングに特に影響するいくつかの問題も見つけました！EOSトークンは正しいですが、PADトークンはおそらくむしろ次のようにするべきです `"<|vision_pad|>`" それを次で更新しました： <https://huggingface.co/unsloth/QwQ-32B/blob/main/tokenizer_config.json>

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

## :tools: ダイナミック4ビット量子化

また、単純な4ビット量子化より精度が上がるダイナミック4ビット量子化をアップロードしました！ 活性化と重みの量子化誤差の両方についてQwQの量子化誤差プロット解析を添付します：

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-16157f53eff143c179be571a43f8b55000d94290%2FQwQ%20quantization%20errors.png?alt=media" alt=""><figcaption></figcaption></figure>

ダイナミック4ビット量子化を次にアップロードしました： <https://huggingface.co/unsloth/QwQ-32B-unsloth-bnb-4bit>

vLLM 0.7.3（2025年2月20日）以降、 <https://github.com/vllm-project/vllm/releases/tag/v0.7.3>、vLLMはUnslothのダイナミック4ビット量子化の読み込みをサポートするようになりました！

私たちのすべてのGGUFはここにあります <https://huggingface.co/unsloth/QwQ-32B-GGUF>!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://unsloth.ai/docs/jp/moderu/tutorials/qwq-32b-how-to-run-effectively.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
