esimd: fix INT4 router residual race for all shapes - #675
Merged
Conversation
Split residual-add/RMSNorm from router GEMV so every work-group consumes the same normalized vector. Reuse the existing optimized INT4 GEMV dispatcher to limit the performance cost and add a high-N regression test. Co-authored-by: OpenAI Codex <noreply@openai.com>
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
Fixes #671.
Root cause
The fused kernel launches one work-group per router output row. Every work-group reads
residual, while only then == 0work-group updates it in place. SYCL does not provide a global barrier across those work-groups, so later-scheduled groups can read the updated residual and effectively addhiddentwice. This perturbs router logits and eventually causes the repeated-token/NaN failure seen withsym_int4and aggressive but valid sampling parameters.PR #399 addresses the same race only for
N > 512. That threshold is not a correctness guarantee: issue #671 reproduces in Qwen3.6-35B-A3B with a 256-expert router under the real TP=2 workload. This change removes the cross-work-group dependency for every shape.Performance
The fix adds one device kernel submission but no host synchronization. RMSNorm is computed once, then the existing tuned INT4 GEMV implementation is used.
On card 2, the existing 1,000-iteration microbenchmark at
N=128, K=2048measured 11.8 us before and 13.1-13.6 us after: +1.3 to +1.8 us (about 11-15%). The absolute per-layer increase corresponds to well below 1% of observed end-to-end decode time. The final model run sustained about 62 tokens/s after warmup; no end-to-end regression was observed.Validation
Built and reinstalled the wheel using the workspace oneAPI flow:
ZE_AFFINITY_MASK=2 pytest -q tests/test_resadd_norm_gemv_int4.py: 11 passedsym_int4, FP16, TP=2 on cards 2/3, exact issue sampling parameters: seeds 0-4 each generated 1,024 tokens with zero repeated!runs!!, 19.9 secondsDisclosure
This change was developed with OpenAI Codex assistance. The submitter is responsible for reviewing every changed line and the validation evidence before merge.