Skip to content

feat(vlm): add SoMark OXR-1.0 (oxr) support - #3536

Merged
inureyes merged 4 commits into
lablup:mainfrom
Jaeyeong-CHOI:feat/3207-oxr
Nov 30, 2026
Merged

inureyes merged 4 commits into
lablup:mainfrom
Jaeyeong-CHOI:feat/3207-oxr

Conversation

@Jaeyeong-CHOI

Copy link
Copy Markdown
Contributor

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 in llm_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 (tree 0abbd1b2521edf4c13fc1e25329ee06de43e6a5d), based on 3cc7e213d. Verification hardware was NVIDIA GB10 (DGX Spark), CUDA 13 / sm_121, NVIDIA driver 580.178.04 and Rust 1.97.1.

Checkpoint verification

Checkpoint Pinned revision Tensor bytes Greedy input Decode tok/s
SoMarkAI/OXR-1.0 c708407f9d2b4df658f2543d9132b62bb7221df4 3,068,857,520 Formula / table 140.31 / 149.42
bxespinozar/OXR-1.0-mlx-bf16 0f20839a945ea0a3e6bbb2dfdb80a3c2c16bd44c 2,757,678,301 Formula 139.29
bxespinozar/OXR-1.0-mlx-8bit 943bd67406639a292bda9802bcaccbe1ff0ed8e3 2,198,992,387 Formula 206.93

These 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_config and vit_config in their actual configs.

The original produced the following completions, byte-identical to mlx_vlm.generate after removing CLI presentation framing. The reference was mlx-vlm 230fc308efb577d87446306bfb8a3e9f1a129558. Its four OXR module files match upstream a0b9352e by SHA-256.

Formula, 46 bytes

$\mathrm{a}^{2}+\mathrm{b}^{2}=\mathrm{c}^{2}$

Table, 117 bytes

<table><tr><td>Item</td><td>Count</td></tr><tr><td>Pens</td><td>12</td></tr><tr><td>Books</td><td>3</td></tr></table>

A loopback POST /v1/chat/completions with an image_url content 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 prompt Write 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.py with 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.

Page Reference Top-1 disagreements Decided disagreements Logit delta p50 / p90 / max Perplexity, reference → mlxcel
Formula Native bf16 0/13 0/13 0.2500 / 0.2500 / 0.2500 17.5111 → 17.1266
Table Native bf16 0/61 0/60 0.0000 / 0.2500 / 0.5000 1.4819 → 1.4830
Formula fp32 0/13 0/13 0.0733 / 0.1376 / 0.1893 17.1147 → 17.1266
Table fp32 0/61 0/60 0.0799 / 0.1956 / 0.4985 1.4792 → 1.4830

Implementation and review

  • Boundary inputs. Tests cover zero dimensions, 1×1, ties-to-even rounding, both pixel bounds, extreme aspect ratio, alpha compositing, multiple images and both directions of marker mismatch. The small random model checks the indicator rows, ordered image features and image-conditioned logits. The processor has a single native-resolution grid per image, with a 900-atom square at the upper pixel bound.
  • Large inputs. Prompt expansion splits the input once and streams the replacement text. A 100,000-marker fixture checks the full output. The model evaluates each image's final soft tokens before starting the next image. The large vocabulary softmax runs in f32 and the product uses the checkpoint dtype. Full self-attention within one image retains the model's quadratic patch-count cost.
  • Other callers. Registry, model metadata, adapter rejection, CLI family order, decoder geometry, batched-decode classification and runtime routing were checked. OXR fits the existing Other VLM group. It delegates native batched decode and last-row projection to Qwen3. Ordinary dense KV reuse applies. Recurrent model-owned snapshots and speculative rewind use Qwen3's default flags. Prepared image prefill stays on the single-request path. PaddleOCR-VL retains its original LayerNorm epsilon; the shared block now also accepts OXR's configured epsilon.
  • Formatting. Ran 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 covers model_type: oxr under 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=1 keeps the checkpoint dtype for a diagnostic comparison. ROCm was also untested. The full-checkpoint parity sample comprises two document pages.

Commands and test results

