Repository navigation
update(xla): round the Qwen3-VL vision tower at eager's BF16 boundaries - #3336
Conversation
The XLA Qwen3-VL vision graph ran in f32 while eager MLX runs the BF16 checkpoint's tower on BF16 tensors, so the two drifted apart over 24 blocks and the fixture's greedy output split at a near-tie (index 8). The graph now keeps its f32 ABI carrier but rounds to BF16 wherever eager stores a BF16 tensor: input patches, patch embedding, interpolated position embeddings, each linear (product, then bias add), LayerNorm (normalized value, weight product, bias sum, as MLX's CUDA kernel does), RoPE'd query and key, attention probabilities and context, GELU outputs, residual adds, and both mergers. Reductions, softmax statistics, and GEMMs still accumulate in f32. Rounding is integer round-to-nearest-even on the bit pattern, so the graph lowers on Metal too; contractions read BF16 where the target supports it and the BF16-exact f32 carrier on Metal. The operator numeric contract declares the BF16 output rounding on every operator except the attention scores, so the v3 auxiliary manifest's contract digest changes and cached f32 artifacts recompile. Validated on GB10: per-block same-input controls pass at 0.08/0.08, Qwen3-VL greedy on the fixture now matches eager through index 26 (index 27 is an exact eager BF16 tie), and Qwen2.5-VL stays token-exact. Refs #3291
Implementation Review SummaryIntent
Rounding points checked against eagerEvery point matches the eager source for this checkpoint, whose vision tower is unquantized BF16, so every linear is
No rounding point is wrong or missing. Each merger's drift moves in the same direction as the chained drift of the block that feeds it, in 8 of 8 image/merger pairs (blocks 5/11/17/23 against DeepStack 0/1/2 and the main merger). DeepStack merger 0, whose input drift is under one step, stays within half a step. The fixture's main merger got worse (1.52 to 5.16) because its input, block 23, got worse (1020 to 1100). The merger itself is not the cause. Remaining Items
Verification
|
|
Security and performance review of the BF16 rounding change: no CRITICAL or HIGH findings, no commits pushed. Cache binding: the vmfb path comes from Shape arithmetic: the new ops derive every dimension from the validated config and the static patch bucket ( Performance: the converts and selects are elementwise integer ops that XLA fuses, and the reported warm vision time did not regress (1.85s to 1.67s, single run). LOW: the flash-attention running maximum is approximated by the row maximum (documented in the code), which is a parity nuance, not a safety issue. Ran |
…elog Pin qwen3_vl_vision_precision to F32 on Metal and BF16 on CUDA, and emit the full vision graph at the Metal precision for the smallest and largest buckets, asserting the MLIR names no bf16 type. Correct the Metal doc comment: the f32 carrier forms the same products only while the vision weights are BF16-exact, which a quantized vision tower is not. Add the Changed entry for the operator numeric contract change, including the one-time artifact recompile. Validation: - cargo test -p mlxcel-xla --lib --profile test-fast qwen3_vl: 17 passed Refs #3291
Adds the English and Korean reports for the Qwen3-VL vision BF16 rounding change: the op-by-op rounding design, the integer round-to-nearest-even with NaN guard, the contract and digest change, results, the revised acceptance criteria, and the remaining limits.
Summary
The XLA Qwen3-VL vision graph now rounds to BF16 wherever eager MLX stores a BF16 tensor for the BF16 checkpoint, instead of running the whole tower in f32. GEMMs, norm reductions and softmax statistics still accumulate in f32, as MLX's kernels do.
emitter/qwen3_vl_ops.rs): input patches; patch embedding and every linear (matmul product, then bias add, two roundings); interpolated position embeddings (f32 corner sum(c0+c1)+(c2+c3), then one rounding); LayerNorm as MLX's CUDA kernel computes it (f32 stats, then normalized value,w*nand+beach rounded); RoPE'd q and k; attention as cuDNN flash SDPA computes it (f32 scores and row sum, BF16 unnormalized probabilities into the value GEMM, normalized context rounded); both GELUs (f32, rounded once); residual adds; main and DeepStack mergers.qwen3_vl_vision_precision(device)).ae5bfb35...tobdd1632d..., and the artifact from18e85256...(defac5fb) to4d3934a5...(775dbb9f). The old cached artifact is not reused.Results (GB10 CUDA,
xla_qwen3_vl_deepstack_check, atol/rtol 0.08 unchanged)iree_vision_seconds(single run)Same-input controls of the production eager block now sit at 1 BF16 step or less in every block except fixture block 10 (2 steps; report-only, was 0.338). Index 27 is an exact eager tie, 576 and 2619 both at 30.375 (margin 0.0). XLA has 2619 over 576 by 0.021, inside one BF16 step (0.125) at that magnitude.
Criteria revised by the maintainer on #3291: chained block-23 drift (184 against Qwen2.5-VL's 133) is recorded, not gated, because block 10 amplifies 1-step summation-order differences about 40x on both images and matching rounding boundaries cannot remove that; final-logit drift passes. The report-only block-23
host_dequant_dense_f32control compares against an f32 reference, which BF16 matching is expected to widen (6 values over tolerance on shapes224, BF16 cancellation at magnitude 2545 where one step is 16); the fused control against eager BF16 keeps the 2 failures already present on main. No tolerance changed.Finalization added tests pinning
qwen3_vl_vision_precisionper target and asserting the Metal-precision graph contains nobf16type, and a CHANGELOG entry.Test plan
cargo test -p mlxcel-xla --lib qwen3_vl(17 pass) andoperator_numeric_contract;cargo clippy -p mlxcel-xla --lib --tests -- -D warningscargo check --features cuda,xla-iree --all-targets;cargo check --no-default-features --features xla-diagnostics --all-targets--token-idsat indexes 8 and 27, before and aftermlxcel generate -n 64 --temp 0, eager vsMLXCEL_BACKEND=xla, for qwen3-vl-2b-instruct-4bit and qwen2.5-vl-3b-instruct-4bitCloses #3291