Billy Tse
HomeRoadmapBlogContact
Playground
Buy me a bug

© 2026 Billy Tse

OnlyFansLinkedInGitHubEmail
Back to Blog
January 29, 2026•18 min read

DeepSeek-OCR 2: Visual Causal Flow — 用 LLM 做 Vision Encoder 嘅突破

深入解析 DeepSeek-OCR 2 論文,探討點樣用 LLM 架構作為 vision encoder,透過 causal flow 動態重排 visual tokens,喺 document parsing 達到 SOTA 表現

OCRVisual TokensTransformerCSCI 5640 NLP

論文來源:DeepSeek-AI (2026-01-28) arXiv: 2601.20552 GitHub: deepseek-ai/DeepSeek-OCR-2

TL;DR

DeepSeek-OCR 2 提出咗一個革命性嘅想法:用 LLM 做 vision encoder。傳統嘅 vision-language models (VLMs) 將圖像 patches 以固定嘅 raster-scan 順序(由左至右、由上至下)餵入 LLM,但呢種做法忽略咗圖像嘅語義結構。DeepSeek-OCR 2 嘅 DeepEncoder V2 引入咗 visual causal flow 機制,透過 learnable queries 動態重排 visual tokens,模仿人類視覺系統嘅語義導向掃描模式。

核心突破:

  • 🎯 喺 OmniDocBench v1.5 達到 91.09% 準確度(SOTA)
  • 🚀 Visual tokens 上限只需 1120(比同類模型少 >6000)
  • 📖 Reading order 錯誤率降至 0.057(比 baseline 改善 33%)
  • 🧠 首次驗證 LLM 架構可作為 vision encoder

背景:點解傳統 VLMs 有問題?

人類視覺 vs. 傳統 Encoder

人類睇圖像唔係一個 pixel 一個 pixel 咁掃描,而係根據語義邏輯跳躍式咁睇。例如睇一個螺旋形,我哋嘅眼睛會沿住螺旋嘅內在邏輯移動,每次 fixation 都係因果相關嘅。

但傳統 VLMs 嘅做法係:

  1. 將圖像切成 patches(例如 16×16)
  2. 強制以 top-left → bottom-right 順序排列
  3. 加上固定嘅 positional encoding(如 RoPE)
  4. 餵入 LLM 做 causal decoding

呢種做法有兩大問題:

  • ❌ Spatial bias:強制嘅空間順序忽略咗語義關係
  • ❌ Mismatch with causality:2D 圖像被硬塞入 1D causal LLM

DeepEncoder V2:核心創新

架構設計

DeepEncoder V2 由三個部分組成:

  1. Vision Tokenizer(80M params)

用 SAM-base + 兩層 Conv 將圖像壓縮 16×,例如:

  • 1024×1024 → 256 visual tokens
  • 768×768 → 144 visual tokens

呢個設計大幅減少後續嘅計算成本。

  1. LLM-style Vision Encoder(500M params)

核心創新:用 Qwen2-0.5B 取代傳統嘅 CLIP ViT!

關鍵設計:

[Visual Tokens (prefix)] + [Causal Flow Queries (suffix)] ↓ ↓ Bidirectional Attention Causal Attention

Attention Mask 設計:

M=[1m×m0m×n1n×mLowerTri(n)]M = \begin{bmatrix} 1_{m \times m} & 0_{m \times n} \\ 1_{n \times m} & \text{LowerTri}(n) \end{bmatrix}M=[1m×m​1n×m​​0m×n​LowerTri(n)​]

where n=mn = mn=m (queries 數量 = visual tokens 數量)

  • Visual tokens:用 bidirectional attention,保留 CLIP 嘅全局感知能力
  • Causal flow queries:用 causal attention(三角形 mask),每個 query 可以 attend 到所有 visual tokens 同埋之前嘅 queries
  1. Causal Flow Queries

設計理念:保持 queries 數量 = visual tokens 數量,俾足夠嘅容量做 re-fixation(重新注視)。

Multi-crop 策略:

  • Global view(1024×1024)→ 256 queries (query_global)
  • Local crops(768×768,0-6 個)→ 每個 144 queries (query_local)
  • Total tokens:256 到 1120(ktimes144+256k times 144 + 256ktimes144+256)

呢個設計確保最大 token 數唔超過 Gemini-3 Pro 嘅預算(1120)。

Two-Stage Cascade Causal Reasoning

DeepSeek-OCR 2 嘅完整 pipeline 可以寫成:

O=D(πQ(TL(E(I)⊕Q0;M)))O = D\left(\pi_Q\left(T_L\left(E(I) \oplus Q_0; M\right)\right)\right)O=D(πQ​(TL​(E(I)⊕Q0​;M)))

where:

  • EEE:Vision tokenizer
  • TLT_LTL​:L-layer Transformer with masked attention
  • Q0Q_0Q0​:Learnable causal queries
  • piQpi_QpiQ​:Projection operator(只抽取 queries 部分)
  • DDD:DeepSeek-3B MoE decoder