cargo fmt --all -- --check
cargo clippy --locked --workspace --all-targets --features cuda -- -D warnings
cargo test --locked --workspace --profile test-fast --features cuda --lib oxr -- --test-threads=1
for filter in dots_ocr qwen_vl qwen2_vl qwen2_5_vl qwen3_vl chat_template chat_request paddleocr mage_vl batched_decode_coverage_tests model_metadata kv_arch; do
    cargo test --locked --workspace --profile test-fast --features cuda --lib "$filter" -- --test-threads=1
done
cargo build --locked --profile test-fast --features cuda --bin mlxcel --bin mlxcel-server --example logit_trace
make verify-test-cuda

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. On f0d06f5e, detection failed with Unsupported model type: oxr. The layer tests could not compile against the then-missing OXR APIs.

BIN=target/test-fast
M=models/OXR-1.0
F='Recognize the formula of the image into KaTex format.'
T='Recognize the table of the image into html format.'
"$BIN/mlxcel" arch
"$BIN/mlxcel" generate -m "$M" --image formula.png -p "$F" -n 512 --temp 0 --profile
"$BIN/mlxcel" generate -m "$M" --image table.png -p "$T" -n 512 --temp 0 --profile
"$BIN/mlxcel" generate -m "$M-mlx-bf16" --image formula.png -p "$F" -n 512 --temp 0 --profile
"$BIN/mlxcel" generate -m "$M-mlx-8bit" --image formula.png -p "$F" -n 512 --temp 0 --profile
# For each PAGE=formula/table and matching PROMPT:
MLXCEL_TRACE_IMAGE="$PAGE.png" MLXCEL_TRACE_IMAGE_PROMPT="$PROMPT" \
  "$BIN/examples/logit_trace" "$M" "$PAGE.txt" 128 1 8 > candidate.tsv
python scripts/mlx_vlm_image_logit_trace.py "$M" "$PAGE.png" candidate.tsv --prompt "$PROMPT" > native.tsv
python scripts/mlx_vlm_image_logit_trace.py "$M" "$PAGE.png" candidate.tsv --prompt "$PROMPT" --float32 > fp32.tsv
python scripts/compare_logit_traces.py native.tsv candidate.tsv
python scripts/compare_logit_traces.py fp32.tsv candidate.tsv
python -m mlx_vlm.generate --model "$M" --image "$PAGE.png" --prompt "$PROMPT" --max-tokens 512 --temperature 0

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/models for 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-cuda with a private 0700 TMPDIR on the reviewed tree 0abbd1b2521edf4c13fc1e25329ee06de43e6a5d: 17,669 passed, 0 failed, 517 ignored. The worktree tree was the same before and after the run.

33 repository CI checks
python3 scripts/ci/check_benchmark_csv_schema.py
python3 scripts/ci/check_benchmark_raw_logs.py
python3 scripts/ci/check_binary_assets.py
python3 scripts/ci/check_crate_versions.py
python3 scripts/ci/check_cuda_arch_lists.py
python3 scripts/ci/check_env_var_docs.py
python3 scripts/ci/check_kernel_dtype_keys.py
python3 scripts/ci/check_kernel_port_dispatch.py
python3 scripts/ci/check_llama_compat_manifest.py
python3 scripts/ci/check_native_env_writes.py
python3 scripts/ci/check_technical_reports_layout.py
python3 scripts/ci/check_used_by.py
python3 scripts/ci/check_windows_reserved_paths.py
bash scripts/ci/ab_decode_pair_worktree_test.sh
bash scripts/ci/ab_scripts_outdir_test.sh
bash scripts/ci/check_benchmark_csv_schema_test.sh
bash scripts/ci/check_benchmark_raw_logs_test.sh
bash scripts/ci/check_binary_assets_test.sh
bash scripts/ci/check_cross_repo_refs_test.sh
bash scripts/ci/check_cuda_arch_lists_test.sh
bash scripts/ci/check_kernel_dtype_keys_test.sh
bash scripts/ci/check_kernel_port_dispatch_test.sh
bash scripts/ci/check_llama_compat_manifest_test.sh
bash scripts/ci/check_used_by_test.sh
bash scripts/ci/check_windows_reserved_paths_test.sh
bash scripts/ci/mlx_pinned_commit_test.sh
make verify-rocm-overlay
make verify-cuda-runtime-dir
make verify-python-tooling
python3 scripts/insert_apache_header.py --check
python scripts/ci/check_webui_contract.py --self-test
bash scripts/ci/mlx_pinned_commit.sh
python3 scripts/ci/check_cross_repo_refs.py HEAD^
Exact formula and table PNG inputs

