Repository navigation
Conversation
|
It seems the impl in this branch has numeric precision issue: @o7si could you please have a test on image in that discussion? Thanks. |
@jason-ni |
The DeepSeek-OCR / Unlimited-OCR decoder reads dense layout (e.g. tables) by attending over the always-visible visual prefix. With the default F16 V-cache, those value vectors are truncated enough to garble the output: table headers come out as """ / ">" (reported on ggml-org#24975), while the official HF reference parses them correctly. The HF reference accumulates attention in F32, so match it by promoting the F16 V-cache default to F32 for LLM_ARCH_DEEPSEEK2OCR. An explicit lower-precision -ctv (e.g. q8_0) is still honored. This is the in-graph equivalent of running with --cache-type-v f32. It is not the cuBLAS compute mode: the headers are emitted deep in autoregressive decode (a mat-vec path that bypasses cuBLAS), so FORCE_CUBLAS_COMPUTE_32F has no effect; F16 V storage/accumulation is what truncates. Verified on the reported image (parses cleanly with no flags) and with tools/mtmd/tests/test-deepseek-ocr.py: all cases pass and improve, no regression (v1 0.2626, v2 0.6877, unlimited 0.1641 CER). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015dykwunMpwXWxHPVhbjhiK
|
@jason-ni |
ac42aca to
8d14be3
Compare
# Conflicts: # src/llama-kv-cache.cpp
# Conflicts: # src/llama-kv-cache.cpp
# Conflicts: # src/llama-kv-cache.cpp
|
Intel Arc A770/Vulkan single-page datapoint for Unlimited-OCR (not a test of this PR's R-SWA branch):
The stock build uses full attention, not this PR's reference sliding-window attention. Would a paired stock-versus-PR run with a public synthetic fixture help this PR? |
|
@twinforcesl thanks for testing. I get the same empty output with Q5_K_M on Metal, and on CUDA and Vulkan on a DGX Spark. Your exact Q5_K_M does the same on Metal. I used three-line images with your text.
The mmproj in that HF repo is missing clip.vision.preproc_min_tiles / preproc_max_tiles, so Unlimited-OCR then uses up to 9 tiles instead of 32: A paired run on a synthetic page won't show the window for the same reason. test-deepseek-ocr.py with bf16 and a fixed mmproj on the Arc would help more. It also needs the DeepSeek-OCR and DeepSeek-OCR-2 GGUFs. |
|
imo the impl is quite too cumbersome, this is not something we can merge rn the newly added notion of "latch" is quite out of place, I don't even fully understand how to use it maybe just simply add a new |
Overview
Adds baidu/Unlimited-OCR to mtmd. It is DeepSeek-OCR v1 with a different decoder attention, R-SWA (Reference Sliding Window Attention): every token sees the whole prompt (image + text) plus the last 128 generated tokens. With plain SWA the image would slide out of view.
Changes:
LLAMA_SWA_TYPE_REFERENCEand its mask rulen_ref) when the first generated token arrives, and keeps it correct across seq_rm / seq_cp / seq_add / seq_div and session save/load (LLAMA_SESSION_VERSIONandLLAMA_STATE_SEQ_VERSIONbumped)llama_model_n_swareturns 0 for this arch so the server does not treat it as SWA-ctvis still honoredOnly single-page parity for now.
Validation
bf16, single page, HF reference in its release config (bf16 weights, R-SWA, CUDA):
Re-validated 2026-08-31 after merging current master.
Design note
R-SWA sits in core (swa type, mask rule,
n_refinllama_kv_cache) and is only enabled for deepseek2-ocr. It could live in the model code instead; open to moving it there.Anyhow my immediate aim is that Unlimited-OCR is supported in llama.cpp with its original R-SWA.
Limitations
The KV cache guesses the prompt end from the first single-token decode that requests output. Where the guess is off:
seq_cpcopies the boundary as-isAn explicit prompt-length signal from the caller (mtmd knows it) would remove the guessing. Open to that as well.
How to run
GGUF models: sabafallah/Unlimited-OCR-GGUF
build/bin/llama-mtmd-cli -hf sabafallah/Unlimited-OCR-GGUF:bf16 \ --image tools/mtmd/test-1.jpeg -p "document parsing." \ --chat-template deepseek-ocr \ --temp 0 --flash-attn off --no-warmup \ -n 4096 -c 16384 \ --dry-multiplier 0.8 --dry-base 1.75 --dry-allowed-length 35 \ --dry-penalty-last-n 128 --dry-sequence-breaker noneRequirements