> 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/deepseek-ocr-2.md).

# DeepSeek-OCR 2: Leitfaden zum Ausführen und Feinabstimmen

Leitfaden zum lokalen Ausführen und Feinabstimmen von DeepSeek-OCR-2.

**DeepSeek-OCR 2** ist das neue Modell mit 3 Milliarden Parametern für hochmoderne Bildverarbeitung und Dokumentenverständnis, das DeepSeek am 27. Januar 2026 veröffentlicht hat. Das Modell konzentriert sich auf die Umwandlung von Bildern in Text und bietet ein leistungsfähigeres visuelles Schlussfolgern – nicht nur Texterkennung.

DeepSeek-OCR 2 führt DeepEncoder V2 ein, wodurch das Modell ein Bild in derselben logischen Reihenfolge „sehen“ kann wie ein Mensch.

Anders als herkömmliche Vision-LLMs, die Bilder in einem festen Raster von oben links nach unten rechts abtasten, erstellt DeepEncoder V2 zunächst ein globales Verständnis und lernt dann eine menschenähnliche Lesereihenfolge: worauf es zuerst, als Nächstes und so weiter achten soll. Das verbessert die OCR bei komplexen Layouts, da Spalten besser verfolgt, Beschriftungen mit Werten verknüpft, Tabellen sinnvoll gelesen und Text und Struktur gemeinsam verarbeitet werden.

