mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2955] [Engine] f32 -> bf16 conversions in PLE and prefill keep a NaN a NaN (as bf16_bits.hpp does) #4359
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4359
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2955
Author: @sergqwer
Created: 10/17/2026
Status: 🔄 Open
Base:
main← Head:pr/bf16-nan📝 Commits (1)
c52d60bengine: f32 -> bf16 conversions in PLE and prefill keep a NaN a NaN, as bf16_bits.hpp does📊 Changes
3 files changed (+9 additions, -1 deletions)
View changed files
📝
src/kernels/cuda/ple.cu(+2 -0)📝
src/prefill/kernels.cu(+2 -0)📝
src/prefill/prefill.cpp(+5 -1)📄 Description
Problem and result
The engine has private f32 -> bf16 helpers that round to nearest even. Unlike
bf16_bits.hpp(bf16_from_f32) anddequant_bf16.cu, they have no NaN test. The rounding add carries a NaN out of the mantissa, so a NaN is masked instead of reaching the NaN guard: for example 0x7FFFFFFF (the NaN pattern in #879) becomes 0x8000, i.e. -0.bf16_bits(PLE) andbf(prefill) as -0, +0 or an infinity.Related discussion
None needed: a focused correctness fix. It was #2955 before the 0.2.0-beta tracker reset, unchanged except for the rebase. The fix is sebastianrcnt's (sebastianrcnt/Strata ef1a7ef5), co-author of the commit.
Approach
Each helper tests the magnitude bits first and returns the top half with the quiet bit set (
(i >> 16) | 64), sign kept, asbf16_bits.hppdoes:src/kernels/cuda/ple.cubf16_bits(to_bf16_kernel);src/prefill/kernels.cubf: the BF16 activation image of every prefill norm, plusbf_loand dequant.The two host dumps in
src/prefill/prefill.cppget the same test:STRATA_PREFILL_DUMP_R_ALL(round to nearest even) and theSTRATA_DBG_FEATroute record (round half up; that rounding is kept, only the NaN test is new).Left alone: host references in parity tests and benches (finite data),
fused_gr.cuhc_q8_bf16_kernel(weights x scales, documented as finite) andsycl/. Onmainthe set of private0x7fffrounding sites is the same as on 0.1.45, so the rebase found no new helper to cover.Validation
Revision: this branch, one commit
c52d60b3onmaine88ee39d(v0.2.0-beta + 12 commits), against a build ofmaine88ee39ditself. Machine: RTX 5090 (sm_120), Ryzen 9 9950X3D, 128 GB, Windows 11; MSVC 2022 17.14, CUDA 13.3, Ninja, release configure-DSTRATA_ENABLE_CUDA=ON -DSTRATA_PORTABLE=ON -DCMAKE_CUDA_ARCHITECTURES="75-real;86-real;89-real;120-real" -DSTRATA_GGML_DIR=<llama.cpp at the pinned 3cf03257>, targetstrata.Passed:
All 2^32 f32 bit patterns. A generated CUDA file holds the four helpers verbatim from
main(old) and from this branch (new); built withnvcc -O2 -std=c++17 -gencode arch=compute_120,code=sm_120 -I <this branch>/include. Host (all four helpers) and device (the two device helpers, RTX 5090):bf16_from_f32bf16_bits/bfmasked (of 16,777,214)Engine identity on the NVFP4 GPTQ pack (
Maximilian228/Qwen3.8-Flash-Next-NVFP4-GPTQ-Strata, upstream setup's--family nvfp4 --model NVFP4file set).strata --servewith setup's model files plus--expert-cache 3000 --prefill auto --spec 6 --spec-min-p 0.7 --max-context 262144 --kv int8 --gpu 0 --pcie-frac 0 --adapt-every 1000000, envSTRATA_PREFILL_CPU_SHARE=0 STRATA_PCIE_BALANCE=0 STRATA_IQ_MT_MIN=1 STRATA_DUMP_FIRST_LOGITS=<file>; a 2,100-token and a 32,037-token prompt, 32 greedy tokens each (both stop at the end of turn). First-token logits and tokens are byte-identical tomain's:maintwice, this branch)1e9c612c2e6c7a32...f5b2872c7ac30b17...(
maine88ee39dgives the same hashes as v0.1.45 did.)Failed: none observed.
Not run:
ple.cuandkernels.cuare compiled for HIP too; no ROCm toolchain here. The change is plain integer code.prefill.cpp(the two host dumps); no Mac here.sycl/has its own copies, left as they are).Limits
Only these four helpers. The host references in tests and benches and
hc_q8_bf16_kernelkeep their plain rounding, because their inputs are finite.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.