> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/de/modelle/tutorials/glm-4.7-flash.md).

# GLM-4.7-Flash: So führst du es lokal aus

GLM-4.7-Flash ist Z.ais neues 30B-MoE-Reasoning-Modell für den lokalen Einsatz, das erstklassige Leistung für Coding, agentische Workflows und Chat bietet. Es verwendet \~3,6 Mrd. Parameter, unterstützt 200K Kontext und führt bei SWE-Bench, GPQA sowie Reasoning-/Chat-Benchmarks.

GLM-4.7-Flash läuft auf **24 GB RAM**/VRAM/Unified Memory (32 GB für volle Präzision), und du kannst jetzt mit Unsloth feinabstimmen. Um GLM 4.7 Flash mit vLLM auszuführen, siehe [#glm-4.7-flash-in-vllm](#glm-4.7-flash-in-vllm "mention")

{% hint style="success" %}
Update vom 21. Jan.: `llama.cpp` einen Fehler behoben, bei dem die falsche `scoring_func`: `"softmax"` (sollte `"sigmoid"`sein). Dies verursachte Schleifen und schlechte Ausgaben. Wir haben die GGUFs aktualisiert – bitte lade das Modell erneut herunter, um deutlich bessere Ausgaben zu erhalten.

Du kannst jetzt Z.ais empfohlene Parameter verwenden und großartige Ergebnisse erzielen:

* **Für den allgemeinen Anwendungsfall:** `--temp 1.0 --top-p 0.95`
* **Für Tool-Calling:** `--temp 0.7 --top-p 1.0`
* **Wiederholungsstrafe:** Deaktiviere sie oder setze `--repeat-penalty 1.0`

22\. Jan.: Schnellere Inferenz ist da, da der FA-Fix für CUDA jetzt zusammengeführt wurde.
{% endhint %}

<a href="/pages/1e435114456bba34bc232a642cd33933aee06bbc#run-glm-4.7-flash" class="button primary">Ausführungstutorial</a><a href="/pages/1e435114456bba34bc232a642cd33933aee06bbc#fine-tuning-glm-4.7-flash" class="button secondary">Feinabstimmung</a>

GLM-4.7-Flash GGUF zum Ausführen: [unsloth/GLM-4.7-Flash-GGUF](https://huggingface.co/unsloth/GLM-4.7-Flash-GGUF)

### ⚙️ Nutzungsanleitung

Für die beste Leistung stelle sicher, dass dein insgesamt verfügbarer Speicher (VRAM + Systemspeicher) größer ist als die Größe der quantisierten Modelldatei, die du herunterlädst. Falls nicht, kann llama.cpp weiterhin per SSD/HDD-Offloading laufen, aber die Inferenz wird langsamer.

Nach Rücksprache mit dem Z.ai-Team empfehlen sie, ihre GLM-4.7-Sampling-Parameter zu verwenden:

| Standardeinstellungen (die meisten Aufgaben)                       | Terminal Bench, SWE Bench verifiziert                              |
| ------------------------------------------------------------------ | ------------------------------------------------------------------ |
| <mark style="background-color:green;">**temperature = 1.0**</mark> | <mark style="background-color:green;">**temperature = 0.7**</mark> |
| <mark style="background-color:green;">**top\_p = 0.95**</mark>     | <mark style="background-color:green;">**top\_p = 1.0**</mark>      |
| Wiederholungsstrafe = deaktiviert oder 1.0                         | Wiederholungsstrafe = deaktiviert oder 1.0                         |

* Für den allgemeinen Anwendungsfall:  `--temp 1.0 --top-p 0.95`
* Für Tool-Calling:  `--temp 0.7 --top-p 1.0`
* Wenn du llama.cpp verwendest, setze `--min-p 0.01` da der Standardwert von llama.cpp 0.05 ist
* Manchmal musst du ausprobieren, welche Zahlen für deinen Anwendungsfall am besten funktionieren.

{% hint style="warning" %}
Vorerst empfehlen wir nicht **empfehlen wir nicht** diese GGUF mit **Ollama** wegen möglicher Probleme mit der Kompatibilität des Chat-Templates. Die GGUF funktioniert gut mit llama.cpp (oder Backends wie z. B. LM Studio, Jan).

**Denk daran, die Wiederholungsstrafe zu deaktivieren! Oder setze** `--repeat-penalty 1.0`
{% endhint %}

* **Maximales Kontextfenster:** `202,752`

### 🖥️ GLM-4.7-Flash ausführen

Je nach Anwendungsfall müssen Sie unterschiedliche Einstellungen verwenden. Einige GGUFs landen in ähnlicher Größe, weil die Modellarchitektur (wie [gpt-oss](/docs/de/modelle/gpt-oss-how-to-run-and-fine-tune.md)) Dimensionen hat, die nicht durch 128 teilbar sind, sodass Teile nicht auf niedrigere Bits quantisiert werden können.

Da diese Anleitung 4-Bit verwendet, benötigst du etwa 18 GB RAM/Unified Memory. Für die beste Leistung empfehlen wir, mindestens 4-Bit-Präzision zu verwenden.

{% hint style="warning" %}
Vorerst empfehlen wir nicht **empfehlen wir nicht** diese GGUF mit **Ollama** wegen möglicher Probleme mit der Kompatibilität des Chat-Templates. Die GGUF funktioniert gut mit llama.cpp (oder Backends wie z. B. LM Studio, Jan).

**Denk daran, die Wiederholungsstrafe zu deaktivieren! Oder setze** `--repeat-penalty 1.0`
{% endhint %}

#### 🦥 Unsloth Studio-Anleitung

GLM-4.7-Flash kann ausgeführt und feinabgestimmt werden in [Unsloth Studio](/docs/de/neu/studio.md)unserer neuen Open-Source-Web-UI für lokale KI ausgeführt und feinabgestimmt werden. Mit Unsloth Studio können Sie Modelle lokal auf **MacOS, Windows**, Linux und:

{% columns %}
{% column %}

* Suchen, herunterladen, [GGUFs ausführen](/docs/de/neu/studio.md#run-models-locally) und Safetensor-Modelle
* [**Selbstheilende** Tool-Aufrufe](/docs/de/neu/studio.md#execute-code--heal-tool-calling) + **Websuche**
* [**Code-Ausführung**](/docs/de/neu/studio.md#run-models-locally) (Python, Bash)
* [Automatische Inferenz](https://unsloth.ai/docs/desktop#feature-deep-dive) Parametertuning (Temp, Top-P usw.)
* Schnelle CPU- + GPU-Inferenz über llama.cpp
* [LLMs trainieren](/docs/de/neu/studio.md#no-code-training) 2x schneller mit 70 % weniger VRAM
  {% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="/files/89ac45c1d5144736e3036cb7225d0c867534603a" alt=""><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

{% stepper %}
{% step %}
**Unsloth installieren**

Führen Sie dies in Ihrem Terminal aus:

macOS, Linux, WSL:

```bash
curl -fsSL https://unsloth.ai/install.sh | sh
```

Windows PowerShell:

```bash
irm https://unsloth.ai/install.ps1 | iex
```

{% hint style="success" %}
**Die Installation wird schnell sein und dauert ca. 1–2 Minuten.**
{% endhint %}
{% endstep %}

{% step %}
**Unsloth starten**

MacOS, Linux, WSL und Windows:

```bash
unsloth studio -H 0.0.0.0 -p 8888
```

Dann öffnen Sie `http://localhost:8888` in Ihrem Browser.
{% endstep %}

{% step %}
**GLM-4.7-Flash suchen und herunterladen**

Beim ersten Start müssen Sie ein Passwort erstellen, um Ihr Konto zu sichern, und sich später erneut anmelden. Sie sehen dann einen kurzen Einrichtungsassistenten, um ein Modell, einen Datensatz und grundlegende Einstellungen auszuwählen. Sie können ihn jederzeit überspringen.

Gehen Sie dann zur [Unsloth Chat](/docs/de/neu/studio/chat.md) Registerkarte und suche nach **GLM-4.7-Flash** in die Suchleiste eingeben und das gewünschte Modell und die gewünschte Quantisierung herunterladen.

<div data-with-frame="true"><figure><img src="/files/ab7f9fdce4489cfc90e0e2175e693856b2cef7be" alt="" width="375"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**GLM-4.7-Flash ausführen**

Die Inferenzparameter sollten bei Verwendung von Unsloth Studio automatisch gesetzt werden, Sie können sie jedoch weiterhin manuell ändern. Sie können auch die Kontextlänge, das Chat-Template und andere Einstellungen bearbeiten.

Weitere Informationen finden Sie in unserer [Unsloth-Studio-Inferenzanleitung](/docs/de/neu/studio/chat.md).

<div data-with-frame="true"><figure><img src="/files/72e444ba2ee0f824709d0f03d5c3ca108bd5936f" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}
{% endstepper %}

#### Llama.cpp-Tutorial (GGUF):

Anweisungen für die Ausführung in llama.cpp (beachten Sie, dass wir 4-Bit verwenden, damit es auf die meisten Geräte passt):

{% stepper %}
{% step %}
Holen Sie sich die neueste `llama.cpp` auf [GitHub hier](https://github.com/ggml-org/llama.cpp). Sie können auch den folgenden Build-Anweisungen folgen. Ändern Sie `-DGGML_CUDA=ON` zu `-DGGML_CUDA=OFF` wenn Sie keine GPU haben oder nur CPU-Inferenz möchten. **Für Apple-Mac-/Metal-Geräte**, setzen Sie `-DGGML_CUDA=OFF` und fahren Sie dann wie gewohnt fort – Metal-Unterstützung ist standardmäßig aktiviert.

{% code overflow="wrap" %}

```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=OFF -DGGML_CUDA=ON
cmake --build llama.cpp/build --config Release -j --clean-first --target llama-cli llama-mtmd-cli llama-server llama-gguf-split
cp llama.cpp/build/bin/llama-* llama.cpp
```

{% endcode %}
{% endstep %}

{% step %}
Du kannst direkt von Hugging Face ziehen. Du kannst den Kontext auf 200K erhöhen, sofern dein RAM/VRAM es zulässt.

Du kannst auch Z.ais empfohlene GLM-4.7-Sampling-Parameter ausprobieren:

* Für den allgemeinen Anwendungsfall:  `--temp 1.0 --top-p 0.95`
* Für Tool-Calling:  `--temp 0.7 --top-p 1.0`
* **Denk daran, die Wiederholungsstrafe zu deaktivieren!**

Befolge dies für **allgemeine Anweisungen** Anwendungsfälle:

```bash
./llama.cpp/llama-cli \\
    -hf unsloth/GLM-4.7-Flash-GGUF:UD-Q4_K_XL \\
    --ctx-size 16384 \
    --temp 1.0 --top-p 0.95 --min-p 0.01
```

Befolge dies für **Tool-Aufrufe** Anwendungsfälle:

```bash
./llama.cpp/llama-cli \\
    -hf unsloth/GLM-4.7-Flash-GGUF:UD-Q4_K_XL \\
    --ctx-size 16384 \
    --temp 0.7 --top-p 1.0 --min-p 0.01
```

{% endstep %}

{% step %}
Laden Sie das Modell über herunter (nach der Installation von `pip install huggingface_hub`). Sie können `UD-Q4_K_XL` oder andere quantisierte Versionen. Wenn Downloads hängen bleiben, siehe [Debugging für Hugging Face Hub, XET](/docs/de/grundlagen/troubleshooting-and-faqs/hugging-face-hub-xet-debugging.md)

{% code overflow="wrap" %}

```bash
pip install -U huggingface_hub
hf download unsloth/GLM-4.7-Flash-GGUF \\
    --local-dir unsloth/GLM-4.7-Flash-GGUF \\
    --include "*UD-Q2_K_XL*"
```

{% endcode %}
{% endstep %}

{% step %}
Dann führen Sie das Modell im Konversationsmodus aus:

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \\
    --model unsloth/GLM-4.7-Flash-GGUF/GLM-4.7-Flash-UD-Q4_K_XL.gguf \\
    --ctx-size 16384 \
    --seed 3407 \\
    --temp 1.0 \\
    --top-p 0.95 \
    --min-p 0.01
```

{% endcode %}

Passen Sie außerdem **das Kontextfenster** je nach Bedarf, bis zu `202752`
{% endstep %}
{% endstepper %}

### :loop:Wiederholungen und Schleifen reduzieren

{% hint style="success" %}
**UPDATE AM 21. JAN.: llama.cpp hat einen Fehler behoben, bei dem die falsche** `"scoring_func": "softmax"` **verwendet wurde, was zu Schleifen und schlechten Ausgaben führte (sollte sigmoid sein). Wir haben die GGUFs aktualisiert. Bitte lade das Modell erneut herunter, um deutlich bessere Ausgaben zu erhalten.**
{% endhint %}

Das bedeutet, dass du jetzt Z.ais empfohlene Parameter verwenden und großartige Ergebnisse erzielen kannst:

* Für den allgemeinen Anwendungsfall:  `--temp 1.0 --top-p 0.95`
* Für Tool-Calling:  `--temp 0.7 --top-p 1.0`
* Wenn du llama.cpp verwendest, setze `--min-p 0.01` da der Standardwert von llama.cpp 0.05 ist
* **Denk daran, die Wiederholungsstrafe zu deaktivieren! Oder setze** `--repeat-penalty 1.0`

Wir haben `"scoring_func": "sigmoid"` zu `config.json` für das Hauptmodell - [siehe](https://huggingface.co/unsloth/GLM-4.7-Flash/commit/3fd53b491e04f707f307aef2f70f8a7520511e6d).

{% hint style="warning" %}
Vorerst empfehlen wir nicht **empfehlen wir nicht** diese GGUF mit **Ollama** wegen möglicher Probleme mit der Kompatibilität des Chat-Templates. Die GGUF funktioniert gut mit llama.cpp (oder Backends wie z. B. LM Studio, Jan).
{% endhint %}

### :bird:Flappy-Bird-Beispiel mit UD-Q4\_K\_XL

Als Beispiel haben wir den folgenden langen Dialog mithilfe von UD-Q4\_K\_XL über `./llama.cpp/llama-cli --model unsloth/GLM-4.7-Flash-GGUF/GLM-4.7-Flash-UD-Q4_K_XL.gguf --fit on --temp 1.0 --top-p 0.95 --min-p 0.01` :

```
Hallo
Was ist 2+2
Erstelle ein Flappy-Bird-Spiel in Python
Erstelle ein völlig anderes Spiel in Rust
Finde in beiden Fehler
Mach das erste Spiel, das ich erwähnt habe, aber in einer eigenständigen HTML-Datei
Finde Fehler und zeige das korrigierte Spiel
```

wodurch das folgende Flappy-Bird-Spiel in HTML-Form gerendert wurde:

<details>

<summary>Flappy-Bird-Spiel in HTML (erweiterbar)</summary>

```html
<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Flappy Bird behoben</title>
    <style>
        body {
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #222;
            font-family: 'Arial', sans-serif;
            overflow: hidden;
            user-select: none;
            -webkit-user-select: none;
            touch-action: none; /* Verhindert Zoomen auf Mobilgeräten */
        }

        #game-container {
            position: relative;
            box-shadow: 0 0 20px rgba(0,0,0,0.5);
        }

        canvas {
            background-color: #87CEEB;
            display: block;
            border-radius: 4px;
        }

        /* UI-Overlays */
        #ui-layer {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            text-align: center;
        }

        #score-display {
            position: absolute;
            top: 40px;
            left: 50%;
            transform: translateX(-50%);
            font-size: 48px;
            font-weight: bold;
            color: white;
            text-shadow: 3px 3px 0 #000;
            z-index: 10;
            font-family: 'Courier New', Courier, monospace;
        }

        #start-screen, #game-over-screen {
            background: rgba(0, 0, 0, 0.7);
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            color: white;
            pointer-events: auto; /* Klicks erlauben */
            cursor: pointer;
        }

        h1 { margin: 0 0 10px 0; font-size: 60px; text-shadow: 4px 4px 0 #000; line-height: 1; }
        p { font-size: 22px; margin: 10px 0; color: #ddd; }
        
        .btn {
            background: linear-gradient(to bottom, #ffeb3b, #fbc02d);
            border: 3px solid #fff;
            color: #333;
            padding: 15px 40px;
            font-size: 28px;
            font-weight: bold;
            cursor: pointer;
            border-radius: 8px;
            box-shadow: 0 6px 0 #c49000, 0 10px 10px rgba(0,0,0,0.3);
            text-transform: uppercase;
            transition: all 0.1s;
            margin-top: 10px;
        }

        .btn:active {
            transform: translateY(4px);
            box-shadow: 0 2px 0 #c49000, 0 4px 4px rgba(0,0,0,0.3);
        }

        .score-board {
            background: #ded895;
            border: 2px solid #543847;
            padding: 20px 40px;
            border-radius: 10px;
            box-shadow: 4px 4px 0 #543847;
            margin-bottom: 30px;
            display: none;
            border: 4px solid #543847;
        }
        
        .score-board h2 { margin: 0 0 5px 0; color: #e86101; font-size: 40px; }
        .score-board span { font-size: 20px; color: #543847; display: block; text-align: center; }

    </style>
</head>
<body>

    <div id="game-container">
        <canvas id="gameCanvas" width="400" height="600"></canvas>
        
        <div id="score-display">0</div>

        <div id="ui-layer">
            <div id="start-screen">
                <h1>FLAPPY<br>BIRD</h1>
                <p>Tippe oder drücke die Leertaste, um zu starten</p>
                <button class="btn" style="display:none;" id="touch-instruction">Zum Starten klicken</button>
            </div>

            <div id="game-over-screen">
                <h1>SPIEL VORBEI</h1>
                <div class="score-board" id="score-board">
                    <h2>Punktestand: <span id="final-score">0</span></h2>
                </div>
                <button class="btn" id="restart-btn">Erneut versuchen</button>
            </div>
        </div>
    </div>

<script>
    const canvas = document.getElementById('gameCanvas');
    const ctx = canvas.getContext('2d');

    // --- Konstanten ---
    const GRAVITY = 0.35; // Etwas stärkere Schwerkraft für ein besseres Spielgefühl
    const JUMP_STRENGTH = -6.5;
    const PIPE_GAP = 180;
    const PIPE_WIDTH = 60;
    const PIPE_SPEED = 2.5;
    const PIPE_SPAWN_RATE = 100;

    // --- Status ---
    let frames = 0;
    let score = 0;
    let isGameOver = false;
    let isPlaying = false;
    let gameLoopId;

    const ui = {
        startScreen: document.getElementById('start-screen'),
        gameOverScreen: document.getElementById('game-over-screen'),
        scoreDisplay: document.getElementById('score-display'),
        scoreBoard: document.getElementById('score-board'),
        finalScore: document.getElementById('final-score'),
        restartBtn: document.getElementById('restart-btn')
    };

    const bird = {
        x: 80,
        y: 150,
        radius: 12, // Fester Radius
        velocity: 0,
        
        draw: function() {
            // Vogel basierend auf der Geschwindigkeit drehen für optische Wirkung
            let angle = Math.min(Math.PI / 4, Math.max(-Math.PI / 4, (this.velocity * 0.1)));
            
            ctx.save();
            ctx.translate(this.x, this.y);
            ctx.rotate(angle);
            
            // Körper zeichnen
            ctx.fillStyle = '#FFD700';
            ctx.beginPath();
            ctx.arc(0, 0, this.radius, 0, Math.PI * 2);
            ctx.fill();
            
            // Auge
            ctx.fillStyle = 'white';
            ctx.beginPath();
            ctx.arc(4, -4, 4, 0, Math.PI * 2);
            ctx.fill();
            ctx.fillStyle = 'black';
            ctx.beginPath();
            ctx.arc(6, -4, 2, 0, Math.PI * 2);
            ctx.fill();
            
            // Flügel
            ctx.fillStyle = '#FFA500';
            ctx.beginPath();
            ctx.arc(-4, 4, 5, 0, Math.PI * 2);
            ctx.fill();

            ctx.restore();
        },

        update: function() {
            this.velocity += GRAVITY;
            this.y += this.velocity;
        },

        jump: function() {
            this.velocity = JUMP_STRENGTH;
        },

        reset: function() {
            this.y = 150;
            this.velocity = 0;
        }
    };

    let pipes = [];

    function createPipe() {
        const minHeight = 50;
        const maxPos = canvas.height - PIPE_GAP - minHeight;
        const topHeight = Math.floor(Math.random() * (maxPos - minHeight + 1)) + minHeight;
        
        pipes.push({
            x: canvas.width,
            topHeight: topHeight,
            bottomY: topHeight + PIPE_GAP,
            width: PIPE_WIDTH,
            passed: false
        });
    }

    function drawPipes() {
        ctx.fillStyle = '#2ecc71';
        ctx.strokeStyle = '#27ae60';
        ctx.lineWidth = 2;
        
        pipes.forEach(pipe => {
            // Oberes Rohr
            ctx.fillRect(pipe.x, 0, pipe.width, pipe.topHeight);
            ctx.strokeRect(pipe.x, 0, pipe.width, pipe.topHeight);
            
            // Unteres Rohr
            ctx.fillRect(pipe.x, pipe.bottomY, pipe.width, canvas.height - pipe.bottomY);
            ctx.strokeRect(pipe.x, pipe.bottomY, pipe.width, canvas.height - pipe.bottomY);

            // Kappe
            const capH = 20;
            ctx.fillStyle = '#27ae60'; 
            ctx.fillRect(pipe.x - 2, pipe.topHeight - capH, pipe.width + 4, capH);
            ctx.fillRect(pipe.x - 2, pipe.bottomY, pipe.width + 4, capH);
        });
    }

    function updatePipes() {
        if (frames % PIPE_SPAWN_RATE === 0) createPipe();

        for (let i = 0; i < pipes.length; i++) {
            let p = pipes[i];
            p.x -= PIPE_SPEED;

            // --- KORRIGIERTE KOLLISIONSERKENNUNG ---
            // Vogel als Kreis mit dem Radius 'bird.radius' behandeln
            // Rohr ist ein Rechteck: x, x+w, y_top, y_bottom
            let birdLeft = bird.x - bird.radius;
            let birdRight = bird.x + bird.radius;
            let birdTop = bird.y - bird.radius;
            let birdBottom = bird.y + bird.radius;

            // Horizontale Überschneidung
            if (birdRight > p.x && birdLeft < p.x + p.width) {
                // Vertikale Überschneidung (oberes Rohr ODER unteres Rohr getroffen)
                if (birdTop < p.topHeight || birdBottom > p.bottomY) {
                    gameOver();
                }
            }

            // --- KORRIGIERTE PUNKTVERGABE ---
            // Wenn das Rohr links außerhalb des Bildschirms ist und noch nicht gewertet wurde
            if (p.x + p.width < 0 && !p.passed) {
                score++;
                p.passed = true;
                ui.scoreDisplay.innerText = score;
            }

            if (p.x < -60) {
                pipes.shift();
                i--;
            }
        }
    }

    function checkCollisions() {
        // Boden
        if (bird.y + bird.radius >= canvas.height) {
            gameOver();
        }
        // Decke
        if (bird.y - bird.radius <= 0) {
            bird.y = bird.radius;
            bird.velocity = 0;
        }
    }

    function drawBackground() {
        // Löschen
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        
        // Boden
        ctx.fillStyle = '#654321';
        ctx.fillRect(0, canvas.height - 10, canvas.width, 10);
        
        // Wolken
        ctx.fillStyle = "rgba(255, 255, 255, 0.6)";
        for(let i=0; i<4; i++) {
            let x = (frames * 0.5 + i * 150) % (canvas.width + 100) - 50;
            let y = (i * 40) + 20;
            let scale = 1 + (Math.sin(frames * 0.02 + i) * 0.1);
            let size = 30 * scale;
            ctx.beginPath();
            ctx.arc(x, y, size, 0, Math.PI * 2);
            ctx.arc(x + 20*scale, y - 10*scale, size * 1.2, 0, Math.PI * 2);
            ctx.arc(x + 40*scale, y, size, 0, Math.PI * 2);
            ctx.fill();
        }
    }

    function update() {
        if (!isPlaying) return;
        bird.update();
        updatePipes();
        checkCollisions();
        frames++;
    }

    function draw() {
        drawBackground();
        drawPipes();
        bird.draw();
    }

    function loop() {
        update();
        draw();
        if (isPlaying || !isGameOver) {
            gameLoopId = requestAnimationFrame(loop);
        }
    }

    function startGame() {
        isPlaying = true;
        isGameOver = false;
        
        // UI
        ui.startScreen.style.display = 'none';
        ui.gameOverScreen.style.display = 'none';
        ui.scoreBoard.style.display = 'none';
        
        // Logik
        bird.reset();
        pipes = [];
        score = 0;
        frames = 0;
        ui.scoreDisplay.innerText = '0';
        
        loop();
    }

    function gameOver() {
        isPlaying = false;
        isGameOver = true;
        cancelAnimationFrame(gameLoopId);
        
        ui.finalScore.innerText = score;
        ui.gameOverScreen.style.display = 'flex';
        ui.scoreBoard.style.display = 'block';
    }

    // --- Eingabeverarbeitung ---

    function handleInput(e) {
        if (e.type === 'keydown' && e.code === 'Space') e.preventDefault();

        if (isPlaying) {
            bird.jump();
        } else if (!isGameOver) {
            // Auf den Startbildschirm klicken (oder irgendein Klick, wenn das Spiel noch nicht gestartet wurde)
            startGame();
        }
    }

    // Tastatur
    window.addEventListener('keydown', (e) => {
        if (e.code === 'Space') handleInput(e);
    });

    // Maus / Touch
    window.addEventListener('mousedown', handleInput);
    window.addEventListener('touchstart', (e) => {
        // Zoomen/Scrollen verhindern
        // e.preventDefault(); 
        handleInput(e);
    }, {passive: false});

    // UI-Interaktionen
    ui.restartBtn.addEventListener('click', (e) => {
        e.stopPropagation();
        startGame();
    });
    
    // Klicken auf das Game-Over-Overlay zum Neustart erlauben
    ui.gameOverScreen.addEventListener('mousedown', (e) => {
        if(e.target === ui.gameOverScreen) startGame();
    });
    ui.gameOverScreen.addEventListener('touchstart', (e) => {
        if(e.target === ui.gameOverScreen) {
            e.preventDefault();
            startGame();
        }
    });

    // Erste Zeichnung
    drawBackground();
    bird.reset();
    bird.draw();

</script>
</body>
</html>
```

</details>

Und wir haben einige Screenshots gemacht (4-Bit funktioniert):

<div align="left"><figure><img src="/files/b62a6798dffa6d69b0c5e5156077a477da8bf73a" alt="" width="188"><figcaption></figcaption></figure> <figure><img src="/files/9c5189a382be6d4c2a867faff1c4c5f77e69ddbf" alt="" width="188"><figcaption></figcaption></figure></div>

### 🦥 Feinabstimmung von GLM-4.7-Flash

Unsloth unterstützt jetzt die Feinabstimmung von GLM-4.7-Flash, allerdings musst du `transformers v5`. Das 30B-Modell passt nicht auf eine kostenlose Colab-GPU; du kannst jedoch unser Notebook verwenden. Die 16-Bit-LoRA-Feinabstimmung von GLM-4.7-Flash benötigt etwa **60 GB VRAM**:

* [GLM-4.7-Flash SFT LoRA-Notebook](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/GLM_Flash_A100\(80GB\).ipynb)

{% hint style="warning" %}
Bei der Verwendung einer A100 mit 40 GB VRAM kann es manchmal zu einem Speichermangel kommen. Für reibungslosere Läufe benötigst du H100/A100 mit 80 GB VRAM.
{% endhint %}

{% embed url="<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/GLM_Flash_A100(80GB).ipynb>" %}

Beim Feinabstimmen von MoEs ist es wahrscheinlich keine gute Idee, die Router-Schicht mitzutrainieren, daher haben wir sie standardmäßig deaktiviert. Wenn du seine Reasoning-Fähigkeiten erhalten möchtest (optional), kannst du eine Mischung aus direkten Antworten und Chain-of-Thought-Beispielen verwenden. Verwende mindestens <mark style="background-color:green;">75 % Reasoning</mark> und <mark style="background-color:green;">25 % Nicht-Reasoning</mark> in Ihrem Datensatz, damit das Modell seine Reasoning-Fähigkeiten beibehält.

### 🦙 Llama-Server-Bereitstellung & Deployment

Um GLM-4.7-Flash produktiv bereitzustellen, verwenden wir `llama-server` In einem neuen Terminal, z. B. via tmux, stelle das Modell bereit mit:

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-server \\
    --model unsloth/GLM-4.7-Flash-GGUF/GLM-4.7-Flash-UD-Q4_K_XL.gguf \\
    --alias "unsloth/GLM-4.7-Flash" \\
    --seed 3407 \\
    --temp 1.0 \\
    --top-p 0.95 \
    --min-p 0.01 \
    --ctx-size 16384 \
    --port 8001
```

{% endcode %}

Dann in einem neuen Terminal, nach dem Ausführen von `pip install openai`, führe aus:

{% code overflow="wrap" %}

```python
from openai import OpenAI
import json
openai_client = OpenAI(
    base_url = "http://127.0.0.1:8001/v1",
    api_key = "sk-no-key-required",
)
completion = openai_client.chat.completions.create(
    model = "unsloth/GLM-4.7-Flash",
    messages = [{"role": "user", "content": "Was ist 2+2?"},],
)
print(completion.choices[0].message.content)
```

{% endcode %}

Was Folgendes ausgibt

{% code overflow="wrap" %}

```
Der Benutzer stellt eine einfache Frage: „Was ist 2+2?“ Die Antwort ist 4. Geben Sie die Antwort aus.

2 + 2 = 4.
```

{% endcode %}

### :computer: GLM-4.7-Flash in vLLM

Du kannst jetzt unsere neue [dynamische FP8-Quantisierung](https://huggingface.co/unsloth/GLM-4.7-Flash-FP8-Dynamic) des Modells für Premium- und schnelle Inferenz verwenden. Installiere zuerst die Nightly-Version von vLLM:

{% code overflow="wrap" %}

```bash
uv pip install --upgrade --force-reinstall vllm --torch-backend=auto --extra-index-url https://wheels.vllm.ai/nightly/cu130
uv pip install --upgrade --force-reinstall git+https://github.com/huggingface/transformers.git
uv pip install --force-reinstall numba
```

{% endcode %}

Dann bereitstellen [die dynamische FP8-Version von Unsloth](https://huggingface.co/unsloth/GLM-4.7-Flash-FP8-Dynamic) des Modells. Wir haben FP8 aktiviert, um die KV-Cache-Speichernutzung um 50 % zu reduzieren, und zwar auf 4 GPUs. Wenn du 1 GPU hast, verwende `CUDA_VISIBLE_DEVICES='0'` und setze `--tensor-parallel-size 1` oder entfernen Sie dieses Argument. Um FP8 zu deaktivieren, entfernen Sie `--quantization fp8 --kv-cache-dtype fp8`

```bash
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:False
CUDA_VISIBLE_DEVICES='0,1,2,3' vllm serve unsloth/GLM-4.7-Flash-FP8-Dynamic \\
    --served-model-name unsloth/GLM-4.7-Flash \\
    --tensor-parallel-size 4 \\
    --tool-call-parser glm47 \\
    --reasoning-parser glm45 \\
    --enable-auto-tool-choice \\
    --dtype bfloat16 \\
    --seed 3407 \\
    --max-model-len 200000 \\
    --gpu-memory-utilization 0.95 \\
    --max_num_batched_tokens 16384 \\
    --port 8001 \\
    --kv-cache-dtype fp8
```

Sie können das bereitgestellte Modell dann über die OpenAI-API aufrufen:

```python
from openai import AsyncOpenAI, OpenAI
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8001/v1"
client = OpenAI( # oder AsyncOpenAI
    api_key=openai_api_key,
    base_url=openai_api_base,
)
```

#### :star: vLLM GLM-4.7-Flash spekulative Dekodierung

Wir haben festgestellt, dass die Verwendung des MTP-(Multi-Token-Prediction)-Moduls von GLM 4.7 Flash den Generierungsdurchsatz von 13.000 Tokens auf 1 B200 auf 1.300 Tokens senkt! (10x langsamer) Auf Hopper sollte es hoffentlich in Ordnung sein.

```bash
    --speculative-config.method mtp \\
    --speculative-config.num_speculative_tokens 1
```

Nur 1.300 Tokens/s Durchsatz auf 1xB200 (130 Tokens/s Decoding pro Benutzer)

<figure><img src="/files/aa4355a18b5958bb0932d9f77b8931d39c71e469" alt=""><figcaption></figcaption></figure>

Und 13.000 Tokens/s Durchsatz auf 1xB200 (immer noch 130 Tokens/s Decoding pro Benutzer)

<figure><img src="/files/b3accc916b22880daa1d0df18a4f768a5aae404c" alt=""><figcaption></figcaption></figure>

### :hammer:Tool-Aufrufe mit GLM-4.7-Flash

Siehe [Tool Calling Guide](/docs/de/grundlagen/tool-calling-guide-for-local-llms.md) für weitere Details dazu, wie Tool-Calling funktioniert. In einem neuen Terminal (wenn du tmux verwendest, nutze CTRL+B+D) erstellen wir einige Tools wie das Hinzufügen von 2 Zahlen, das Ausführen von Python-Code, das Ausführen von Linux-Funktionen und vieles mehr:

{% code expandable="true" %}

```python
import json, subprocess, random
from typing import Any
def add_number(a: float | str, b: float | str) -> float:
    return float(a) + float(b)
def multiply_number(a: float | str, b: float | str) -> float:
    return float(a) * float(b)
def subtract_number(a: float | str, b: float | str) -> float:
    return float(a) - float(b)
def write_a_story() -> str:
    return random.choice([
        "Vor langer Zeit in einer weit, weit entfernten Galaxie...",
        "Es gab 2 Freunde, die Faultiere und Code liebten...",
        "Die Welt stand kurz vor dem Untergang, weil sich jedes Faultier zu übermenschlicher Intelligenz entwickelte...",
        "Ohne dass es ein Freund wusste, hatte der andere versehentlich ein Programm geschrieben, das Faultiere weiterentwickelt...",
    ])
def terminal(command: str) -> str:
    if "rm" in command or "sudo" in command or "dd" in command or "chmod" in command:
        msg = "Die Befehle 'rm, sudo, dd, chmod' können nicht ausgeführt werden, da sie gefährlich sind"
        print(msg); return msg
    print(f"Terminalbefehl `{command}` wird ausgeführt")
    try:
        return str(subprocess.run(command, capture_output = True, text = True, shell = True, check = True).stdout)
    except subprocess.CalledProcessError as e:
        return f"Befehl fehlgeschlagen: {e.stderr}"
def python(code: str) -> str:
    data = {}
    exec(code, data)
    del data["__builtins__"]
    return str(data)
MAP_FN = {
    "add_number": add_number,
    "multiply_number": multiply_number,
    "subtract_number": subtract_number,
    "write_a_story": write_a_story,
    "terminal": terminal,
    "python": python,
}
tools = [
    {
        "type": "function",
        "function": {
            "name": "add_number",
            "description": "Addiere zwei Zahlen.",
            "parameters": {
                "type": "object",
                "properties": {
                    "a": {
                        "type": "string",
                        "description": "Die erste Zahl.",
                    },
                    "b": {
                        "type": "string",
                        "description": "Die zweite Zahl.",
                    },
                },
                "required": ["a", "b"],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "multiply_number",
            "description": "Multipliziere zwei Zahlen.",
            "parameters": {
                "type": "object",
                "properties": {
                    "a": {
                        "type": "string",
                        "description": "Die erste Zahl.",
                    },
                    "b": {
                        "type": "string",
                        "description": "Die zweite Zahl.",
                    },
                },
                "required": ["a", "b"],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "subtract_number",
            "description": "Subtrahiere zwei Zahlen.",
            "parameters": {
                "type": "object",
                "properties": {
                    "a": {
                        "type": "string",
                        "description": "Die erste Zahl.",
                    },
                    "b": {
                        "type": "string",
                        "description": "Die zweite Zahl.",
                    },
                },
                "required": ["a", "b"],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "write_a_story",
            "description": "Schreibt eine zufällige Geschichte.",
            "parameters": {
                "type": "object",
                "properties": {},
                "required": [],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "terminal",
            "description": "Führe Operationen vom Terminal aus.",
            "parameters": {
                "type": "object",
                "properties": {
                    "command": {
                        "type": "string",
                        "description": "Der Befehl, den Sie ausführen möchten, z. B. `ls`, `rm`, ...",
                    },
                },
                "required": ["command"],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "python",
            "description": "Rufe einen Python-Interpreter mit etwas Python-Code auf, der ausgeführt wird.",
            "parameters": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": "Der auszuführende Python-Code",
                    },
                },
                "required": ["code"],
            },
        },
    },
]
```

{% endcode %}

Dann verwenden wir die folgenden Funktionen (kopieren, einfügen und ausführen), die die Funktionsaufrufe automatisch parsen und den OpenAI-Endpunkt für jedes Modell aufrufen:

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

```python
from openai import OpenAI
def unsloth_inference(
    messages,
    temperature = 0.7,
    top_p = 1.0,
    top_k = -1,
    repetition_penalty = 0.0,
):
    messages = messages.copy()
    openai_client = OpenAI(
        base_url = "http://127.0.0.1:8001/v1",
        api_key = "sk-no-key-required",
    )
    model_name = next(iter(openai_client.models.list())).id
    print(f"Verwende Modell = {model_name}")
    has_tool_calls = True
    original_messages_len = len(messages)
    while has_tool_calls:
        print(f"Aktuelle Nachrichten = {messages}")
        response = openai_client.chat.completions.create(
            model = model_name,
            messages = messages,
            temperature = temperature,
            top_p = top_p,
            tools = tools if tools else None,
            tool_choice = "auto" if tools else None,
            extra_body = {"top_k": top_k, "min_p": min_p, "dry_multiplier" :repetition_penalty,}
        )
        tool_calls = response.choices[0].message.tool_calls or []
        content = response.choices[0].message.content or ""
        tool_calls_dict = [tc.to_dict() for tc in tool_calls] if tool_calls else tool_calls
        messages.append({"role": "assistant", "tool_calls": tool_calls_dict, "content": content,})
        for tool_call in tool_calls:
            fx, args, _id = tool_call.function.name, tool_call.function.arguments, tool_call.id
            out = MAP_FN[fx](**json.loads(args))
            messages.append({"role": "tool", "tool_call_id": _id, "name": fx, "content": str(out),})
        else:
            has_tool_calls = False
    return messages
```

{% endcode %}

Nachdem GLM-4.7-Flash über `llama-server` wie in [#deploy-with-llama-server-and-openais-completion-library](#deploy-with-llama-server-and-openais-completion-library "mention") oder siehe [Tool Calling Guide](/docs/de/grundlagen/tool-calling-guide-for-local-llms.md) für weitere Details können wir dann einige Tool-Aufrufe durchführen:

**Tool-Aufruf für mathematische Operationen für GLM 4.7**

{% code overflow="wrap" %}

```python
messages = [{
    "role": "user",
    "content": [{"type": "text", "text": "Was ist das heutige Datum plus 3 Tage?"}],
}]
unsloth_inference(messages, temperature = 1.0, top_p = 0.95, top_k = -1, min_p = 0.01)
```

{% endcode %}

<figure><img src="/files/c65584a6dcba3fae024e43a1e2819019446b8023" alt=""><figcaption></figcaption></figure>

**Tool-Aufruf zur Ausführung von generiertem Python-Code für GLM-4.7-Flash**

{% code overflow="wrap" %}

```python
messages = [{
    "role": "user",
    "content": [{"type": "text", "text": "Erstelle eine Fibonacci-Funktion in Python und finde fib(20)."}],
}]
unsloth_inference(messages, temperature = 1.0, top_p = 0.95, top_k = -1, min_p = 0.01)
```

{% endcode %}

<figure><img src="/files/e56652f7cfccb3876e702100b6ffb2e6b9d1ea97" alt="" width="563"><figcaption></figcaption></figure>

### Benchmarks

GLM-4.7-Flash ist das leistungsstärkste 30B-Modell über alle Benchmarks hinweg, mit Ausnahme von AIME 25.

<figure><img src="/files/4ce31a24f8b6892eda5e7d0d531f69eaddeddad1" alt="" width="375"><figcaption></figcaption></figure>

| Benchmark          | GLM-4.7-Flash | Qwen3-30B-A3B-Thinking-2507 | GPT-OSS-20B |
| ------------------ | ------------- | --------------------------- | ----------- |
| AIME 25            | 91.6          | 85.0                        | 91.7        |
| GPQA               | 75.2          | 73.4                        | 71.5        |
| LCB v6             | 64.0          | 66.0                        | 61.0        |
| HLE                | 14.4          | 9.8                         | 10.9        |
| SWE-bench Verified | 59.2          | 22.0                        | 34.0        |
| τ²-Bench           | 79.5          | 49.0                        | 47.7        |
| BrowseComp         | 42.8          | 2.29                        | 28.3        |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://unsloth.ai/docs/de/modelle/tutorials/glm-4.7-flash.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
