Skip to content

Qwen 3.5 CUDA: host bf16 weight copies use core's rounding, so a NaN weight stays NaN (#1863) - #1986

Merged
ashhart merged 2 commits into
mainfrom
lead/1863-bf16
Nov 3, 2026
Merged

ashhart merged 2 commits into
mainfrom
lead/1863-bf16

Conversation

@ashhart

@ashhart ashhart commented Nov 3, 2026

Copy link
Copy Markdown
Owner

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.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant