Skip to content

fix(xla): load bf16 affine quant scales in the OpenXLA weight loader - #569

Merged
inureyes merged 2 commits into
mainfrom
fix/xla-bf16-quant-scales
Jul 1, 2026
Merged

inureyes merged 2 commits into
mainfrom
fix/xla-bf16-quant-scales

Conversation

@inureyes

@inureyes inureyes commented Jul 1, 2026

Copy link
Copy Markdown
Member

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::load failed 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_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.

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.

inureyes added 2 commits July 1, 2026 15:42
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).
@inureyes
inureyes merged commit ad6e786 into main Jul 1, 2026
5 checks passed
@inureyes
inureyes deleted the fix/xla-bf16-quant-scales branch July 1, 2026 06:58
@inureyes inureyes self-assigned this Aug 31, 2026
@inureyes inureyes added status:done Completed type:bug Bug fixes, error corrections, or issue resolutions labels Sep 6, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…ablup#569)

* fix(xla): load bf16 affine quant scales in the OpenXLA weight loader

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 lablup#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).

* style(xla): rustfmt-wrap the bf16 stacked-dequant test call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant