Repository navigation
Reuse Qwen3-VL vision rotary tables without changing CUDA rounding - #3655
Merged
inureyes merged 4 commits intoDec 2, 2026
Merged
Conversation
…measurements Drop `mlx::core::compile` (`compiled_vision_rotary`) from the C++ bridge and keep `VisionRotaryTables::apply` eager. The compiled path regressed NVIDIA GB10 CUDA first-use by +1,222..1,230 ms with warm paired deltas crossing zero, and 4 paired runs on Apple M1 Ultra Metal (`models/qwen3-vl-4b-instruct-4bit`) showed `256x256` warm regressed +0.27 ms [+0.06, +0.86] in 4/4 pairs (first +2.26 ms) while `640x384` warm was -0.34 ms [-0.94, +2.30] (noise, first +6.17 ms). Keep the hoisted `VisionRotaryTables` (eliminating redundant per-block `cos`/`sin`/`tile` recomputations with bit-identical output), remove the one-off `examples/qwen3_vl_tower_timing.rs` probe, restore `/// Used by:` annotations in `src/vision/encoders/qwen2_vl.rs` (dropping the incorrect `Youtu-VL` entry), and add a multi-image/video grid unit test. Validated with `cargo test --profile test-fast --lib qwen3_vl` (64 passed), `cargo fmt --check`, and a real Metal `mlxcel generate --image` check on `models/qwen3-vl-4b-instruct-4bit`. Refs lablup#3634, lablup#3655
inureyes
force-pushed
the
perf/qwen3-vl-vision-rope-gb10
branch
from
December 2, 2026 00:11
d0f9242 to
a8d0da0
Compare
Member
Implementation Hardening SummaryAudited PR #3655 against issue #3634 and Findings & Fixes
Validation
|
3 tasks done
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.
Closes #3634.
Share one expanded cosine/sine table pair across Qwen3-VL vision blocks. Compile the two f32 products but leave addition and casting outside the graph: a fully fused CUDA prototype changed greedy output. The dequantized diagnostic retains its eager reference. Other encoders are unchanged.
Spark2 / NVIDIA GB10
Baseline
b67573543versus this PR; NVIDIA driver 580.178.04, MLX 5a48f9cc. Model:mlx-community/Qwen3-VL-4B-Instruct-4bit, weights SHA-25690eeb02604181dbcccd0a30a1f550a4a8928ca7dcbee4aee1449239306cfdfca. Deterministic, generated RGB inputs: (x, y, x XOR y), each channel modulo 256. Six paired runs per size, alternating baseline→PR and PR→baseline. Each binary invocation starts a fresh process. Each accepted pair held the shared GPU lock throughout; monitoring rejected overlap with other GPU compute PIDs, builds or transfers. On-disk kernel caches were primed once per binary/size and reused; first use is the first tower call, not a cache-empty compile or an end-to-end cold start. The clock excludes loading and preprocessing, and includes evaluation of the main output and all three DeepStack outputs.Median [min, max] across the six process timings, ms. For warm, each timing is the median of ten forwards after three warmups. Delta is PR minus baseline within each pair; negative means faster.
First use regressed in every pair: approximately 1.22–1.23 seconds more on the PR, despite primed disk caches. Warm paired medians favored the PR by 0.65 ms and 0.44 ms, respectively, but both ranges cross zero. These data do not establish a reliable warm speedup, and the first-use cost dominates for one-off calls.
Reproduction
Copy the PR’s
examples/qwen3_vl_tower_timing.rsunchanged into the baseline checkout. In each checkout, build and save the executable under the corresponding name:Set MODEL to the local model directory. Run on an otherwise idle GB10 under the shared device lock, with a common persistent PTX cache:
Correctness: CUDA Qwen3-VL library tests (64 passed, 1 ignored) include exact eager/compiled f32, f16 and bf16 parity and a deterministic f16 rounding regression. In the earlier two-image validation, the main and three DeepStack outputs matched byte-for-byte; a 16-token greedy continuation matched on the smaller image. Workspace formatting passed. Metal, server latency and other models were not measured.