fix(dsa): skip invalid slots in sparse indexer backward - #6166
Open
QiZhangNV wants to merge 2 commits into
Open
Conversation
Signed-off-by: qizhang <qizhang@nvidia.com>
Signed-off-by: qizhang <qizhang@nvidia.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
This PR fixes severe atomic contention caused by padded slots in the cuDNN sparse indexer backward path.
It:
-1, allowing the kernel's bounds guard to skip their K/dK work.torch.where(..., torch.zeros_like(predict))with an out-of-placeclamp_min()followed by an in-placemasked_fill_(), avoiding unnecessary full-size temporary tensors.Problem
The caller previously assigned index
0to invalid slots. Although their scores were zero, index0passed the kernel's bounds check, so the backward kernel still issued atomic dK updates todK[0, :].When many padded slots shared index
0, these atomics became heavily contended.Fix
Invalid positions now use index
-1. The sparse backward kernel rejects these positions through its existing bounds guard and therefore skips their K/dK updates.Valid indices, scores, and gradients are unchanged. The new
masked_fill_()operates on the output ofclamp_min(), so the originalpredicttensor is not modified.Validation
Validated with the GLM-5.2 proxy model on 16 GB200 GPUs:
Rank-0 NSys results for the affected backward kernel:
End-to-end comparison using the same 4K recipe without NSys:
The small reserved-memory difference is allocator-level run-to-run variation; peak allocated memory is unchanged.