Repository navigation
fix(vision): build the DeepSeek-OCR prompt as the reference does - #3482
Merged
Merged
Conversation
deepseek-ai/DeepSeek-OCR's `infer()` takes a prompt that already names the
page (`<image>\nFree OCR.`), strips it (`format_messages`, 'plain' format),
splits it on `<image>`, tokenizes each piece without special tokens and puts
id 0 first. For `Free OCR.` on a 1920x1280 page that is
0, <image> x 893, 201 '\n', 21431 'Free', 126041 ' OCR', 16 '.'
mlxcel rendered the instruction through the template the MLX conversions
ship (mlx-vlm's `{{message['content']}} `, a space after every message) and
spliced the image run after BOS, so the model read
0, <image> x 893, 21431 'Free', 126041 ' OCR', 16 '.', 223 ' '
with no newline after the page and a space token the reference never feeds.
mlx-vlm renders the same template but ends up with the reference ids: it
formats the message as `<image>\n` + text and its processor drops the last
id. DeepSeek-OCR 2 is built by the same upstream code and had the same
prompt.
With the model card's document prompt, `<|grounding|>Convert the document to
markdown.`, the difference decides the output: on DeepSeek-OCR-4bit a
1600x1200 page came back as `4.4.4.4...` and a dense table as
`21 21 21...`, and the other three pages lost the `<|ref|>...<|det|>` box
and heading of their title block (one of them every box), where mlx-vlm
returns the grounded markdown.
`prepare_deepseekocr_prompt_tokens` now builds the prompt for both families
from the rendered text, in the prompt module, the way GOT-OCR and FastVLM
re-tokenize theirs: strip, put one `<image>\n` per page in front when the
text names no `<image>` itself, split on `<image>`, tokenize the pieces,
BOS first. A prompt that already writes `<image>` is only stripped, so the
model card's `<image>\nFree OCR.` and the bare instruction give the same
ids and nothing is doubled. `mlxcel generate`, `mlxcel-server` and
`examples/logit_trace` all go through it.
Unlimited-OCR keeps its own layout (one `<image>` for all pages, no
newline), GOT-OCR its own conversation, and a text-only request is not
touched. A prompt whose own `<image>` count does not match the pages is
left as before.
Eight tests in `deepseekocr_prompt.rs`; against main's behaviour behind the
new functions, six fail (the ids end in 223, and have no 201 unless the
caller wrote the marker) and the two guards (marker count mismatch,
Unlimited-OCR) pass.
On GB10 CUDA the prompt ids equal mlx-vlm e8035ae3's on five pages for
DeepSeek-OCR-4bit and two for DeepSeek-OCR-2-4bit. The 160-token `Free OCR.`
replies are byte-identical to the float32 reference's on all eight
page/model pairs, and the DeepSeek-OCR markdown replies differ from it only
in box coordinates, by at most 2. A teacher-forced trace against that
reference has no disagreement at a decided position on any of the nine
traces (main: one on five of them) and a perplexity within 0.3% of it
(main: 2.6% to 11.9% higher). Unlimited-OCR-4bit, GOT-OCR2_0-4bit and
deepseek-vl2-small-4bit output is byte-identical before and after.
8 tasks
4 of 5 tasks
This was referenced Nov 28, 2026
inureyes
pushed a commit
that referenced
this pull request
Nov 28, 2026
…coder (#3505) DeepSeek-VL2 chat requests are now rendered with the model's own conversation format (`deepseek`, `deepseekv2`, `plain`) and encoded per turn as upstream `format_messages_v2` does, with typed image markers. The tiny variant, whose config has `use_mla:false`, now loads through the MHA decoder in `models::deepseek`. The disaggregated router's refusal for natively tokenized prompts now names DeepSeek-VL2 alongside Kimi K3. Hardening review: merged main and #3482 locally, compared against upstream at `ef9f91e2`, ran fmt, clippy (cuda, all targets), 457 lib tests, a revert experiment (loader and renderer tests fail without the fix), and real-checkpoint runs on VL2 tiny and small whose prompt ids match an upstream-transcribed oracle exactly (2030/4048 and 2032/4050 tokens). Closes #3504
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 #3481
DeepSeek-OCR and DeepSeek-OCR 2 read a prompt their reference never builds: the image run sat directly after BOS with no
\nbehind it, and the prompt ended in the space the shipped chat template prints after every message. ForFree OCR.on a 1920x1280 page:<image>)deepseek-ai/DeepSeek-OCRinfer()with<image>\nFree OCR., and mlx-vlme8035ae3withFree OCR.0, [128815 x 893], 201 '\n', 21431 'Free', 126041 ' OCR', 16 '.'main0, [128815 x 893], 21431, 126041, 16, 223 ' '0, [128815 x 893], 201, 21431, 126041, 16The prompt for the two families is now built in
src/multimodal/deepseekocr_prompt.rsthe way upstream'sinfer()builds it: strip the rendered text, put<image>\nin front when the text names no<image>itself, split on<image>, tokenize the pieces without special tokens, BOS first. Unlimited-OCR, GOT-OCR and DeepSeek-VL2 are untouched and byte-identical.On GB10 CUDA with
mlx-community/DeepSeek-OCR-4bitandmlx-community/DeepSeek-OCR-2-4bit:e8035ae3's in all nine teacher-forced traces (five pages withFree OCR.and two with the document prompt on DeepSeek-OCR, two pages on DeepSeek-OCR 2).<|grounding|>Convert the document to markdown.,mainreturns4.4.4.4...for a 1600x1200 page and21 21 21...for a dense table, and drops the title block's<|ref|>...<|det|>box on the other three pages (every box on one of them). With this PR all five replies have the reference's text and boxes, the coordinates within 2 of the float32 reference's.Free OCR.the 160-token reply is byte-identical to the float32 reference's on all five DeepSeek-OCR pages and all three DeepSeek-OCR 2 pages.maintranscribes nearly the same text but opens every reply with a space, and on four of the eight it changes or drops the heading marks (**Northern Network: Q3 Operations**where the reference writes## **Northern Network: Q3 Operations**).main: one in five of them), perplexity within 0.3% of the reference (main: 2.6% to 11.9% higher), largest logit delta on the reference's choice 0.55 to 1.79 (main: 1.42 to 9.89).main's prompt ids scores likemain(perplexity within 0.3% ofmain's, no decided disagreement), so the gap is the prompt and not the port.One page does not improve: on the dense table page
Free OCR.makes the reference itself loop (| Shipment | Shipment | ...), and this PR reproduces that loop byte for byte. See "Verification limits".What changed
src/multimodal/deepseekocr_prompt.rsdeepseekocr_prompt_text(prompt, num_images): the text upstream tokenizes. The rendered prompt is stripped (upstream'sformat_messagesstrips the message and the assembled prompt). If it contains no<image>, one<image>\nper image goes in front, which is mlx-vlm'sMessageFormat.IMAGE_TOKEN_NEWLINEfordeepseekocr/deepseekocr_2and the shape of every prompt on the two model cards. If it does contain<image>, it is used as written, so<image>\nFree OCR.is not prefixed a second time.prepare_deepseekocr_prompt_tokens(prompt_tokens, prompt, counts, image_token_id, encode): splits that text on<image>, tokenizes each piece withadd_special = false, expands markeritocounts[i]placeholder ids and putsDEEPSEEKOCR_BOS_TOKEN_ID(0, upstream's literalbos_id = 0) first. It replacesprompt_tokenson success. When the text's own<image>count does not match the number of images it returnsNoneand leaves the tokens alone, which is whatinsert_deepseekocr_image_tokensdid for that case.insert_deepseekocr_image_tokensandinsert_unlimited_ocr_image_tokensare unchanged; HunyuanVL and Unlimited-OCR still call them.src/multimodal/vlm_runtime.rs: theVlmRuntimeRef::DeepSeekOcrandVlmRuntimeRef::DeepSeekOcr2arms ofprepare_vlm_embeddings_with_cachecall the new builder with the renderedpromptand theencodeclosure, like the GOT-OCR and FastVLM arms do.mlxcel generate(server::local_media::prepare_local_vlm_embeddings),mlxcel-server(server::model_worker::prepare_request_vlm_embeddings) andexamples/logit_traceall reach this function, so the three build the same prompt.docs/supported-models.md: one sentence in the DeepSeek-OCR entry on how the prompt is built.The checkpoint's chat template is not replaced. It still renders
Free OCR.; the builder strips it. So #3473'sdeepseek_ocr_keeps_its_shipped_templatestays true, and nothing insrc/server/chat_template.rschanges.Choices that differ from mlx-vlm
Upstream is the reference where the two disagree:
<image>. Upstream takes it as written. mlx-vlm prefixes another<image>\nand then rejects the request (The number of image tokens in the prompt does not match the number of images: 2 != 1). Here-p $'<image>\nFree OCR.'and-p "Free OCR."give the same ids, and<image>Free OCR.(no newline) gets none, as upstream would give it.Free OCR.\nends in603 '.\n'there, because the id its processor drops is the template's space) and a leading one. HereFree OCR.\n,Free OCR.andFree OCR.all become the ids ofFree OCR..infer()only ever builds one user message.Not changed:
21431, 126041, 16, 223); upstream would strip it. The image-less path does not go through the prompt builder.<image>for all pages and no newline (mlx-vlmSINGLE_IMAGE_TOKEN), which is where the run already goes. Its trailing space was fixed by fix(vision): match the Unlimited-OCR processor crop limit and prompt #3473.modeling_GOT.py::chat(got_ocr_prompt.rs).CHANGELOG.md: no entry yet, since the issue number does not exist until the issue is filed.Verification
Spark2: NVIDIA GB10, driver 580.178.04, CUDA 13.0.88, Linux 7.0.0-1019-nvidia aarch64, rustc 1.97.1 (the pinned toolchain),
--features cuda,--profile test-fast,MLX_ENABLE_TF32=0 MLXCEL_SDPA_DETERMINISTIC=1. Base92d502ec0b8bd6f59e44788d57126ae3226d0ada. Commit treeec2c9bd60edec179fda74d489cad7eb362257459, the tree the unit tests, the binaries, clippy and the test gate ran on.mainmoved twice while this was being verified (521ba0f71->2b34a2f7a->92d502ec0), and the change was rebased and rerun each time. The numbers below are from the last base unless a line says otherwise; the two earlier runs are in "Earlier bases".mainhas since moved once more, toef0076b96(#3462).git merge-tree --write-treeof this commit with it has no conflict; nothing was rerun there.cargo fmt --all -- --checkcargo clippy --locked --workspace --all-targets --features cuda -- -D warningspython3 scripts/ci/check_used_by.py(used-by: OK, 78 top-level pub fn in 2 shared files, 57 annotated, 636 caller-file references resolved, 3165 Rust files scanned),bash scripts/ci/check_used_by_test.sh(all used-by checker cases passed),python3 scripts/insert_apache_header.py --check,python3 scripts/ci/check_env_var_docs.py,python3 scripts/ci/check_kernel_dtype_keys.py,python3 scripts/ci/check_cross_repo_refs.py(no bare 3+-digit '#NNN' added). The two used-by scripts and the cross-repo check also pass on the macOS worktree of the commit.The eight new tests (table below) and the related filters.
make verify-test-cudawith a private 0700TMPDIR(13:40 to 14:07): 17,383 passed, 5 failed, 517 ignored over 199test resultlines, treeec2c9bd6before and after. A memory guard (stop the test binary under 25 GiB available) did not trip; the lowest available memory was 63 GiB. The five failures are lib tests in Raon code this PR does not touch. Each, run alone with--exact, fails with the same message on unmodified92d502ec0and on this commit:models::raon1_mini::speculative::tests::{a_steered_verify_block_applies_the_alpha_exactly_as_decode_does, a_verify_block_equals_the_decode_chain_byte_for_byte, rollback_after_a_partial_accept_equals_a_fresh_decode_of_the_accepted_tokens, the_exactness_probe_passes_on_the_tiny_model}(the four fix: Raon-1 mini correctness and validation follow-ups #3457 listed; fix: Raon-1 mini correctness and validation follow-ups #3457 is closed and they still fail on this GB10 host)models::raon_mhc::tests::compiled_site_equals_the_eager_site_bit_for_bit(d 64 seed 0 dtype 12 rows 1: h_res, bytes off by one in the last place). I found no issue for it (gh search issuesfor the test name and forraon_mhc);src/models/raon_mhc_tests.rswas last changed by feat(perf): speed up Raon-1 mini decode, load and prompt reuse #3461.models::deepseek_v32::rope_tests::prefill_and_decode_cache_yarn_rotated_keys_past_the_original_context(fix(cuda): rotate broadcast RoPE inputs in a dense output #3443) and the twomlxcel-xlaplamo2 golden tests (fix(xla): refresh the plamo2 prefill goldens for the shifted-add scan #3471) pass on this base.Before a quiet enough window for the gate came up, the same test set was also run as thirteen processes (the other workspace packages;
mlxcel's bins and its 170 integration tests withoutrequired-features; doc tests; the 13,345 lib tests in ten--exactchunks). It gave the same totals and the same five failures.fix(vision): match the Unlimited-OCR processor crop limit and prompt #3473 and fix(vision): match DeepSeek-OCR CLIP and SAM encoder numerics #3456 merged while this was in progress and are both in the base. Before that,
git merge-tree --write-treeagainst each (cbb0ec529,e287f903e) was clean.Tests
cargo test --locked --profile test-fast --features cuda -p mlxcel --lib -- <name> --exact --test-threads=1, all inmultimodal::deepseekocr_prompt::tests. The "main" column ismainplus the new tests, with the two new functions stubbed tomain's behaviour so the tests compile:deepseekocr_prompt_textreturns the text unchanged andprepare_deepseekocr_prompt_tokenscallsinsert_deepseekocr_image_tokenson the tokens the front produced.deepseekocr_free_ocr_prompt_has_the_reference_idsleft: [0, 128815, 128815, 128815, 21431, 126041, 16, 223],right: [0, 128815, 128815, 128815, 201, 21431, 126041, 16]deepseekocr_grounding_prompt_has_the_reference_idsleft: [0, 128815, 128815, 128820, 21842, 270, 4940, 304, 2121, 7919, 16, 223],right: [0, 128815, 128815, 201, 128820, 21842, 270, 4940, 304, 2121, 7919, 16]deepseekocr_explicit_image_marker_is_not_doubledleft: [0, 128815, 128815, 201, 21431, 126041, 16, 223],right: [0, 128815, 128815, 201, 21431, 126041, 16]deepseekocr_prompt_is_stripped"Free OCR.\n ":left: [0, 128815, 21431, 126041, 16, 223],right: [0, 128815, 201, 21431, 126041, 16]deepseekocr_each_page_gets_its_own_markerleft: [0, 128815 x 5, 21431, 126041, 16, 223],right: [0, 128815, 128815, 201, 128815, 128815, 128815, 201, 21431, 126041, 16]deepseekocr_prompt_text_adds_markers_only_when_absentleft: "Free OCR. ",right: "<image>\nFree OCR."deepseekocr_marker_count_mismatch_leaves_the_tokens_aloneunlimited_ocr_prompt_has_no_newline_after_the_imageThe test encoder is a lookup table of the pieces the builder may tokenize, with the ids the checkpoints'
tokenizer.jsongives them (the file is byte-identical, sha256a02f8fd5..., indeepseek-ai/DeepSeek-OCR,deepseek-ai/DeepSeek-OCR-2and the twomlx-community4-bit conversions). It panics on any other piece, so a stray space or a second<image>\nfails the test rather than mapping to something.Related filters on the committed tree, all passing:
deepseekocr43,unlimited_ocr13 (with #3473'sdeepseek_ocr_keeps_its_shipped_template),deepseek_vl214,got_ocr26,got_chat_template5,chat_template199 (5 ignored),vlm_runtime65,fastvlm6,hunyuan33,multimodal::388 (28 ignored),builtin_template6.Real checkpoints
mlx-community/DeepSeek-OCR-4bitrevision4958b6b0,mlx-community/DeepSeek-OCR-2-4bit378131e9,mlx-community/Unlimited-OCR-4bit945968c0,mlx-community/GOT-OCR2_0-4bit0e28c877,mlx-community/deepseek-vl2-small-4bit1ffbe89b. Reference: mlx-vlme8035ae3(mlx 0.32.4 CUDA) anddeepseek-ai/DeepSeek-OCRrevision9f30c71f/deepseek-ai/DeepSeek-OCR-2revisionaaa02f38. Five synthetic pages: the 1024x1024, 1600x1200 and 1920x1280 report pages and the 1920x1280 dense table from #3456, and the 1000x3000 notice from #3473. Temperature 0, 160 tokens. Every model and reference process ran alone under a watchdog (stop below 25 GiB available or above an RSS bound), never beside a build; none tripped.Prompt ids
MLXCEL_PRINT_TOKEN_IDS=1 mlxcel generate, DeepSeek-OCR, 1920x1280 page,I= the run of 893 image tokens. The upstream column is a transcription ofinfer()'s steps (strip, split on<image>, tokenize each piece without special tokens, id 0 first) run on the checkpoint'stokenizer.json; the upstream modules themselves were not executed. The mlx-vlm column is its processor on CPU with no weights loaded.-pmainFree OCR.0, I, 21431, 126041, 16, 2230, I, 201, 21431, 126041, 160, I, 201, 21431, 126041, 16for<image>\nFree OCR.<|grounding|>Convert the document to markdown.0, I, 128820, 21842, 270, 4940, 304, 2121, 7919, 16, 2230, I, 201, 128820, 21842, 270, 4940, 304, 2121, 7919, 16<image>\n<|grounding|>...<image>\nFree OCR.0, I, 201, 21431, 126041, 16, 2230, I, 201, 21431, 126041, 162 != 1image tokens)<image>\nFree OCR.(README form)0, I, 201, 21431, 126041, 16, 2620, I, 201, 21431, 126041, 16Free OCR.\n0, I, 21431, 126041, 603, 2230, I, 201, 21431, 126041, 16<image>\nFree OCR.\n0, I, 201, 21431, 126041, 603<image>Free OCR.0, I, 21431, 126041, 16, 2230, I, 21431, 126041, 16201 is
\n, 223 one space, 262 two spaces, 603.\n. With this PR the first, third, fourth and fifth prompt give the same ids and the same reply, byte for byte.DeepSeek-OCR 2 on the same page (1121 image tokens):
main0, I, 21431, 126041, 16, 223, this PR0, I, 201, 21431, 126041, 16, the ids of mlx-vlm's processor.examples/logit_traceprints the same# prompt_idsas the CLI on both builds, andscripts/mlx_vlm_image_logit_trace.py(without--mlxcel-prompt) prints the reference's. This PR's line equals the reference's in all nine traces;main's equals it in none.mlxcel-serverdoes not print prompt ids. One/v1/chat/completionsrequest each (image part, then text part) reportsusage.prompt_tokens898 (Free OCR., 1600x1200), 903 (document prompt) and 1126 (DeepSeek-OCR 2), the CLI's counts, on both builds. With this PR the three server replies are byte-identical to the CLI's. Onmainthe document-prompt reply is byte-identical to the CLI's (4.4.4...), and the twoFree OCR.replies equal the CLI's once the CLI's leading space is removed.Free-running output
mlxcel generate, document prompt, DeepSeek-OCR. Each cell is the first line of the reply; the last column counts the<|det|>blocks in the whole 160-token reply.mainNorthern Network: Q3 Operations<|ref|>sub_title<|/ref|><|det|>[[37, 41, 562, 71]]<|/det|><|ref|>sub_title<|/ref|><|det|>[[37, 41, 562, 71]]<|/det|>4.4.4.4.4.4.4...(all 160 tokens)<|ref|>sub_title<|/ref|><|det|>[[41, 58, 592, 100]]<|/det|><|ref|>sub_title<|/ref|><|det|>[[41, 58, 592, 101]]<|/det|>Northern Network: Q3 Operations<|ref|>sub_title<|/ref|><|det|>[[40, 62, 558, 108]]<|/det|><|ref|>sub_title<|/ref|><|det|>[[40, 62, 558, 109]]<|/det|>21 21 21 21 21...(all 160 tokens)<|ref|>title<|/ref|><|det|>[[20, 22, 391, 46]]<|/det|><|ref|>title<|/ref|><|det|>[[18, 21, 391, 46]]<|/det|>1. ScopeThis notice covers the replacement ...(the title is missing)<|ref|>sub_title<|/ref|><|det|>[[66, 24, 840, 45]]<|/det|><|ref|>sub_title<|/ref|><|det|>[[67, 24, 840, 46]]<|/det|>On all five pages this PR's reply and the reference's are the same text once the numbers inside
<|det|>[[...]]<|/det|>are masked, with the same number of boxes and every coordinate within 2.Free OCR.:main**Northern Network: Q3 Operations**...Northern Network: Q3 Operations...)Northern Network: Q3 Operations...Northern Network: Q3 Operations... (the reference's text behind one space)| | | | | ...(all 160 tokens)| Shipment | Shipment | Shipment | ..., all 160 tokens)# Dock Door Replacement Notice...# Dock Door Replacement Notice...)**Northern Network: Q3 Operations**...## **Northern Network: Q3 Operations**...)**Northern Network: Q3 Operations**...# **Northern Network: Q3 Operations**...)**Dock Door Replacement Notice**/**1. Scope**...# Dock Door Replacement Notice/## 1. Scope...)DeepSeek-OCR 2 with the document prompt (float32 reference made for these three pages too): on 1600x1200 and 1920x1280
mainalready returns the grounded layout (4 boxes, coordinates within 3 of the reference; this PR within 2), so the prompt did not break those two. On 1000x3000mainreturns plain text with no box (1. Scopefirst, the title missing) and this PR returns the reference's text and five boxes, coordinates within 6.Teacher-forced trace
examples/logit_trace MODEL REPLY 128 1 8withMLXCEL_TRACE_IMAGE/MLXCEL_TRACE_IMAGE_PROMPT, over the float32 reference's own greedy reply (128 positions), againstscripts/mlx_vlm_image_logit_trace.py --float32on mlx's CUDA device. Decided positions are those where the reference's top-two gap is at least 2 logits.ref(main prompt)is the same reference script scoringmain's prompt ids (--mlxcel-prompt).Free OCR.mainmainFree OCR.mainmainFree OCR.mainmainFree OCR.mainmainFree OCR.mainmainmainmainmainmainFree OCR.mainmainFree OCR.mainmainReading it: against the reference on its own prompt,
mainis 2.6% to 11.9% worse in perplexity and disagrees at a decided position in five traces (the reference's gap there is 2.0 to 6.4); this PR is within 0.3% and disagrees at none. The reference givenmain's prompt lands wheremaindoes (the third row of each block: no decided disagreement, perplexity within 0.3%), and its own distance from itself across the two prompts (the fourth row) is the distancemainshows. So the difference betweenmainand the reference is the prompt.A teacher-forced trace understates the free-running effect: it scores each position behind the reference's own tokens, so the
4.4.4...reply shows up here as one decided disagreement at the first position.Controls
mlxcel generate,mainvs this PR, prompt ids and reply:Free OCR.OCR:Describe this image in detail.The Unlimited-OCR and GOT-OCR traces (128 positions over the reply) are row-for-row identical between the two builds, and so is the Unlimited-OCR server reply.
Watchdog, over the three runs: 268 model and reference processes (113, 79 and 76), largest RSS 4.97 GiB, no trip. The lowest available memory seen during a run was 26.9 GiB, in the first run, while another job's vLLM engines held about 53 GiB; in the last run it was 68.5 GiB. Exit codes other than 0 were the servers stopped with TERM after their one request (24) and
deepseek-vl2-tiny-4bit, which neither build loads (2).Earlier bases
521ba0f71(before fix(vision): match DeepSeek-OCR CLIP and SAM encoder numerics #3456, fix(cuda): rotate broadcast RoPE inputs in a dense output #3443 and fix(vision): match the Unlimited-OCR processor crop limit and prompt #3473). Same code, built from the working tree before two comment lines and the docs sentence were touched. Same prompt ids on both builds, same picture: with the document promptmainreturned4.4.4...(1600x1200) and0 1 1 1...(dense table); this change had no decided disagreement in the nine traces andmainone in four. The encoder differences fix(vision): match DeepSeek-OCR CLIP and SAM encoder numerics #3456 fixed were still there, so this change's replies were close to the reference's rather than identical (perplexity -0.2% to +3.6%, logit delta up to 12.6), and on the dense table withFree OCR.mainon that base transcribed the rows while the reference and this change looped on a table header.2b34a2f7a(with fix(vision): match DeepSeek-OCR CLIP and SAM encoder numerics #3456). Tree63eeeec1: the eight tests and the same related filters passed, and the full real-checkpoint run gave the replies, prompt ids and trace numbers shown above; the run on92d502ec0reproduced every DeepSeek-OCR, DeepSeek-OCR 2, GOT-OCR and DeepSeek-VL2 reply and prompt byte for byte and the same trace summary. Only Unlimited-OCR moved between the two bases, by fix(vision): match the Unlimited-OCR processor crop limit and prompt #3473, equally on both builds (898 tokens and a date line before, 897 tokens and the title box after). On this base fix(vision): match the Unlimited-OCR processor crop limit and prompt #3473's patch (cbb0ec529) was also applied on top of the change, before it merged: both PRs' tests passed together (multimodal::deepseekocr_prompt12,unlimited_ocr_chat_template_tests3,deepseekocr43,unlimited_ocr13,chat_template197).# prompt_idsline was checked against the reference trace's.Verification limits
Free OCR.gets no better. mlx-vlm, in bf16 and in float32, answers it with| Shipment | Shipment | Shipment | ...for all 160 tokens, and this PR now does exactly that.mainon the current base loops too (| | | | ...); on521ba0f71it transcribed the rows. Matching the reference means matching this as well. With the document prompt the same page is transcribed as a table.deepseek-aiids come from a transcription ofinfer()'s prompt steps applied to the checkpoint'stokenizer.json; I did not execute the upstream modules or load the PyTorch checkpoints. mlx-vlme8035ae3is the reference that actually ran, and its ids equal the transcription's wherever both exist.mlxcel-serverprints no ids; the evidence isusage.prompt_tokensequal to the CLI's count and replies byte-identical to the CLI's.<image>\n<image>\nFree OCR., one run and one newline per image, from upstream's split loop). My two-image probe of mlx-vlm's processor raised an error, and I ran no multi-image request on a checkpoint. A multi-turn conversation was not run either.trim()is not Python'sstrip()for U+001C..U+001F, which Python strips and Rust does not. No prompt here contains them.modeling_GOT.py, which the MLX conversion does not ship). Its prompt code is untouched and its ids, reply and trace rows are identical before and after.cargoprocess; before that, a few processor-only probes (no weights, CPU, under 1 GiB) ran while this task's own first build was in progress.deepseek-vl2-small-4bitis byte-identical before and after.