Repository navigation
perf(dflash, glm5_next): reuse nax sparse attention - #4342
Merged
Merged
Conversation
jundot
added a commit
that referenced
this pull request
Oct 9, 2026
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.
Summary
This PR reuses existing NAX attn kernel (already used for attn during prefill) for block verify.
Validation
M5U 80c 256gb
GLM5.3-Flash-4bit affine
GLM5.3-Flash-oQ4e
Validated performance and parity against main 2238a44
Stacked with #4338 against main:
Since the acceptance is varied, the gain seems a bit higher. The overall gain against similar acceptance result looks to be around +4.3%.
Tested with this script:
check.py
``` python import argparse import asyncio import gc import hashlib import json import logging import statistics import subprocess import sys import time from dataclasses import replace from pathlib import PathNAX attention is not producing identical results to existing baseline. The drift comes from different intermediate precision, however it turns out NAX route has more accurate math.
Stock 512-wide SDPA rounds QK scores and normalized softmax probabilities to BF16. NAX attention keeps them near FP32 precision until the final output.
Small synthetic checks with 64 heads, 512-wide latents and 2,051 selected keys reproduces the drift:
These are relative L2 differences. Against an independent FP64 reference, NAX’s error was 0.166%, versus 0.534–0.558% for SDPA. So NAX is mathematically more accurate here:
parity_probe.py
```python """Synthetic sparse-attention precision check; no model loading or timing.All relevant tests pass. Added 2 additional tests for the nax route and fallback.
Checklist