This Python snippet reconstructs the two input files and verifies their SHA-256 digests.

from base64 import b64decode
from hashlib import sha256
from pathlib import Path

png = b64decode(
    "iVBORw0KGgoAAAANSUhEUgAAAcAAAADICAIAAADwY6b9AAAN8UlEQVR4nO3df0zU9R/A8c8hKigXv1ZYEC7DQlKDEqwNDapF"
    "KWm1tYqsrD/QLIFc66+2rLZstlyznDXdam39mP0wGVraEBQCAy1+zQj5UaA3MZBfCocc3PeP++6zz044Przg7nN+eD7+4nO9"
    "P3dv3lxP78fnPmdxOp0KAGDiAoyeAABcqwgoAAgRUAAQIqAAIERAAUCIgAKAEAEFACECCgBCBBQAhAgoAAgRUAAQIqAAIERA"
    "AUCIgAKAEAEFACECCgBCBBQAhAgoAAgRUAAQIqAAIERAAUCIgAKAEAEFACECCgBCBBQAhAgoAAgRUAAQIq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VRnsEylJPhtkegeoUFham3Tx//rxBExlFZmbm"
    "WN845Ebdpb29XecuggNfJiQpKUnPMLeXQU+ePOn6wDU8GxkZKS0t1V5y//3369z333//dTqdjY2NXpjX9DVNA6qtj6IoFy9e"
    "NGomJqN9w9eDBQsWaI/YtdvttbW1XpuUeVRXV/f29qqbs2bN4gxJxjLhRzkdDsfhw4cLCwurqqqampp6enr6+vpGRkY87NLf"
    "3z/q5SdPnvTOHE3ruuuu0zNs5syZN998c0tLi3pJY2PjXXfdpW6y8qNqaGjQbs6fP197XLMMSz0Zpgro8PDwzp0733///QsX"
    "LkxoR6fm9URMhucP0WpZrVbtZldXlxemYzZuT5V0/nMF7zFPQDs6OlatWlVZWWn0RCaroKBA50j1hYioqCg/eRnX7bURD0JC"
    "QrSb3d3dUz8b03ELqP5/ruAlJnkNtL+/Pz09XVvPoKCg7OzsQ4cOnT179uozcbW1tRk4Wyj+96hf/3t3At5+7w5GMckj0Hfe"
    "eaeurk7djI2NPXLkyO23327glKYn/W+mX758WbsZHh7uhemYTUREhHbTbQ3he2Z4BGq323ft2qW9ZN++fdTTEH19fTpHat9N"
    "Vq46sAyjcp0kSeW2hvA9MwT06NGjly5dUjdTUlKWL19u4Hyms87OTj3DhoaG3F5F0X48EWNxe1jwzz//OBwOoyYDxRxP4Zua"
    "mrSbycnJRs0Ep0+f1jOssbFR+/HZ4ODgJUuWeG1Suuh/785AS5YsCQsLU99wGxoaampq4smWgczwCNTtCJjQ0NBxd9E+YsUU"
    "0nkURFFRkXZz2bJl+s+EPZ0FBASsWLFCe4nbSo6lp6cnMDDQ9Y7Wli1bvDO76cgMAXV7+UzPs0i3B62YKuXl5XoOqMrPz9du"
    "rlu3zmszMpvs7Gzt5v79+/XsdejQIfUh/yOPPDL105quzBBQ15e3qI4dOzbuLjrvdpiokZGRTz75xPOYmpqaI0eOqJshISHP"
    "PPOMl+dlHqtXr3ades7l119//eOPP8bd6+OPP3b9cNNNN7lOeo0pYYaApqWlzZo1S92sr6///vvvPYyvrq7+8ssvvT+v6chq"
    "te7YseOvv/4aa4DD4cjJydEeBPr666+7fSoJHlgslg8//FDddDqdmzZtGhwc9LDL3r17y8vLXT9v3rzZ9Y0dmBq+Pv2Td7z0"
    "0kvaX8pqtRYXF486srq6OiYmxu0Vtz179vh4wlNCnb//nM7u7bffVhQlNjb29OnTVw8eGBiY6Fd6YFQ5OTnaZfTwlR7ffPON"
    "WsyFCxfy9e5TyyQBPXfu3PXXX6+9SwUEBDz33HOHDx/+77//hoaGurq6SkpKXn311aCgIEVRtm/fPta/KNdQTI0KaG5u7lir"
    "V1RU5PrUzezZs/Py8srKyjo7OwcGBpqamj777DPxl8rBzeDg4OOPP65dzJiYmG3bttXW1vb09AwODra2tu7bt0/9lg5FUebM"
    "mfP7778bPXGzMUlAnU5nRUWFnoOxLRbLjh07PHyUk4COy3NA7Xb7gw8+OO4fIiwsrKKiwpfTNpnh4eFNmzaNu84uVqu1sLDQ"
    "6CmbkBleA3VJTk6uqqp64IEHPIy58cYbf/rpp9dee81ns5qGZs+eXVBQsHnzZg9nWsvMzKyrq+OI3ckICAjYtWtXcXHxuKeU"
    "f+ihh2pqavSfehn6WZx+dk6HyTt16tS3335bWlra0tLS1dVlsViioqISExPXrFmTlZXl9jXZ8J6///77888/LyoqOnPmTF9f"
    "X0RERHR09MqVK7OyslJSUoyenXk4nc6KioqCgoLi4mKbzdbe3j48PBweHh4XF5eamvr0008vXbrU6DmalgkDCgC+YZ6n8ADg"
    "YwQUAIQIKAAIEVAAECKgACBEQAFAiIACgBABBQAhAgoAQgQUAIQIKAAIEVAAECKgACBEQAFAiIACgBABBQAhAgoAQgQUAIQI"
    "KAAIEVAAECKgACBEQAFAiIACgBABBQAhAgoAQgQUAIQIKAAIEVAAECKgACBEQAFAiIACgBABBQAhAgoAQgQUAIQIKAAIEVAA"
    "ECKgACBEQAFAiIACgBABBQAhAgoAQgQUAIQIKAAIEVAAECKgACBEQAFAiIACgBABBQAhAgoAQgQUAIQIKAAIEVAAECKgACBE"
    "QAFAiIACgBABBQAhAgoAQgQUAIQIKAAIEVAAECKgACBEQAFAiIACgBABBQAhAgoAQgQUAIQIKAAIEVAAECKgACBEQAFAiIAC"
    "gBABBQAhAgoAQgQUAIQIKAAIEVAAECKgACBEQAFAiIACgBABBQAhAgoAQgQUAIQIKAAIEVAAECKgACBEQAFAiIACgBABBQAh"
    "AgoAQv8DihI6JajVVLIAAAAASUVORK5CYII="
)
assert sha256(png).hexdigest() == "bec00903d8ce9867426914de090fc2ca4b39f6e5794fed31407782b2b3420afa"
Path("formula.png").write_bytes(png)

