[PR #487] Fix IQ1_S/IQ2_S/IQ3_S MMQ decoding on Windows CUDA #558

Open
opened 2026-10-29 21:26:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/487
Author: @Fringe210
Created: 10/25/2026
Status: 🔄 Open

Base: main ← Head: fix/glm-iq-mmq-prefill


📝 Commits (1)

  • ae26bf6 fix(cuda): correct IQ S MMQ decoding and partial expert tile IDs

📊 Changes

6 files changed (+428 additions, -33 deletions)

View changed files

📝 CMakeLists.txt (+9 -3)
➕ docs/GLM_MMQ_CORRECTNESS.md (+80 -0)
📝 tests/glm_mmq_glu_test.cu (+33 -0)
➕ tests/glm_prefill_probe.cpp (+71 -0)
📝 third_party/ggml/mmq-fused-swiglu.patch (+118 -30)
➕ tools/check_glm_conversations.py (+117 -0)

📄 Description

GLM conversations on Windows/CUDA 13.2 could ignore the latest turn, repeat earlier text or invent an unrelated translation task when using batched prefill. The same weights, prompt and API request worked through token-at-a-time prefill; disabling the CPU expert lane or fused SwiGLU did not fix it.

The IQ1_S/IQ2_S/IQ3_S MMQ loaders read codebook and sign bytes through pointers to local packed registers. In the affected build these reads produced incorrect indices, including out-of-bounds codebook accesses. Extract unsigned bytes explicitly with shifts/masks for both plain and fused products. Also guard unused destination-ID reads in the last partial expert tile.

Extend the existing fused/plain regression with independent CPU dequantization and scalar double-precision dots: fused/plain parity alone passed when both products were wrong. Non-finite values now fail both parity modes. Add --iq-s-only for targeted memory checks, a full-pack prefill diagnostic and a conversation acceptance harness. The patch still applies to CMake's build-tree copy of the pinned GGML sources.

Before/after on the same hardware

Base: 4615f346d9311dd1ce9f5738ab04446f023a6e42 (v1.1.27). Windows, NVIDIA RTX PRO 6000 Blackwell sm_120, driver 596.86, CUDA 13.2, Maya-M.

Independent dot relative L2 Before After
IQ1_S 1.18493 0.0107327
IQ2_S 0.778627 0.00366127
IQ3_S 0.966161 0.00720439

Full-model prefill/token KL decreased from 3.48662072 to 0.0674770672 and the next-token argmax agreed after the byte fix. This full-pack measurement preceded the additional partial-ID guards; the final guarded kernels passed the memory checks below. Numerical output changes intentionally because the affected original products were incorrect.

Validation

  • Reapplied the PR patch to pristine pinned sources and checked that both resulting CUDA files match the compiled corrected sources.
  • Rebuilt and ran glm_mmq_glu_test: 14 formats, two expert-row profiles, clamped/unclamped fused/plain checks and independent CPU-dot comparisons all passed.
  • compute-sanitizer --tool memcheck --error-exitcode 88 .../glm_mmq_glu_test --iq-s-only: all affected formats passed; 0 errors.
  • python tools/check_hip_compat.py: passed.
  • Twenty-six real-server cases previously passed with these final kernels and the separately submitted small-output reasoning-budget fix, including latest-turn correction, cached conversation switching, streaming/cancellation recovery and prompts up to 31851 tokens. A subsequent 229041-token prompt with a 32768-token completion allowance recovered a code from its first turn.
  • Full Python suites: Python 3.12 on Linux (WSL): server discovery 370 run, 364 passed, 6 skipped; installer/tools discovery 393 run, 365 passed, 28 skipped. Skipped cases are not counted as verified. These full Python suites were run from the independent reasoning-budget branch.

Measurements and reproduction commands are in docs/GLM_MMQ_CORRECTNESS.md. GPU numerical tests were performed on this Blackwell/CUDA configuration; other GPUs, toolkits and HIP hardware were not exercised. No performance improvement is claimed.


🔄 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/mw00/project-maya/pull/487 **Author:** [@Fringe210](https://github.com/Fringe210) **Created:** 10/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/glm-iq-mmq-prefill` --- ### 📝 Commits (1) - [`ae26bf6`](https://github.com/mw00/project-maya/commit/ae26bf6ea2053116970d6179a92255d33e80777f) fix(cuda): correct IQ S MMQ decoding and partial expert tile IDs ### 📊 Changes **6 files changed** (+428 additions, -33 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+9 -3) ➕ `docs/GLM_MMQ_CORRECTNESS.md` (+80 -0) 📝 `tests/glm_mmq_glu_test.cu` (+33 -0) ➕ `tests/glm_prefill_probe.cpp` (+71 -0) 📝 `third_party/ggml/mmq-fused-swiglu.patch` (+118 -30) ➕ `tools/check_glm_conversations.py` (+117 -0) </details> ### 📄 Description GLM conversations on Windows/CUDA 13.2 could ignore the latest turn, repeat earlier text or invent an unrelated translation task when using batched prefill. The same weights, prompt and API request worked through token-at-a-time prefill; disabling the CPU expert lane or fused SwiGLU did not fix it. The IQ1_S/IQ2_S/IQ3_S MMQ loaders read codebook and sign bytes through pointers to local packed registers. In the affected build these reads produced incorrect indices, including out-of-bounds codebook accesses. Extract unsigned bytes explicitly with shifts/masks for both plain and fused products. Also guard unused destination-ID reads in the last partial expert tile. Extend the existing fused/plain regression with independent CPU dequantization and scalar double-precision dots: fused/plain parity alone passed when both products were wrong. Non-finite values now fail both parity modes. Add `--iq-s-only` for targeted memory checks, a full-pack prefill diagnostic and a conversation acceptance harness. The patch still applies to CMake's build-tree copy of the pinned GGML sources. ### Before/after on the same hardware Base: `4615f346d9311dd1ce9f5738ab04446f023a6e42` (v1.1.27). Windows, NVIDIA RTX PRO 6000 Blackwell sm_120, driver 596.86, CUDA 13.2, Maya-M. | Independent dot relative L2 | Before | After | | --- | ---: | ---: | | IQ1_S | 1.18493 | 0.0107327 | | IQ2_S | 0.778627 | 0.00366127 | | IQ3_S | 0.966161 | 0.00720439 | Full-model prefill/token KL decreased from 3.48662072 to 0.0674770672 and the next-token argmax agreed after the byte fix. This full-pack measurement preceded the additional partial-ID guards; the final guarded kernels passed the memory checks below. Numerical output changes intentionally because the affected original products were incorrect. ### Validation - Reapplied the PR patch to pristine pinned sources and checked that both resulting CUDA files match the compiled corrected sources. - Rebuilt and ran `glm_mmq_glu_test`: 14 formats, two expert-row profiles, clamped/unclamped fused/plain checks and independent CPU-dot comparisons all passed. - `compute-sanitizer --tool memcheck --error-exitcode 88 .../glm_mmq_glu_test --iq-s-only`: all affected formats passed; **0 errors**. - `python tools/check_hip_compat.py`: passed. - Twenty-six real-server cases previously passed with these final kernels and the separately submitted small-output reasoning-budget fix, including latest-turn correction, cached conversation switching, streaming/cancellation recovery and prompts up to 31851 tokens. A subsequent 229041-token prompt with a 32768-token completion allowance recovered a code from its first turn. - Full Python suites: Python 3.12 on Linux (WSL): server discovery **370 run, 364 passed, 6 skipped**; installer/tools discovery **393 run, 365 passed, 28 skipped**. Skipped cases are not counted as verified. These full Python suites were run from the independent reasoning-budget branch. Measurements and reproduction commands are in `docs/GLM_MMQ_CORRECTNESS.md`. GPU numerical tests were performed on this Blackwell/CUDA configuration; other GPUs, toolkits and HIP hardware were not exercised. No performance improvement is claimed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#558
No description provided.