fix(xla): load bf16 affine quant scales in the OpenXLA weight loader#569
Merged
Conversation
The XLA 4bit/8bit dequant loader hardcoded an f16 expectation for the affine scales/biases and rejected anything else. The pre-existing baselines (Llama-3.2-1B, Qwen2.5-0.5B) happen to store f16 scales, so it went unnoticed, but every Qwen3 dense checkpoint, Gemma3-27B, and Qwen3-MoE store bf16 scales, so `XlaReferenceEngine::load` failed with "scales/biases dtype BF16/BF16, expected F16" and those architectures could not load or generate on the XLA path at all. Thread a `scales_bf16` flag through `dequantize_affine` and `dequantize_affine_stacked` and widen the matching 16-bit format to f32 via the existing `bf16_to_f32` (both f16 and bf16 are exact in f32). `iree.rs` now accepts a matching F16 or BF16 scale/bias pair and rejects only a mismatched or non-16-bit pair. This completes the "loads and generates via CLI" acceptance for the Qwen3 / Gemma3 / MoE families added in epic #493. Adds a bf16-scales dequant unit test (2.0/0.5/10.0/-1.0 are exact in bf16, so the recovered row matches the f16 hand example).
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.
The XLA 4bit/8bit dequant loader hardcoded an f16 expectation for the affine scales/biases and rejected anything else. The pre-existing baselines (Llama-3.2-1B, Qwen2.5-0.5B) store f16 scales so it went unnoticed, but every Qwen3 dense checkpoint, Gemma3-27B, and Qwen3-MoE store bf16 scales, so
XlaReferenceEngine::loadfailed with "scales/biases dtype BF16/BF16, expected F16" and those architectures could not load or generate on the XLA path at all. This surfaced during the epic #493 GPU (xla-iree, CUDA) validation sweep.Thread a
scales_bf16flag throughdequantize_affineanddequantize_affine_stackedand widen the matching 16-bit format to f32 via the existingbf16_to_f32(both f16 and bf16 are exact in f32).iree.rsnow accepts a matching F16 or BF16 scale/bias pair and rejects only a mismatched or non-16-bit pair. This completes the "loads and generates via CLI" acceptance for the Qwen3 / Gemma3 / MoE families added in epic #493.Validation: new bf16-scales dequant unit test (2.0/0.5/10.0/-1.0 are exact in bf16, recovered row matches the f16 hand example); full mlxcel-xla lib suite green (112 passed); clippy/fmt clean. On a GB10 with the xla-iree CUDA build, qwen3-0.6b-4bit (bf16 scales) is now token-exact single-sequence vs the HF fp32 oracle (was previously unloadable), and gemma3-1b-4bit + stablelm-1.6b-4bit pass both the single-seq and serve gates.
Relates to #493.