png = b64decode(
    "iVBORw0KGgoAAAANSUhEUgAAAcAAAAEYCAIAAABEKrFmAAAgpElEQVR4nO3daVBUV8I38HPZGhBlUUEEwaCiqKhoCnECihKj"
    "GB3LaIwRFYRRow4aJFFTqfhoBcFKmIFiNNGYqOASFSe4xKgzUUHGAmRRUWQkyBaMsqhsDd000M+H8763+ukNOH2xafj/Pt26"
    "Z7mn28Pf03fp5uRyOQEAgO4z0vcAAAAMFQIUAIARAhQAgBECFACAEQIUAIARAhQAgBECFACAEQIUAIARAhQAgBECFACAEQIU"
    "AIARAhQAgBECFACAEQIUAIARAhQAgBECFACAEQIUAIARAhQAgBECFACAkYlQHXEcJ1RXAACvge6/CIcVKAAAI8FWoBR+4xOE"
    "RT/ZYF6BsIT6xIwVKAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjBCgAACME"
    "KAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjgX8XXhcPHz709PTUVJqRkeHj"
    "4/M6xwN9WENDw+XLl//1r3/l5ubW1NS8ePHC3Nzczs7O3d3d09PTz89vzpw5gwYN0vcwobfj5HK5MB1xHCFEl94QoKBK93ml"
    "pLm5OT4+PjY29tWrV1qqmZiY+Pn5rVy5ctmyZTY2NkIdHXoJweaVXCAC9lZaWsoPr7CwUG2duLg4WiEyMlKQg0LvJOwsraio"
    "mDJlCu3TxcUlKiqKrkBbW1tfvHiRkZGxd+9eV1dXxT+QsLAwoY7eG+APhxJqXvWij/AAPaq0tHTGjBlVVVWEkA0bNvz973+3"
    "tLTkS+3s7Hx8fHx8fCIiIrZu3Xr48GH9jRQMBi4iQb/Q3Ny8ZMkSmp6hoaEHDx5UTE9FFhYW33333bJly17vAMEgIUChX4iK"
    "irp//z4hxMnJKT4+vtP6Bw4cMDc37/FhgYFDgELf9/Lly/3799Pt8PDwgQMHdtrE3t7+/fff7+FxgeHT/TQqJWBvWi4iNTY2"
    "dvqKSktLlTqUSqWHDx9euHChk5OTSCQaNGjQ2LFjw8LCrl+/rnYAkydPVvsunT592tfX18bGxtbWdtq0aX/729+ampr4VtnZ"
    "2cuXL3dxcTEzM3N0dFy+fHlubq4gb0h/Jsi8SkhI4P8pKyoqutjq1KlTRPNFJJlMlpiY+N5777m4uFhYWFhZWY0ePXr16tUX"
    "L15Urfz7778rzSilazgpKSlKFTIyMhQraJqTycnJc+bMsbe3F4lELi4uq1evzs/PVx0A2x9OHybIvJLL5X0/QDMzM0eOHKmp"
    "cmBgYF1dndIAVCerTCZbs2aNanMvL68XL17I5fLvvvvO2NhYqdTMzEztnxN0nSDzatGiRbQfZ2dnQUaVk5MzevRoTZPKx8en"
    "vLxcsX5PBKhMJlu9erXq0UUi0S+//KI0YASoEkHmldzgApTXxbsxbty4Qc9kGRkZRUREFBQUSCSSV69eXbt2zc/Pj/YwZcqU"
    "lpYWtc1FIhGts3v37tGjR58/f76+vr65ufn69eseHh60KDg4+MaNGyKRKCoqqqKiorW1taioiJ/ZQ4YMUVylQncJMq9sbW1p"
    "PwsWLNB9SKmpqRYWFrTDkJCQ7OxssVhcX1+fmpq6YMECut/e3r64uFi1bafzNiAgQG2A8vg5+T//8z8jRow4depUbW2tVCrN"
    "z89fvHgxf3RNUxq3MVEI0M7nQVVV1dChQ2m1H374Qam0ra3t3XffpaURERFq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wJyUp/tO92q9z7ujo+O233zodmy46/cOBbjHUd5OfiIpXOS9fvsxxHL/WWLt2Ld1I"
    "SkrS1E91dbWVlRXHcQcPHuyxwYL+bdu2jV4cr6ys3LZtm/bK1dXVkZGRhBATE5Mvv/yS389xHD+pTp482d7ertq2vr7+woUL"
    "dFv17mNHR0e6ofaUUVpamo73CXSqK3840HWGGqAjRoygG4qfpB48eEAU7kyKjIyka4eMjAz+AQxFUql0w4YNYrF46NChK1eu"
    "7PFBg/6Ym5tfuHCBfgY/fPjw5s2bNZ3ELCsrmzt3Lp1X0dHR/J2VVGRkJF2EFhYWxsTEqDb/+OOP6+rqCCGTJ08OCgpSKn3z"
    "zTfpGjA3N1fxiTtCiFQq/eyzz0xNTVlfYpd05Q8HukH3h5koAXvryqOcdXV19MORlZXV9evXxWLxrVu36Pmm3bt389XS09P5"
    "/3JXrlx569at+vp6iURSWlqalJQ0depUQgjHcf/85z/VHkXxphBVYWFhtPT48eOqpTdv3qSl8+bN6/57AP+PsLO0srKS/2Ut"
    "V1fX6OjovLy8Fy9eyGSy2tramzdvhoeH85fXt2/frraTtLQ0vk5wcHB2dnZzc3NDQ0NaWlqnz8LL5XL+AeKJEyfSqSsWi1NT"
    "U319fWfNmjVnzhxa2umjnGpLr1y5QksXL16stkIX/3D6PKHmVS8KUPrfoCaq82nHjh2q1dzc3F69eqVYLS8vT8t/rba2tsnJ"
    "yUo9qy4cqM2bN8vl8rt376ottba2ps0nTJigtsLhw4d1eX/6J6EmOk8qlUZHR9vZ2WmZbCNGjFCdFYqys7O1fBvT9OnTlZ5S"
    "V1RaWurk5KTaysvL648//uCfhefRrwXRPiflcrna++oJIaovpIt/OH0bfdW692PAN9LHxMS4uLgcPXq0sLCwtbV1+PDhCxYs"
    "2L17t9JvKHp5eRUUFJw+fTolJSUnJ6empqa9vX3w4METJ04MDAxcu3YtfnOxXzEzM/vss882b96ckpJy7dq1u3fvVlVVNTY2"
    "WllZOTs7T5s2bdGiRYsWLTIzM9PSyZtvvllYWHjq1Knz58/n5uZWV1cbGxs7ODjMmDFj+fLlf/7zn7W0HTlyZF5eXmxs7OXL"
    "l0tLS42NjUePHr1q1aqNGzdq+pURYXXxDwe6ohf9rDGAKswr6AlCzStDvYgEAKB3CFAAAEYIUAAARghQAABGCFAAAEYIUAAA"
    "RghQAABGCFAAAEYIUAAARghQAABGCFAAAEYIUAAARghQAABGCFAAAEYIUAAARghQAABGCFAAAEYIUAAARghQAABGCFAAAEYI"
    "UAAARghQAABGCFAAAEYIUAAARghQAABGCFAAAEYIUAAARghQAABGCFAAAEYmwnbHcZywHQIQzCvorbACBQBgJPAKVC6XC9sh"
    "9HN07Yl5BcIS6jMNVqAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjBCgAACM"
    "EKAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjHpRgD58+JDrjEgkGjZsWEBA"
    "QHR0dE1Njb6HDIbq6dOn8+fPp5OqrKysK01aWlrOnDkTGho6YcIEW1tbU1PTwYMHT5s2bdOmTf/5z396eLzQW8kFontvDx48"
    "6NbILSwsvvnmG6HGD72TsLOUOn78uI2NDT+RSktLtdevrq7esWPHoEGDtMzGuXPnVlRUCDtO6DlCzateFKC80tJSfl4WFhby"
    "+9va2v7444/Tp097enryFfbt2yfIQaF3EjZAq6urlyxZQgjhOK7rAbp582ZaUyQSbd++PTc3t6mpSSqVFhcXx8bG2tra0lJX"
    "V9fKykqhhgo9qj8GKK+lpWXmzJm0grGx8YMHDwQ5LvRCAs6rn376aejQoYQQb2/vCxcudDdATUxMbt26pVr6+PFjPkMXL14s"
    "yFChpwk1r3rROdCuMzc3P3ToEF1EtLe3x8fH63tEYAA+/PDDlpaW+Pj4jIyMSZMmdbd5SEiIn5+f6n53d/cvvviCbl+8eLGy"
    "slLXgYLhMMgAJYSMGzdu7NixdPvXX3/V72DAICxatOjRo0dbt241MmKZ9gsXLtRURE8LEELkcnlWVhbj+MAAGWqAEkLc3Nzo"
    "xtOnT/k1OYAmycnJI0aMYGi4f/9+uVy+ePFiTRUUu3358iXL4MAwGXCAagnN1tbW77//ftGiRc7Ozubm5tbW1uPGjfvLX/5y"
    "48YN1cpTpkxRulmK7j937lxAQICDg4O5ubmrq+uaNWs6vU8gMzNz3bp1EyZMGDRokJmZmbOz89KlSxMTE1taWnR5pdDLtba2"
    "8ttOTk56HAm8brqfRqUE7K3Ti0jUuHHjaB1XV1fF/ZmZmSNHjtT0egMDA+vq6hTrT548WamOTCZbvXq1aluRSPTLL7+oHUxb"
    "W9tHH32k6aB2dnZff/21RCIR4u3pX4SdpTzFOdbpRaRO5eXl0a6srKwaGxuFGCD0LKHmlaGuQAsLCx8/fky33377bX7/zZs3"
    "/f39y8rKjIyMIiIiCgoKJBLJq1evrl27Rq8AXLlyxd/fXyKR8E3u3btH3wuRSET3REVFpaamnjp1qra2ViqV5ufn049vUqk0"
    "JCREsS1v3759Bw8eJIT4+/tfvXr1+fPnEomktLT0+PHjHh4eL1++/PTTTy9dutRj7wfo088//0w3NmzYYGVlpd/BwGulewZT"
    "AvbWrduYjIyM+NuYqqqq6H0qhJAffvhBqVVbW9u7775LSyMiIlS75QN0yJAhZWVlikUymWz06NG09OzZs0oNOzo67O3tCSHO"
    "zs6qy8zGxsYxY8YQQpKTk7v1PoDcEFagzc3Njo6OhJDhw4e/evVKmPFBDxNqXhnSCrSjo+P58+dnz56dPn36rVu36M7o6OiJ"
    "EyfS7djYWPp8p6+vb2hoqFJzY2PjhIQEegX24MGDL1680HSgjRs3urq6Ku4xMTFZunQp3b5z545S/ZcvX1ZXVxNCxowZw6cw"
    "z8rKKiQkpBuvEwzK7t27nz17ZmxsnJSUpPiAE/QLumcwJWBviqsDLZQe5eSXgYSQQ4cOaep8ypQptM7hw4eVivjsy8rKUm14"
    "7NgxWhoUFKRUJJPJzMzMCCGWlpa4q19Yws5SnlAr0EuXLt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XXxNqaIiAi+2ldffaVYpPg00Zdf"
    "fqnaln+aaPLkyVqeROpuW7nWRznr6ur45+vXrVunWPTbb78RQqytrX///XfVI1ZXVw8YMIAQIhKJ6uvrNb0hfZIg84r/IoL3"
    "33+/tbVVtcLdu3f5hyNU7+2FvkeovDKwAJVIJBUVFcnJybNnz+brzJw5U/WvIi0tjb+MHhwcnJ2d3dzc3NDQkJaW1unz7Lq0"
    "1f6N9Pfu3eN7TkxM5PfTACWEODs7f/vtt8XFxRKJpKWlpays7OjRo/yz8BERESxvqCETNkDpf3tJSUkVFRX0Jz1yc3N37NjB"
    "/6MMGzasqKhIkJFDb9YHA5Th0qexsfGmTZvEYrHaDrOzs7V8o9L06dPV/roDc1u1X3VOCImLi5PL5RkZGZp6y8jI6OjoOHHi"
    "BH9TgVrr169Xu3rq2+hr17GTurq63bt30ycatAgICHjy5Ikgw4ZeTpB5JTe4ADU1NbW1tfXw8Hjvvffi4uIqKiq09ymTyRIT"
    "E5csWeLi4mJubj5gwAA3N7egoKALFy50Op7uttUlQGkPbW1tly5dCg0N9fDwGDhwoLGxsY2NzdSpU7ds2ZKbm9u9d7OvEGqi"
    "y+VyqVSakpKyfv36adOmDRkyxMTExMLCYtiwYX5+fpGRkZmZmYIcBQyCUPOK4/vSEb0JWajeACjMK+gJQs0rA74KDwCgXwhQ"
    "AABGCFAAAEYIUAAARghQAABGCFAAAEYIUAAARghQAABGCFAAAEYIUAAARghQAABGCFAAAEYIUAAARghQAABGCFAAAEYIUAAA"
    "RghQAABGCFAAAEYIUAAARghQAABGCFAAAEYIUAAARghQAABGCFAAAEYIUAAARghQAABGCFAAAEYIUAAARghQAABGJsJ2x3Gc"
    "sB0CEMwr6K2wAgWA/kgul+veCSdILwAA/RBWoAAAjBCgAACMEKAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjBCgAACMEKAAAIwQ"
    "oAAAjBCgAACMEKAAAIwQoAAAjBCgAACMEKAAAIwQoAAAjBCgAACM/he3LBsn78petwAAAABJRU5ErkJggg=="
)
assert sha256(png).hexdigest() == "19dc2ead388b57a4ff1027fd73447d1eabd854fb7d7e7b2a70cc0fc2e9348706"
Path("table.png").write_bytes(png)

