[PR #154] [CLOSED] Correctness fixes from #149 (s_gemv barrier, bf16 NaN, QSA page mask, verify-window bounds, MSVC, test build) #2479

Closed
opened 2026-11-04 02:00:34 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/154
Author: @gputier
Created: 9/29/2026
Status: ❌ Closed

Base: main ← Head: fix/correctness


📝 Commits (6)

  • 9c1a8a1 s_gemv: the q8 split kernel reaches its barrier before a rowless warp returns
  • dc6022d bf16: a NaN stays a quiet NaN in f32 -> bf16, as in ggml
  • df94c1d qsa: mask cells whose page did not resolve; refuse a clock sweep over fewer slots than the resolve block
  • 7426fe2 expert_source, s2_expert_grouped: guard the verify window's fixed tables
  • f51ad78 gguf_reader.hpp: define NOMINMAX before windows.h
  • de33f38 build: guard the last two bench/micro targets on their file, as upstream does for the others

📊 Changes

12 files changed (+316 additions, -16 deletions)

View changed files

📝 CMakeLists.txt (+10 -6)
📝 include/strata/artifact/gguf_reader.hpp (+3 -0)
📝 include/strata/kernels/bf16_bits.hpp (+7 -0)
📝 src/core/expert_source.cpp (+17 -3)
➕ src/kernels/bf16_bits_test.cpp (+80 -0)
📝 src/kernels/cuda/dequant_bf16.cu (+3 -0)
📝 src/kernels/cuda/kv_stream.cu (+8 -0)
📝 src/kernels/cuda/qsa_decode_attn.cu (+7 -4)
📝 src/kernels/cuda/s2_expert_grouped.cu (+4 -0)
📝 src/kernels/cuda/s_gemv.cu (+11 -3)
📝 src/kernels/elementwise_parity.cpp (+59 -0)
📝 src/kernels/s_gemv_q8k_parity.cpp (+107 -0)

📄 Description

The correctness fixes offered in #149, on top of 0.1.26 (ac8b251). One commit per fix; each is small and changes no result outside the case it fixes.

  • s_gemv: in s_gemv_q8_split_kernel, a warp with no row returned before the __syncthreads() that follows the codebook load. The codebook is now loaded first, then the rowless warp returns. s_gemv_q8k_parity gains output widths that are not a multiple of the eight rows per block.
  • bf16: the rounding add in bf16_from_f32 carried a NaN out of the mantissa (0x7FFFFFFF came back as -0, 0x7F800001 as +inf). A NaN now stays a quiet NaN, as in ggml; bf16_bits_test checks all 2^32 inputs against ggml's rule, and elementwise_parity covers the device side, including the second copy in dequant_bf16.cu. The HIP __builtin_memcpy branch is kept as is; the NaN check comes right after it, so it applies to every backend.
  • qsa: a cell whose KV-streaming page did not resolve (-1) was read anyway in qsa_decode_attn; it is now masked with weight 0. kv_stream stops with a message when asked to sweep fewer slots than the resolve block, where two threads could take the same slot (the engine never goes below 5,120 slots, so this is a guard).
  • expert_source: the verify window's fixed tables (kind[128], distinct[128]) are bounded by a static_assert and a runtime check on n_tok * k, and s2_expert_grouped asserts its group limit covers the window.
  • gguf_reader.hpp: NOMINMAX before windows.h, so every file that reaches this header can use std::min/std::max under MSVC (gguf_reader_test.cpp, native_dense.cpp and native_head.cpp include it without defining it).
  • build: 0.1.26 already guards graph_registry_test and pinned_capture on their file. The two bench/micro/ targets still unguarded, native_mmvq_multi and hit_cpu_order_parity, get the same EXISTS check, with the backend variables.

Before the rebase: tested on an RTX 5090 (Windows 11, MSVC 2022, CUDA 13.4, sm_120), ctest 30 of 33, the three failures being missing model files on my side (ple_parity wants a Q2_0 PLE table, expert_parity and pool_test want pack/full/experts.bin).

After the rebase on 0.1.26: the four code fixes are byte-identical to the tested ones (git range-diff); only the bf16_bits.hpp conflict and the CMake commit changed. Checked on x86-64 Linux, CPU only: configure and build clean, bf16_bits_test passes (0 differences from ggml over 2^32 inputs), 10 of 11 CPU tests pass, and the failing one, expert_multi_test, fails the same way on plain 0.1.26. The CUDA and HIP paths were not rebuilt after the rebase, so your byte-identity gate is the check there.

qsa_decode_attn and s2_expert_grouped have no ctest target, so the build is their only check.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/154 **Author:** [@gputier](https://github.com/gputier) **Created:** 9/29/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/correctness` --- ### 📝 Commits (6) - [`9c1a8a1`](https://github.com/Niko1221/Strata/commit/9c1a8a1d97d57d31bc828e139f180891f65091d2) s_gemv: the q8 split kernel reaches its barrier before a rowless warp returns - [`dc6022d`](https://github.com/Niko1221/Strata/commit/dc6022db49e8bf0cbb859cfec80bebace811bb49) bf16: a NaN stays a quiet NaN in f32 -> bf16, as in ggml - [`df94c1d`](https://github.com/Niko1221/Strata/commit/df94c1d68ea4bd2aee110579442a5cf8cb4e44f4) qsa: mask cells whose page did not resolve; refuse a clock sweep over fewer slots than the resolve block - [`7426fe2`](https://github.com/Niko1221/Strata/commit/7426fe2f34c629b067687ac1398a79c2897a8fe9) expert_source, s2_expert_grouped: guard the verify window's fixed tables - [`f51ad78`](https://github.com/Niko1221/Strata/commit/f51ad78aab6a6acdc916362406cbfc408c17267a) gguf_reader.hpp: define NOMINMAX before windows.h - [`de33f38`](https://github.com/Niko1221/Strata/commit/de33f380f8972baa275941baf88f375d173bb6c1) build: guard the last two bench/micro targets on their file, as upstream does for the others ### 📊 Changes **12 files changed** (+316 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+10 -6) 📝 `include/strata/artifact/gguf_reader.hpp` (+3 -0) 📝 `include/strata/kernels/bf16_bits.hpp` (+7 -0) 📝 `src/core/expert_source.cpp` (+17 -3) ➕ `src/kernels/bf16_bits_test.cpp` (+80 -0) 📝 `src/kernels/cuda/dequant_bf16.cu` (+3 -0) 📝 `src/kernels/cuda/kv_stream.cu` (+8 -0) 📝 `src/kernels/cuda/qsa_decode_attn.cu` (+7 -4) 📝 `src/kernels/cuda/s2_expert_grouped.cu` (+4 -0) 📝 `src/kernels/cuda/s_gemv.cu` (+11 -3) 📝 `src/kernels/elementwise_parity.cpp` (+59 -0) 📝 `src/kernels/s_gemv_q8k_parity.cpp` (+107 -0) </details> ### 📄 Description The correctness fixes offered in #149, on top of 0.1.26 (ac8b251). One commit per fix; each is small and changes no result outside the case it fixes. - `s_gemv`: in `s_gemv_q8_split_kernel`, a warp with no row returned before the `__syncthreads()` that follows the codebook load. The codebook is now loaded first, then the rowless warp returns. `s_gemv_q8k_parity` gains output widths that are not a multiple of the eight rows per block. - `bf16`: the rounding add in `bf16_from_f32` carried a NaN out of the mantissa (0x7FFFFFFF came back as -0, 0x7F800001 as +inf). A NaN now stays a quiet NaN, as in ggml; `bf16_bits_test` checks all 2^32 inputs against ggml's rule, and `elementwise_parity` covers the device side, including the second copy in `dequant_bf16.cu`. The HIP `__builtin_memcpy` branch is kept as is; the NaN check comes right after it, so it applies to every backend. - `qsa`: a cell whose KV-streaming page did not resolve (-1) was read anyway in `qsa_decode_attn`; it is now masked with weight 0. `kv_stream` stops with a message when asked to sweep fewer slots than the resolve block, where two threads could take the same slot (the engine never goes below 5,120 slots, so this is a guard). - `expert_source`: the verify window's fixed tables (`kind[128]`, `distinct[128]`) are bounded by a `static_assert` and a runtime check on `n_tok * k`, and `s2_expert_grouped` asserts its group limit covers the window. - `gguf_reader.hpp`: `NOMINMAX` before `windows.h`, so every file that reaches this header can use `std::min`/`std::max` under MSVC (`gguf_reader_test.cpp`, `native_dense.cpp` and `native_head.cpp` include it without defining it). - build: 0.1.26 already guards `graph_registry_test` and `pinned_capture` on their file. The two `bench/micro/` targets still unguarded, `native_mmvq_multi` and `hit_cpu_order_parity`, get the same `EXISTS` check, with the backend variables. Before the rebase: tested on an RTX 5090 (Windows 11, MSVC 2022, CUDA 13.4, sm_120), ctest 30 of 33, the three failures being missing model files on my side (`ple_parity` wants a Q2_0 PLE table, `expert_parity` and `pool_test` want `pack/full/experts.bin`). After the rebase on 0.1.26: the four code fixes are byte-identical to the tested ones (`git range-diff`); only the `bf16_bits.hpp` conflict and the CMake commit changed. Checked on x86-64 Linux, CPU only: configure and build clean, `bf16_bits_test` passes (0 differences from ggml over 2^32 inputs), 10 of 11 CPU tests pass, and the failing one, `expert_multi_test`, fails the same way on plain 0.1.26. The CUDA and HIP paths were not rebuilt after the rebase, so your byte-identity gate is the check there. `qsa_decode_attn` and `s2_expert_grouped` have no ctest target, so the build is their only check. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:00:34 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2479
No description provided.