Repository navigation
fix(vision): use the DeepSeek-VL2 conversation format and tiny MHA decoder - #3505
Merged
Merged
Conversation
inureyes
pushed a commit
that referenced
this pull request
Nov 28, 2026
DeepSeek-OCR and DeepSeek-OCR 2 prompts are now built the way upstream `modeling_deepseekocr.py::infer()` does: the prompt is stripped, `<image>\n` is added per image when the prompt has no marker, each text piece is tokenized without special tokens, and id 0 leads. Grounding prompts now return boxed titles and paragraphs instead of the `4.4.4` failure. Hardening review: merged main locally, compared against upstream, ran fmt, clippy (cuda, all targets) and 457 lib tests on a combined tree with #3505, a revert experiment (6 OCR prompt tests fail without the fix), and real-checkpoint runs on DeepSeek-OCR and OCR 2 whose prompt ids match an upstream-transcribed oracle exactly (898/903 and 1126/1131 tokens). Closes #3481
The disaggregated router refuses any request whose chat renderer produced token ids. Since DeepSeek-VL2 now encodes each turn natively, its text-only requests reach the same refusal, whose message named only Kimi K3. The message now names both formats, and the Unlimited-OCR rationale that was dropped with builtin_template_overrides_checkpoint is restored next to the inlined family check.
Member
Hardening reviewReviewed against #3504 and upstream DeepSeek-VL2 Pushed (
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #3504
DeepSeek-VL2 small now receives its image inside the user turn on both the CLI and the OpenAI-compatible server. Tiny loads its plain multi-head attention (MHA) decoder and generates on NVIDIA GB10. This completes the plain-MHA branch specified in #533. #660 validated small's multi-head latent attention (MLA) branch. The change is based on main
944dbfc2d. Its changes to the vision runtime and model list are on different lines from #3482.sft_formatwith the upstream default ofdeepseek. Render the registereddeepseek,deepseekv2andplainconversations. Insert image markers where their content parts occur. Preserve explicit markers and reject a mismatch with the attachment count.:Ais token 48389). Re-encoding a joined multi-turn string changes the actual model input.Which template and decoder
All three DeepSeek releases and all three 4-bit MLX conversions declare
sft_format: deepseek. Upstream emits one BOS, formats each stripped user question with a blank assistant turn, splits at each image, then separately encodes each historical assistant answer with EOS. A leading system message is encoded on its own. The registereddeepseekv2roles are spelled differently from the literalUsertested by that formatter, so its actual non-empty question ends in EOS.plainemits the user text directly. Upstream processor · Formatter · Registrationsuse_mla=false,kv_lora_rank=null, zero MLA dimensions, separate Q/K/V weightsThe MLX model cards identify the three prince-canuma checkpoints as conversion inputs and mlx-vlm 0.1.5 as the converter. Those inputs already have a separate
chat_template.json. Its decoded string matches the current mlx-vlm processor default for all three sizes (SHA-256 prefixaae9bf506da51538). Small alone also inherits the DeepSeek Coder string intokenizer_config.jsonfrom the original DeepSeek release (8ba1ca9a4c606d3fin the original, intermediate and MLX checkpoint). The converter saves the processor atmlx_vlm/utils.py:768. For a text-only system/user/assistant/user history, the standalone template yielded 19 tokens vs upstream’s 18 on tiny and 25 vs 21 on small. It inserted whitespace around the system message and omitted the EOS after the historical answer. The one-user-turn controls matched at 7 and 8 tokens. Model card · Intermediate template · Conversion code · Current mlx-vlm processorOn main,
src/server/chat_template.rs:443–464gives standalone templates precedence only if they expect typed parts. The standalone VL2 template expects strings, so small selects the Coder template.src/commands/generate.rs:917andsrc/server/chat_request.rs:1061produce a text-only turn.src/multimodal/deepseek_vl2_prompt.rs:66–80inserts the missing image run immediately after BOS. Separately,src/loading/vlm_deepseek_vl2.rs:39–40,117,176assumes small's tokenizer IDs and always builds the V2 decoder. Tiny then fails at the null rank in the non-optional usize at src/models/deepseek_v2.rs:76 before any prompt reaches the model. Upstream makes this architecture choice explicitly at modeling_deepseek.py:1232. Decoder constructionCheckpoint verification
GB10, CUDA 13.0.88, driver 580.178.04, 4-bit tiny
4772de7c, small1ffbe89b, DeepSeek-OCR4958b6b0. One or two copies of the same 1024 × 1024 RGB page (SHA-2565eca426628aab1afa8b67fa1f208d67455dc12b6d4ac0c4bcd21b84f0ffc5500), user textDescribe this image in detail., greedy decoding, 24 tokens.The tested commit is
e4219cdc683d1cdfd648cea654d40c0e6efd2856, tree3365abfa6ac8da735db9a781eef14c4306594dc0. The main CLI and server matched the previous GB10 build's SHA-256 manifest for main treea5d9963e. After switching the private build checkout and touching the changed inputs, the CLI hashes were5c8e96ac5918…(main) and1098eaa58428…(fixed), and the server hashes were88fc0103cc6c…andac28f153a8bb….The CLI dump and live HTTP buffer (read with a debugger on return from image expansion) match the upstream ID arrays at every position. Upstream's token-producing methods ran with the released tokenizer and actual PIL image dimensions. Pixel normalization was omitted in this token-only oracle. Both public mlx-vlm entry points produced those exact IDs for both image counts. A read-only observer recorded the processor's returned inputs during the actual CLI and HTTP requests. Generation on GB10 then failed for two-image CLI requests at deepseek_vl_v2.py:340 (CUDA tile slice requires 32-bit indices). All four HTTP requests returned 500 inside generation.py:1814 → apc.py:171 when the image hash tried to evaluate a tensor on a GPU stream unavailable to the worker thread. These are errors after tokenization. A separate direct
prepare_inputs(prompts=[text], images=[a,b])call fails earlier because the processor zips one prompt with the first image. The scalarprocess_onecall accepts both and yields the upstream IDs. mlx-vlm batch pathThe corrected one-image inputs are shown in full with run-length notation. For a second image insert another identical run and newline immediately after the first run and newline.
Exact main small IDs, CLI and HTTP
Both arrays start with BOS 100000, immediately followed by 100003 repeated 2017 times for one image or 4034 times for two images. Both end with the same 72-token Coder suffix.
Main tiny has no input ID array because loading fails.
Tiny's mlxcel CLI and server and the mlx-vlm CLI returned the same 24 tokens of text about the title and northern distribution network. Small on main described the quarterly report despite the coding template. With the fix it opened “The image is an official document titled …” for one image and “The image displays a document titled …” for two. Stock mlx-vlm on one small image returned
$310.and repeated newlines.The continuation, checkpoint, pixels and full prompt IDs match for each comparison. Small has only one decided position and diverges substantially on the others. Small on main naturally uses different inputs. As a control, a private checkpoint view supplied the corrected single-turn template to the unmodified main binary, with symlinks to the original weights. After verifying all 2032 IDs were identical, every one of its 39 TSV score rows (target, NLL, top-8 IDs and logits) matched the fix byte for byte. Main cannot produce a tiny trace.
Small MLA diagnostic. DeepSeek pairs adjacent elements in its rotary head before rotating. mlxcel's existing MLA path uses interleaved rotation. Stock mlx-vlm small passes its default
rope_traditional=Falseto nn.RoPE on the same weights. In a separate run, changing only that argument in mlx-vlm's MLA attention to true reduced the disagreements from 36/39 to 0/39, including 0/9 decided positions. Reference PPL became 10.1849 versus 10.2473 in mlxcel. This diagnostic uses a modified reference. The stock numbers above are unchanged. DeepSeek rotary layout · mlx-vlm default · mlx-vlm MLA callThe server ran as
mlxcel-server -m "$MODEL" --host 127.0.0.1 --port 18979. The HTTP client posted the same text and 1–2 image_url data-URL parts to/apply-templateand/v1/chat/completionswith temperature 0 and max_tokens 24. Repeating--image "$PAGE"on the CLI supplies image two.The comparison consumes TSV headers and rows after removing the reference processor's six initialization messages. The CLI, HTTP, and reference processes ran serially. Model runs used a 44 GiB RSS watchdog and 25 GiB host-available floor. The first isolated binary could not locate CCCL headers at JIT time. Setting
MLXCEL_CCCL_DIRto the reused headers resolved it.Regression and review checks
cargo fmt --all -- --checkpassed on Spark2.With the new renderer and loader tests copied onto main,
cargo test --locked --profile test-fast --features cuda --lib deepseek_vl2 -- --test-threads=1returned 16 passed and 5 failed. The failures cover tiny's decoder, image formats, explicit/interleaved markers, system/history boundaries and the exact multi-turn request IDs. On the final tree the same command returned 23 passed. With the filter replaced by deepseekocr, got_ocr and unlimited_ocr, it returned 35, 26 and 12 passed, respectively.cargo clippy --locked --workspace --all-targets --features cuda -- -D warningspassed in 7m 20s.python3 scripts/ci/check_used_by.pyresolved 636 caller-file references andbash scripts/ci/check_used_by_test.shpassed all 35 cases. The applicable scripts/ci/check_.py checks and scripts/ci/_test.sh self-tests passed, including 49 WebUI contract fixtures. The Apache header check and 252 Python tooling tests passed. The ROCm overlay and CUDA runtime-directory checks were host-only. Multi-host and ROCm execution were outside this single-GB10 run. The initial WebUI check used the host interpreter, which lacked compatible JSON Schema dependencies. Both normal and self-test modes passed with the isolated dependency set and the existing venv interpreter.TMPDIR="$R/tmp" make verify-test-cudaran to completion with mode 0700 on TMPDIR. Across 196 outer test targets, 17,413 passed, 5 failed, 517 ignored (make exit 2). Two additional one-test summaries in the lib log belong to filtered subprocesses, and are excluded from this total. mlxcel-xla's library had 586 passed and 23 ignored, including its registered-golden check. The DeepSeek-V3.2 YaRN tests passed. Gate peak process-group RSS was 26.64 GiB with 85.48 GiB minimum available and no watchdog intervention.Other gate commands included
python3 scripts/ci/check_webui_contract.pywith and without--self-test,python3 scripts/ci/check_webui_evidence.py --self-test,python3 scripts/insert_apache_header.py --checkandmake verify-rocm-overlay verify-cuda-runtime-dir verify-python-tooling. The remaining check_*.py scripts ran with no arguments and each *_test.sh ran under bash.The five failing tests are
On unmodified main 944dbfc (tree a5d9963e, clean index and worktree),
cargo test --locked --profile test-fast --features cuda -p mlxcel --lib -- --test-threads=1 raon1_mini::speculative raon_mhc::tests::compiled_site_equals_the_eager_site_bit_for_bitreturned 4 passed and the same 5 failed. The sets of fully qualified failure names were compared directly. On the same clean main,cargo test --locked --profile test-fast -p mlxcel-xla --lib -- --test-threads=1independently returned 586 passed, 0 failed and 23 ignored.Verification limits
The final Mac and Spark2 trees matched and both worktrees were clean. The Spark2 directory occupied 51.18 GiB (48.63 GiB in Cargo target). No checkpoint weights were downloaded. Existing CUDA dependencies, checkpoints and the reference environment were reused.
Base was checked against published configs and tokenizer files. Its weights were not loaded. The original DeepSeek implementation supplied the prompt oracle. Numerical comparisons used mlx-vlm's CUDA model on one page and one fixed continuation per size.