Repository navigation
feat(vlm): add SoMark OXR-1.0 (oxr) support - #3536
Conversation
Load the original OXR checkpoint and mlx-vlm exports with Qwen3 and the PaddleOCR vision blocks. Use the decoder context limit for both config spellings and check the tower's GELU variant before loading. Expand and validate literal image markers for CLI and server requests, including operator templates. Suppress the pad and both vision boundary tokens during generation. Cover the processor, rotary positions, visual embedding rows and f16 dtype propagation with small fixtures. Closes lablup#3207.
7efa3ee to
19c4915
Compare
Request images are untrusted. The new test sweeps degenerate, extreme-aspect and u32::MAX sizes through the OXR processor and asserts that each one either fails or lands on an even grid within the max_pixels budget (900 atoms by default), which bounds per-image attention and the soft-vocabulary product.
Hardening reviewReviewed this PR against #3207's acceptance criteria. Detection, loader, sanitize, vision tower, visual tokenizer, processor, wrapper, the Pushed: Shared vision code: the PaddleOCR-VL changes only widen visibility and pass Security: each request image is bounded by the server's decode and image-count limits. After that, Performance: each image's soft tokens are evaluated before the next image starts. The 65,532-way softmax runs in f32 and is released after the product. Full attention per image is quadratic, as in the reference. Local validation (remote CI cancelled by maintainer decision):
Not verified on this Mac: no OXR or PaddleOCR-VL checkpoint is present, so I ran no real-model generation, and any checkpoint-gated parity tests skip. The contributor's GB10/CUDA checkpoint results above stand as reported. |
# Conflicts: # CHANGELOG.md # NOTICE # src/execution/config_fields.rs # src/loaded_model_capabilities.rs # src/loading/vlm.rs # src/models/detection_tests.rs # src/server/chat_template.rs # src/vision/mod.rs
#3573) ## Summary Every lib test that drives `batched_decode_harness` now takes `mlx_test_guard()` as its first statement, so the model-owned multistep and native batched-decode tests no longer run in parallel and abort in `cudaStreamEndCapture`. The guard stays out of the harness because it is a non-reentrant `Mutex`. The re-run sweep found 87 unguarded tests, not the 54 in the issue. The extra 33 are: - Tests that call a same-file helper which drives the harness (cohere2, gemma3n, mixed-cache, wrapper and VLM delegation tests, and others). - Macro-generated tests (`fn $name`) in `llama_runtime_tests.rs` (tensor-parallel Llama) and `popular_dense_batched_decode_tests.rs`. - Tests holding only a private mutex that does not exclude the other MLX tests: `cohere2_tests.rs` and `cohere2_moe_tests.rs` now take the shared guard before their local lock, and the popular-dense macro uses the shared guard in place of its private one. - A gemma4 test with an `#[ignore]` attribute between `#[test]` and `fn`. Helpers that already take the guard internally were left alone, so nothing takes it twice. ## New test `tests/mlx_test_guard_coverage.rs` is a dependency-free text scan of `src/`. It flags any `#[test]` that calls a harness function (qualified or imported), directly or through a same-file helper that does not take the guard, and lists the offenders. A second test checks the scanner on small fixtures. ## Verification - Revert check: with `src/` restored to main, the scan fails and lists 87 tests; with this change it passes. - `cargo clippy --lib --tests --features cuda -- -D warnings` clean, `cargo fmt --all -- --check` clean, the five CI contract scripts pass. - `cargo test --profile test-fast --features cuda --bin mlxcel`: 363 passed. - Narrow lib selectors for a sample of the touched modules under `gpu-lock` : 65 passed, 0 failed, 8 ignored (popular_dense, cohere2, afmoe, inkling tiny, wrapper_batched_decode, mixed_cache, mixtral_style). - Full CUDA lib suite at default parallelism: the first run aborted in `cudaStreamEndCapture` inside `audio::` tests that do not use the harness (`audio::fastconformer` aborts 6 of 6 parallel runs on its own). That is a wider pre-existing problem, now #3574, so the issue's third acceptance criterion moves there (see the comment on #3567). Metal was not available on this host. - After rebasing onto main with #3536 (SoMark OXR): the scan test, contract scripts, fmt, clippy, `--bin mlxcel` (363 passed) and the selectors popular_dense_batched, cohere2 and oxr pass. Closes #3567
Summary
Closes #3207.
Load and serve SoMark OXR-1.0 from the original checkpoint or either pinned mlx-vlm conversion. OXR reuses the Qwen3 decoder and PaddleOCR-VL's patch embedding and transformer blocks. Its vision path adds bicubic position resizing, merge-block patch and rotary order, and the soft visual vocabulary with separate start/end indicator rows.
The loader accepts both pairs of nested config names, carries decoder quantization into Qwen3, reshapes the original convolution weights and accepts already-converted tensors. It rejects unknown original visual-tokenizer keys and packed visual weights by name. The CLI and HTTP request paths share the rendered prompt and embedding preparation. The request validator checks one literal
<image>per image, including for custom templates. Sampling suppresses the pad and both vision boundary tokens. The original checkpoint declares 40,960 positions at the top level and 32,768 inllm_config. mlx-vlm passes the latter to Qwen3, so both config spellings use the decoder’s 32,768-token default.The reviewed commit is
7efa3ee22ad24698150771f02acee4ec825542bf(tree0abbd1b2521edf4c13fc1e25329ee06de43e6a5d), based on3cc7e213d. Verification hardware was NVIDIA GB10 (DGX Spark), CUDA 13 / sm_121, NVIDIA driver 580.178.04 and Rust 1.97.1.Checkpoint verification
c708407f9d2b4df658f2543d9132b62bb7221df40f20839a945ea0a3e6bbb2dfdb80a3c2c16bd44c943bd67406639a292bda9802bcaccbe1ff0ed8e3These are single-run decode measurements on a GB10 shared with another GPU workload. Original bf16 generated 24 tokens on the formula and 53 on the table. All three produced the same formula. The vendor Python files were inspected as text. Both converted checkpoints retain
llm_configandvit_configin their actual configs.The original produced the following completions, byte-identical to
mlx_vlm.generateafter removing CLI presentation framing. The reference was mlx-vlm230fc308efb577d87446306bfb8a3e9f1a129558. Its four OXR module files match upstreama0b9352eby SHA-256.Formula, 46 bytes
Table, 117 bytes
A loopback
POST /v1/chat/completionswith animage_urlcontent part returned HTTP 200 and the same 46 formula bytes. A two-image request returned 200. The CLI processed a 1×1 transparent image (217 prompt tokens, immediate EOS) and a 960×960 image (900 visual atoms, 921 prompt tokens, four generated tokens at the requested cap). The image-free promptWrite the number two.ended immediately in both implementations. The CLI returned an error and HTTP returned 400 with both counts for an extra marker and for an image with no marker. The latter used a template override on the server.Teacher-forced parity
The Rust and Python traces independently rendered identical prompt IDs (232 for formula, 237 for table). They scored the same fixed continuation within each pair. “Decided” follows
compare_logit_traces.pywith reference top-two gap ≥2. The deltas below are absolute differences on the reference's top choice. The fp32 oracle casts the original dense weights to fp32.Implementation and review
cargo fmt --all -- --check. Ran the Used-by checker and its self-tests. Verified the commit-range checker’s bare references against lablup/mlxcel issues feat(vlm): add SoMark OXR-1.0 (oxr) support #3207 (OXR), fix(models): decide the GELU formula for the families #2423 left open #2548 (GELU) and perf(models): prefill projects every position through the LM head in most models #3070 (prefill LM-head projection).Scope and attribution
The shared Qwen helper inserts already-tokenized markers. OXR replaces literal
<image>before tokenization, so expansion lives with the OXR wrapper and uses the existing template and multimodal runtime. Detection coversmodel_type: oxrunder both nested config spellings. The processor resizes each image to a single patch grid. Layout detection, reading-order reconstruction and video are outside the OXR model path.mlxcel's OXR implementation translates mlx-vlm’s MIT-licensed OXR code. No SoMarkAI/OXR source code is copied. The OXR license governs the checkpoint and its use. NOTICE reproduces it for users who redistribute or serve the model. Section 1 sets a USD 2 million threshold for total funding or annual revenue and exempts personal use and non-commercial research from that section. Section 2 requires linked attribution when providing the model to third parties without a separate license. Section 3 covers termination. Section 4, “Definitions and Scope,” includes the requirement to ship the additional terms with Apache-2.0 when redistributing the model or its derivatives. OXR license
Verification limits
No Apple Silicon Mac was available for model validation. On Apple Silicon the dense original bf16 checkpoint loads in f16 by default, including the vision tower, projection and 65,532-column LayerNorm. Formula and table parity on Metal remains unmeasured.
MLXCEL_KEEP_BF16=1keeps the checkpoint dtype for a diagnostic comparison. ROCm was also untested. The full-checkpoint parity sample comprises two document pages.Commands and test results
On the pre-review implementation
e406dbdb9, the new sampling assertion returned[]instead of[60, 61, 62], and the context-window assertion returned 40,960 instead of 32,768. Both regression assertions passed after the fixes. The synthetic f16 test passed on CUDA before and after the changes. It checks the tower output, soft visual tokens and merged decoder embeddings for f16 dtype and finite values, and compares the merged pad rows with the visual tokens.All 14 OXR tests and all 8 dots.ocr tests passed. The Qwen filters passed 44 (
qwen_vl), 36 (qwen2_vl), 21 (qwen2_5_vl) and 80 (qwen3_vl), with 11, 0, 1 and 1 ignored respectively. The chat-template filter passed 206 with 5 ignored, and chat-request passed 145 with 2 ignored. PaddleOCR (26), Mage-VL (30), batched-decode coverage (14), model metadata (8) and KV architecture (63) also passed. Counts are per filter and can overlap. Formatting and workspace Clippy passed.The original detection and layer red runs predate the rebase onto
3cc7e213d. Onf0d06f5e, detection failed withUnsupported model type: oxr. The layer tests could not compile against the then-missing OXR APIs.The server command was
"$BIN/mlxcel-server" -m "$M" --host 127.0.0.1 --port "$PORT", with a loopback port assigned by the OS. The client queried/v1/modelsfor the returned model ID and posted this JSON to/v1/chat/completions, substituting the PNG bytes and model ID:{"model":"<model ID>","messages":[{"role":"user","content":[{"type":"image_url","image_url":{"url":"data:image/png;base64,<formula PNG>"}},{"type":"text","text":"Recognize the formula of the image into KaTex format."}]}],"temperature":0,"max_tokens":512}Formula continuation:
a^{2}+b^{2}=c^{2}. Table continuation:<table><thead><tr><td>Item</td><td>Count</td></tr></thead><tbody><tr><td>Pens</td><td>12</td></tr><tr><td>Books</td><td>3</td></tr></tbody></table>.All 33 repository CI checks passed after one retry. The synthetic ROCm guard timing test missed its simulated process during the first Python tooling run. The full retry passed all 270 Python tests, and the same isolated test passed on the unmodified parent.
The five historical Raon failures on main were fixed by #3476, which is in this branch’s parent.
make verify-test-cudawith a private 0700TMPDIRon the reviewed tree0abbd1b2521edf4c13fc1e25329ee06de43e6a5d: 17,669 passed, 0 failed, 517 ignored. The worktree tree was the same before and after the run.33 repository CI checks
Exact formula and table PNG inputs
This Python snippet reconstructs the two input files and verifies their SHA-256 digests.