Du kannst DeepSeek-OCR 2 jetzt in Unsloth mit unserem [**kostenlosen Fine-Tuning-Notebook**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Deepseek_OCR_\(3B\).ipynb)**.** Wir haben eine [Verbesserung um 88,6 %](#fine-tuning-deepseek-ocr) beim Sprachverständnis nachgewiesen.

<a href="https://unsloth.ai/docs/de/modelle/tutorials/deepseek-ocr-2.md#running-deepseek-ocr-2" class="button primary">DeepSeek-OCR 2 ausführen</a><a href="https://unsloth.ai/docs/de/modelle/tutorials/deepseek-ocr-2.md#fine-tuning-deepseek-ocr-2" class="button secondary">DeepSeek-OCR 2 feinabstimmen</a>

## 🖥️ **DeepSeek-OCR 2 ausführen**

Damit das Modell ausgeführt werden kann, wurde DeepSeek-OCR 2 wie das erste Modell angepasst, um Inferenz und Training mit der neuesten Transformers-Version zu ermöglichen (ohne Änderungen an der Genauigkeit). Du findest [es hier](https://huggingface.co/unsloth/DeepSeek-OCR-2).

Um das Modell mit [transformers](#transformers-run-deepseek-ocr-2-tutorial) oder [Unsloth](#unsloth-run-deepseek-ocr-tutorial), auszuführen, empfehlen wir folgende Einstellungen:

### :gear: Empfohlene Einstellungen

DeepSeek empfiehlt folgende Einstellungen:

* <mark style="color:Standard;background-color:blue;">**Temperatur = 0,0**</mark>
* `max_tokens = 8192`
* `ngram_size = 30`
* `window_size = 90`

**Unterstützte Modi – dynamische Auflösung:**

* Standard: (0-6)×768×768 + 1×1024×1024 — (0-6)×144 + 256 visuelle Tokens

**Beispiele für Prompts:**

```
# document: <image>\n<|grounding|>Convert the document to markdown.
# other image: <image>\n<|grounding|>OCR this image.
# without layouts: <image>\nFree OCR.
# figures in document: <image>\nParse the figure.
# general: <image>\nDescribe this image in detail.
# rec: <image>\nLocate <|ref|>xxxx<|/ref|> in the image.
```

<div align="center"><figure><img src="https://797013937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FGff3UBRgiu0aFXsbwll2%2Ffig1.png?alt=media&amp;token=58864777-114a-450a-ab56-3cabc9219cf7" alt="" width="375"><figcaption><p>Wandelt jedes Dokument mithilfe von Visual Causal Flow in Markdown um.</p></figcaption></figure></div>

### 🦥 Unsloth: Tutorial zum Ausführen von DeepSeek-OCR 2

1. Installiere die neueste Version von `unsloth` mit `pip install --upgrade unsloth` . Wenn Unsloth bereits installiert ist, aktualisiere es mit `pip install --upgrade --force-reinstall --no-deps --no-cache-dir unsloth unsloth_zoo`
2. Führe anschließend DeepSeek-OCR 2 mit dem folgenden Code aus:

{% code overflow="wrap" %}

```python
from unsloth import FastVisionModel
import torch
from transformers import AutoModel
import os
os.environ["UNSLOTH_WARN_UNINITIALIZED"] = '0'

from huggingface_hub import snapshot_download
snapshot_download("unsloth/DeepSeek-OCR-2", local_dir = "deepseek_ocr")
model, tokenizer = FastVisionModel.from_pretrained(
    "./deepseek_ocr",
    load_in_4bit = False, # Use 4bit to reduce memory use. False for 16bit LoRA.
    auto_model = AutoModel,
    trust_remote_code = True,
    unsloth_force_compile = True,
    use_gradient_checkpointing = "unsloth", # True or "unsloth" for long context
)

prompt = "<image>\nFree OCR. "
image_file = 'your_image.jpg'
output_path = 'your/output/dir'
res = model.infer(tokenizer, prompt=prompt, image_file=image_file, output_path = output_path, base_size = 1024, image_size = 640, crop_mode=True, save_results = True, test_compress = False)
```

{% endcode %}

### 🤗 Transformers: DeepSeek-OCR 2 – Tutorial ausführen

Inferenz mit Hugging Face Transformers auf NVIDIA-GPUs. Getestete Anforderungen: Python 3.12.9 + CUDA 11.8:

```bash
torch==2.6.0
transformers==4.46.3
tokenizers==0.20.3
einops
addict 
easydict
pip install flash-attn==2.7.3 --no-build-isolation
```

```python
from transformers import AutoModel, AutoTokenizer
import torch
import os
os.environ["CUDA_VISIBLE_DEVICES"] = '0'
model_name = 'unsloth/DeepSeek-OCR-2'

tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModel.from_pretrained(model_name, _attn_implementation='flash_attention_2', trust_remote_code=True, use_safetensors=True)
model = model.eval().cuda().to(torch.bfloat16)

# prompt = "<image>\nFree OCR. "
prompt = "<image>\n<|grounding|>Convert the document to markdown. "
image_file = 'your_image.jpg'
output_path = 'your/output/dir'

res = model.infer(tokenizer, prompt=prompt, image_file=image_file, output_path = output_path, base_size = 1024, image_size = 768, crop_mode=True, save_results = True)
```

## 🦥 **DeepSeek-OCR 2 feinabstimmen**

Unsloth unterstützt jetzt das Feinabstimmen von DeepSeek-OCR 2. Wie beim ersten Modell musst du unseren [benutzerdefinierten Upload](https://huggingface.co/unsloth/DeepSeek-OCR-2) verwenden, damit es mit `transformers` funktioniert (ohne Genauigkeitseinbußen). Wie beim ersten Modell trainiert Unsloth DeepSeek-OCR-2 1,4-mal schneller, mit 40 % weniger VRAM und 5-mal längeren Kontextlängen – ohne Genauigkeitsverlust.\
\
Du kannst DeepSeek-OCR 2 jetzt über unser kostenloses Colab-Notebook feinabstimmen.

* DeepSeek-OCR 2: [Nur-Feinabstimmungs-Notebook](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Deepseek_OCR_2_\(3B\).ipynb)

Unten findest du die Verbesserungen der CER-Genauigkeit (Character Error Rate, Zeichenfehlerrate) für Persisch:

#### CER pro Stichprobe (10 Stichproben)

| Index | OCR1 vorher | OCR1 nachher | OCR2 vorher | OCR2 nachher |
| ----- | ----------: | -----------: | ----------: | -----------: |
| 1520  |      1.0000 |       0.8000 |     10.4000 |       1.0000 |
| 1521  |      0.0000 |       0.0000 |      2.6809 |       0.0213 |
| 1522  |      2.0833 |       0.5833 |      4.4167 |       1.0000 |
| 1523  |      0.2258 |       0.0645 |      0.8710 |       0.0968 |
| 1524  |      0.0882 |       0.1176 |      2.7647 |       0.0882 |
| 1525  |      0.1111 |       0.1111 |      0.9444 |       0.2222 |
| 1526  |      2.8571 |       0.8571 |      4.2857 |       0.7143 |
| 1527  |      3.5000 |       1.5000 |     13.2500 |       1.0000 |
| 1528  |      2.7500 |       1.5000 |      1.0000 |       1.0000 |
| 1529  |      2.2500 |       0.8750 |      1.2500 |       0.8750 |

#### Durchschnittliche CER (10 Stichproben)

* **OCR1:** vorher **1.4866**, danach **0.6409** (**-57%**)
* **OCR2:** davor **4.1863**, danach **0.6018** (**-86%**)

## 📊 Benchmarks

Die Benchmarks für das Modell DeepSeek-OCR 2 basieren auf der offiziellen Forschungsarbeit.

**Tabelle 1:** Umfassende Bewertung des Dokumentenverständnisses auf OmniDocBench v1.5. V-token𝑚𝑎𝑥\
steht für die maximale Anzahl visueller Tokens, die in diesem Benchmark pro Seite verwendet werden. R-order\
bezeichnet die Lesereihenfolge. Mit Ausnahme von DeepSeek OCR und DeepSeek OCR 2 stammen alle anderen Modellergebnisse\
in dieser Tabelle aus dem OmniDocBench-Repository.

<figure><img src="https://797013937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FhxyKqi0rT9Jm4Y9PFqBY%2FScreenshot%202026-01-27%20at%201.14.02%E2%80%AFAM.optimized.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>

**Tabelle 2:** Editierabstände für verschiedene Kategorien von Dokumentelementen in OmniDocBench v1.5.\
V-token𝑚𝑎𝑥 bezeichnet die niedrigste maximale Anzahl visueller Tokens.

<figure><img src="https://797013937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FcTVu52ugTwQAqLdnQLLz%2FScreenshot%202026-01-27%20at%201.14.15%E2%80%AFAM.png?alt=media&amp;token=ec92a4a1-facb-4b63-90cd-73d23a41dcfb" alt="" width="563"><figcaption><p>Übertrifft Gemini-3 Pro auf OmniDocBench</p></figcaption></figure>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/de/modelle/tutorials/deepseek-ocr-2.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
