Skip to content

test(vision): refresh the DeepSeek-OCR CLIP reference for quick GELU - #3578

Merged
inureyes merged 2 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/clip-reference-3563
Nov 30, 2026
Merged

inureyes merged 2 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/clip-reference-3563

Conversation

@Jaeyeong-CHOI

Copy link
Copy Markdown
Contributor

Addresses the GB10 failure in #3563. The requested Metal run is still outstanding.

The model is already using the right activation. The expected CLIP mean still describes the older erf-GELU implementation, even though #3456 switched the MLP to the quick GELU used by mlx-vlm. Refresh the reference mean and replace the test's pointer to a missing scratchpad script with a runnable, independent mlx-vlm reference. No inference code, SAM expectation, or tolerance changes.

On GB10, using mlx-community/DeepSeek-OCR-4bit revision 4958b6b, mlx-vlm 0.8.1 and MLX 0.32.4, I ran the same deterministic bf16 input through the reference SAM once, then through the reference CLIP with and without substituting the old erf GELU:

mlx-vlm run SAM absmean CLIP layer 1 absmean CLIP layer 24 absmean
Unmodified (quick GELU) 0.043049 0.101277 0.130674
Only the activation changed to erf GELU same input 0.103147 0.143602

The old target is 0.14356. The new target, 0.13067, comes from unmodified mlx-vlm, not the implementation under test. The original 0.005 tolerance rejects the erf variant by more than a factor of two.

To regenerate: python scripts/deepseekocr_encoder_reference.py models/deepseek-ocr-4bit with mlx-vlm installed. The input normalization runs in float32 before the cast to bf16, matching the Rust fixture.

Metal: no Metal device on the test host. The Metal review of #3456 covered related library tests, not this checkpoint-gated integration test; a run of this specific test on Metal remains unverified.

The macOS nightly workflow also documents that its self-hosted runner has no model weights and that checkpoint-gated tests self-skip. A green test name there would not by itself establish an encoder measurement on Metal.

On the unmodified Rust base 60cd7d657, the checkpoint-gated CUDA integration test really executed and failed: SAM 0.04305, CLIP 0.13067141 (test exit 101). On the candidate, the same SAM and CLIP signatures, including the first four values, pass the unchanged tolerances (test exit 0). cargo fmt --all -- --check also passed.

As a separate diagnostic, with the same checkpoint and SAM handoff, I stopped both CLIP encoders after 1, 6, 12, 18 and 24 transformer blocks. These are float32 reductions of the bf16 hidden states (not just the final layer):

CLIP blocks mlx-vlm quick GELU mlxcel
1 0.10128 0.10131
6 0.13023 0.13040
12 0.12842 0.12853
18 0.11163 0.11166
24 0.13067 0.13067

Final GB10 make verify-test-cuda completed (exit 0): 17,947 passed, 0 failed, 519 ignored, including the real-checkpoint integration test. A first run failed unrelated PTX cache trust checks because the temporary build directory was group-writable; the successful rerun used private directories, without source changes.

@inureyes inureyes added status:review Under review type:test Test related changes priority:low Low priority labels Nov 30, 2026
@inureyes inureyes self-assigned this Nov 30, 2026
Mark scripts/deepseekocr_encoder_reference.py executable in Git, which the
python tooling check requires for scripts with a shebang. Load the model
with mlx_vlm.utils.load_model so the script no longer depends on tokenizer
and processor resolution, which fails under transformers 5.24.1 for this
checkpoint. Resolve the test checkpoint through tests/common so
MLXCEL_REQUIRE_MODELS=1 fails instead of silently skipping.

Refs lablup#3563
Refs lablup#3578
@inureyes

Copy link
Copy Markdown
Member

Maintainer hardening review, with a follow-up commit 30e1b0d7 pushed to this branch.

Independent measurement on GB10 (spark-102, sm_121)

I installed mlx-vlm 0.8.1 with mlx[cuda13]==0.32.4 in a fresh venv and ran it against the same checkpoint revision (4958b6b):

Run SAM absmean CLIP absmean
mlx-vlm, unmodified (quick GELU) 0.04305 0.13067
mlx-vlm, CLIP MLP swapped to nn.gelu (erf) same input 0.14360
mlxcel, this branch (MLXCEL_REQUIRE_MODELS=1) 0.04302 0.13064

The new target reproduces from an independent reference, and the erf variant lands 0.0129 away, about 2.6 times the unchanged 0.005 tolerance, so the check still rejects the old activation. src/vision/encoders/deepseekocr_clip.rs already applies GeluActivation::Fast (gelu_sigmoid), so no inference change is needed.

Fixes in 30e1b0d7

  • python tooling tests failed because the new script has a shebang but Git mode 100644. It is now 100755.
  • mlx_vlm.load failed before reaching the encoders here (Unrecognized processing class, transformers 5.24.1). The script only needs the vision towers, so it now uses mlx_vlm.utils.load_model, which skips tokenizer and processor resolution. The table above comes from the fixed script.
  • The test looked only at models/deepseek-ocr-4bit and skipped silently even under MLXCEL_REQUIRE_MODELS=1. It now resolves through tests/common::repo_model_dir, like the other checkpoint-gated tests.

Validation

  • cargo test -p mlxcel --features cuda --profile test-fast --test deepseekocr_encoder_parity -- --test-threads=1 with MLXCEL_REQUIRE_MODELS=1: 1 passed, exit 0.
  • cargo fmt --all -- --check and python3 -m unittest tests/test_script_executable_modes.py: pass.

Still unverified: the Metal run of this specific test, as the PR body says. #3563 asks for it, so this PR uses Refs rather than closing the issue.

@inureyes
inureyes merged commit 2292469 into lablup:main Nov 30, 2026
36 checks passed
@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

priority:low Low priority status:review Under review type:test Test related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants