Skip to content

WoA: work around MSVC ARM64 miscompile in NEON bf16 conversion - #2155

Open
matthewdouglas wants to merge 1 commit into
mainfrom
fix/msvc-arm64-bf16-miscompile
Open

matthewdouglas wants to merge 1 commit into
mainfrom
fix/msvc-arm64-bf16-miscompile

Conversation

@matthewdouglas

Copy link
Copy Markdown
Member

Since GitHub moved the windows-11-arm runner to the VS2026 image on Sep 30 (MSVC 14.51, then 14.52 since mid-November), the Windows ARM64 CPU tests have been failing for every torch version: bf16 dequantization returns NaN or garbage. There were 7 failures under 14.51 and 328 under 14.52, with no code change on our side. 0.50.2 was built before the image change and isn't affected.

The cause is a known MSVC ARM64 codegen bug (google/XNNPACK#11368). In neon_f32_to_bf16x4, the compiler fuses the integer rounding add with the preceding float multiply into an integer MLA on the float bit patterns. This change uses vaddhn_u32 instead of vaddq_u32 + vshrn_n_u32, the same workaround XNNPACK used (google/XNNPACK#11330). The result is bit-identical, and it's one instruction shorter on all compilers.

I checked the built libbitsandbytes_cpu.dll from this branch: the 5 integer mla instructions at the bf16 conversion sites are gone, replaced by addhn.

cpu_ops.cpp is built into every backend library, so this also fixes bf16 dequantization of CPU tensors in the Windows ARM64 CUDA builds.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant