Repository navigation
Qwen 3.5 CUDA: host bf16 weight copies use core's rounding, so a NaN weight stays NaN (#1863) - #1986
Merged
Merged
Conversation
…und.bits (#1863) cuda_weights.zig's f32bf16 (norm weights + 1, dequantized router rows), cuda_exl3_weights.zig's bf16Of (EXL3 norms 1 + w, widened f16 vectors) and cuda_draft_weights.zig's toBf16 (DFlash2 affine-4 scales and biases) rounded with a wrapping add and no NaN branch, so 131,072 fp32 NaNs became +-0 or +-Inf at load: a NaN weight could load as a finite zero. They are now core's bits(), which the rest of the engine uses. Every non-NaN input keeps its bits; a NaN stays a NaN with its sign. Each loader gets a host test with its old copy as the oracle: every word with exponent 0 or 255 (zeros, subnormals, infinities, every NaN), every bf16 bucket's tie and edges, 4M random words, and quiet and signalling NaNs of both signs, including 0x7fff8001 and 0xffff8001, which the old copies turned into -0 and +0.
ashhart
force-pushed
the
lead/1863-bf16
branch
from
November 3, 2026 06:52
0169230 to
e8ba52a
Compare
This was referenced Nov 3, 2026
Merged
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.
Part of #1863. Three Qwen 3.5 CUDA weight loaders rounded fp32 to bf16 with their own wrapping copies, which could turn a NaN weight into a finite value (+-0 or +-Inf) at load:
qwen3_5/cuda_weights.zig:f32bf16(norm weights + 1, and dequantized rows);qwen3_5/cuda_exl3_weights.zig:bf16Of(EXL3 norm weights, widened vectors);qwen3_5/cuda_draft_weights.zig:toBf16(drafter affine-4 scales and biases).Each now calls core's
bf16_round.bits. On every finite input and every rounding tie the result is bit-identical (old-as-oracle tests, each shown failing first), NaN stays NaN and Inf passes through, so no token receipt is needed. Independent review: LAND. The remaining copies elsewhere follow in a separate PR.