兩階段因果推理:

  1. Encoder stage:透過 causal queries 對 visual tokens 做語義重排(reading logic reasoning)
  2. Decoder stage:LLM 對已重排嘅 visual tokens 做 autoregressive reasoning(visual task reasoning)

呢種設計將 2D 理解分解成兩個互補嘅 1D causal reasoning 任務。

訓練流程

Stage 1: Encoder Pretraining(40k iterations)

  • 用 language modeling objective 訓練 encoder
  • 配一個輕量級 decoder 做 joint optimization
  • Vision tokenizer:從 DeepEncoder 初始化
  • LLM encoder:從 Qwen2-0.5B-base 初始化
  • 資源:160 A100 GPUs,batch size 640

Stage 2: Query Enhancement(15k iterations)

  • 凍結 vision tokenizer
  • 同時優化 LLM encoder 同 DeepSeek-3B decoder
  • 用 multi-crop 策略統一多種解像度
  • 4-stage pipeline parallelism

Stage 3: Decoder Specialization(20k iterations)

  • 凍結所有 encoder 參數
  • 只更新 DeepSeek-LLM 參數
  • 訓練速度提升 >2×
  • 幫 LLM 更好理解重排後嘅 visual tokens

實驗結果

OmniDocBench v1.5 主要指標

ModelV-token (max)Overall ↑Text ED ↓Formula CDM ↑Table TEDS ↑R-order ED ↓
Qwen3-VL-235B>600089.15%0.06988.14%86.21%0.068
Gemini-2.5 Pro-88.03%0.07585.82%85.71%0.097
DeepSeek-OCR115687.36%0.07384.14%85.25%0.085
DeepSeek-OCR 2112091.09%0.04890.31%87.75%0.057

相比 baseline 改善:

  • Overall:+3.73%
  • Text ED:-0.025(改善 34%)
  • Formula CDM:+6.17%
  • Reading order:-0.028(改善 33%)

跨文檔類型表現

| Document Type | DeepSeek-OCR Text / R-order | DeepSeek-OCR 2 Text / R-order | | ----------------- | --------------------------- | ----------------------------- | | PPT | 0.052 / 0.052 | 0.031 / 0.025 ✅ | | Academic Paper | 0.028 / 0.021 | 0.013 / 0.013 ✅ | | Colorful Textbook | 0.130 / 0.125 | 0.053 / 0.066 ✅ | | Exam Paper | 0.074 / 0.083 | 0.047 / 0.048 ✅ | | Note | 0.145 / 0.089 | 0.068 / 0.035 ✅ |

喺幾乎所有類別都有顯著改善,尤其係 reading order 指標。

Production Readiness

EnvironmentMetricDeepSeek-OCRDeepSeek-OCR 2Improvement
Online user imagesRepetition rate6.25%4.17%↓ 2.08%
Pretraining PDFsRepetition rate3.69%2.88%↓ 0.81%

重複率大幅降低,證明架構喺實際場景中更加穩健。

深入分析

點解 LLM 可以做 Vision Encoder?

論文提出三個關鍵因素:

1. Prefix Concatenation 設計

將 visual tokens 作為 prefix(而非用 cross-attention 分離),確保 visual tokens 喺所有 layers 都保持活躍,促進同 causal queries 嘅有效交換。

實驗發現:用 mBART-style encoder-decoder + cross-attention 會無法收斂,因為 visual tokens 被隔離後交互唔足。

2. Equal Cardinality

Queries 數量 = Visual tokens 數量,提供足夠容量做 re-fixation。人類視覺會重複注視重要區域,呢個設計模仿咗呢種機制。

3. Dual-Stream Attention

  • Visual tokens 用 bidirectional attention → 保留全局理解
  • Queries 用 causal attention → 引入順序推理

呢種混合設計結合咗 ViT 同 LLM decoder 嘅優點。

對比其他 Parallelized Query 設計

ModelQuery DesignAttentionUse Case
DETR100 object queriesBidirectionalObject detection
BLIP-2 Q-former32 learnable queriesBidirectionalToken compression
DeepEncoder V2n queries (n = visual tokens)CausalToken reordering

DeepEncoder V2 係首個將 causal attention 應用於 vision encoder queries 嘅架構。

限制同未來方向

當前限制

1. Newspaper 表現仍有改善空間

Text ED 仍然 >0.13,可能原因:

  • Visual token 上限(1120)對 text-rich 文檔唔夠
  • 訓練數據只有 250k newspaper samples

解決方案:增加 local crops 數量或增強 newspaper 數據。

2. 單次 Reordering

當前設計只做一次語義重排,未能支持 multi-hop reordering 或 multiple re-examinations。

未來方向

  1. Towards Genuine 2D Reasoning

論文提出一個大膽嘅假設:2D reasoning = 兩個 1D causal reasoners 嘅級聯。

要實現真正嘅 2D reasoning,可能需要:

  • Causal flow tokens 數量 >> original visual tokens
  • Multi-hop reordering mechanisms
  • 驗證喺 general visual reasoning tasks 嘅有效性
  1. Towards Native Multimodality

DeepEncoder V2 提供咗 omni-modal encoder 嘅可能性:

Shared LLM Encoder (W_k, W_v, attention, FFNs) ↓ Modality-specific learnable queries ↓ [Text queries] [Audio queries] [Vision queries]

優勢:

  • 統一架構處理多種 modalities
  • 自然繼承 LLM 社群嘅優化(MoE、efficient attention 等)
  • 參數共享,更高效

技術啟示

1. 打破 Encoder-Decoder 範式

傳統 VLMs:Non-causal Encoder → Causal Decoder

DeepSeek-OCR 2:Causal Encoder → Causal Decoder

呢種設計更加 end-to-end causal,減少 2D→1D 嘅 mismatch。

2. Visual Tokens 唔係越多越好

DeepSeek-OCR 2 用 1120 tokens 就打贏咗用 >6000 tokens 嘅模型(Qwen3-VL-235B、InternVL3.5 等)。

關鍵:語義重排 > 暴力增加 token 數量

3. LLM Pretraining 對 Multimodal 嘅價值

Qwen2-0.5B 嘅 pretrained weights 提供咗強大嘅初始化,證明 LLM 訓練學到嘅知識可以 transfer 到 vision tasks。

4. Document OCR 係理想 Testbed

論文選擇 document parsing 作為主要實驗場景,因為:

  • 包含 complex layouts(多列、表格、公式)
  • 需要 sophisticated causal reasoning
  • 有明確嘅 ground truth(reading order)

呢個選擇非常聰明,because it validates the architecture in a challenging yet well-defined setting。

實作細節

Attention Mask 實現

def create_deepencoder_v2_mask(m, n): """ m: number of visual tokens n: number of causal query tokens (n == m) """ # Upper-left: visual tokens (bidirectional) visual_mask = torch.ones(m, m) # Upper-right: queries cannot attend to visual tokens initially upper_right = torch.zeros(m, n) # Lower-left: queries can attend to all visual tokens lower_left = torch.ones(n, m) # Lower-right: causal mask for queries lower_right = torch.tril(torch.ones(n, n)) # Concatenate top = torch.cat([visual_mask, upper_right], dim=1) bottom = torch.cat([lower_left, lower_right], dim=1) mask = torch.cat([top, bottom], dim=0) return mask

Multi-Crop Token Count

def calculate_token_count(image_width, image_height): """ Calculate total visual tokens using multi-crop strategy """ # Global view (always present) global_tokens = 256 # from 1024x1024 → 64x64 patches → 256 tokens # Local crops (0-6 views) if image_width <= 768 and image_height <= 768: num_local_crops = 0 else: # Heuristic: depends on aspect ratio and size num_local_crops = min(6, calculate_crops(image_width, image_height)) local_tokens = num_local_crops * 144 # each 768x768 → 144 tokens total = global_tokens + local_tokens # Range: [256, 1120] return total

同其他工作嘅比較

vs. RLM (Recursive Language Models)

兩者都係最近嘅突破性工作,但方向唔同:

AspectRLMDeepSeek-OCR 2
TargetContext rot(超長文檔)Visual token ordering
ApproachRecursive calls on textCausal flow on vision
Context10M+ tokens256-1120 visual tokens
Key IdeaEnvironment-based navigationSemantic reordering

vs. Traditional OCR Pipelines

PipelineV-tokensOverallArchitecture
PaddleOCR-VL-92.86%Multi-stage pipeline
MinerU2.5-90.67%Multi-stage pipeline
DeepSeek-OCR 2112091.09%End-to-end VLM

DeepSeek-OCR 2 以 end-to-end 方式接近咗 multi-stage pipeline 嘅表現。

總結

DeepSeek-OCR 2 唔只係一個 document parsing 嘅 SOTA 模型,更重要嘅係提出咗一個全新嘅 vision encoding 範式:

核心貢獻

  1. Visual Causal Flow:首次證明 LLM 架構可以作為 vision encoder
  2. Dual-Stream Attention:結合 bidirectional 同 causal attention
  3. Cascade Causal Reasoning:將 2D 理解分解成兩個 1D causal tasks
  4. High Efficiency:用最少嘅 visual tokens 達到 SOTA 表現

長遠影響

呢篇論文可能開啟咗幾個重要方向:

For Vision-Language Models:

  • 打破 "encoder 一定要 bidirectional" 嘅假設
  • 證明 semantic reordering 可以改善 visual understanding

For Multimodal Foundation Models:

  • 提供 omni-modal encoder 嘅可行路徑
  • 統一 text/audio/vision 處理架構

For Architecture Design:

  • 驗證 LLM pretraining 對 vision tasks 嘅價值
  • 展示 cascade causal reasoning 嘅潛力

相關資源

  • 📄 論文:arXiv:2601.20552
  • 💻 代碼:deepseek-ai/DeepSeek-OCR-2
  • 🎯 Benchmark:OmniDocBench v1.5
  • 📊 前作:DeepSeek-OCR

呢篇 review 基於 2026-01-28 發表嘅 DeepSeek-OCR 2 論文。如果你對 visual causal flow 或 multimodal architecture 有興趣,呢篇論文絕對值得深入閱讀。

Back to all articles
目錄