@inureyes inureyes added status:review Under review type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:models Model architectures, weights, loading, metadata modelsize:small 4-bit checkpoint <= 10GB; fast iteration, safe for smoke tests modeltype:vlm Vision-language model arch:dense Dense transformer decoder labels Nov 28, 2026
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.
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.
@inureyes

Copy link
Copy Markdown
Member

Hardening review

Reviewed this PR against #3207's acceptance criteria. Detection, loader, sanitize, vision tower, visual tokenizer, processor, wrapper, the LoadedModel/VlmRuntimeRef arms, server and CLI prompt paths, and the docs/NOTICE rows are all wired into the shared code paths. I found no correctness defects. smart_resize matches upstream mlx-vlm a0b9352e line for line.

Pushed: 6ee30d1b0 merges main, which brings in #3548 and fixes the binary assets check. a723d926a adds untrusted_image_sizes_stay_within_the_pixel_budget. It runs degenerate, extreme-aspect and u32::MAX image sizes through the processor and asserts that each one either fails or lands on an even grid within the max_pixels budget (900 atoms by default).

Shared vision code: the PaddleOCR-VL changes only widen visibility and pass 1e-6 through the new eps parameter, so its numerics are unchanged. The mage_vl_rope, merge.rs, resample_matrix and weights.rs edits only change comments. nested_text_config reads llm_config only when model_type == "oxr".

Security: each request image is bounded by the server's decode and image-count limits. After that, smart_resize caps it at max_pixels, or it errors. Extreme sizes return an error instead of panicking. The checkpoint can raise max_pixels, but every published OXR config uses 921,600 or nothing. Marker mismatches and injected <|image_pad|> text return errors, not panics. Packed visual weights and unknown keys are refused at load.

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):

  • cargo fmt --all -- --check: pass
  • cargo clippy -p mlxcel --lib --tests --features metal,accelerate -- -D warnings: pass
  • cargo test --lib filtered to oxr, paddleocr, mage_vl, resample_matrix, vision::merge, server::chat_template, server::state, server::model_worker, execution::config_fields, loading::tests, models::detection, multimodal::vlm_runtime, batched_decode_coverage, kimi, deepseek_ocr and dots_ocr: 779 passed
  • --test paddleocr_vl_parity --test kimi_vl_parity: pass
  • check_binary_assets.py and check_env_var_docs.py: pass

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
@inureyes
inureyes merged commit 60cd7d6 into lablup:main Nov 30, 2026
33 of 36 checks passed
inureyes added a commit that referenced this pull request Nov 30, 2026
#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
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch:dense Dense transformer decoder area:models Model architectures, weights, loading, metadata modelsize:small 4-bit checkpoint <= 10GB; fast iteration, safe for smoke tests modeltype:vlm Vision-language model priority:medium Medium priority status:review Under review type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(vlm): add SoMark OXR-1.0 (oxr) support

2 participants