Repository navigation
feat(dsa): DeepSelect top-k for the fp8 indexer (SM90/SM100) - #3958
Open
faresobeid wants to merge 1 commit into
Open
faresobeid wants to merge 1 commit into
faresobeid wants to merge 1 commit into
Conversation
Contributor
|
@faresobeid did you happen to test if deep select has better determinism for top_k? Know that's sometimes an issue, though maybe resolved in recent torch. Haven't checked |
Contributor
Author
ya didnt see any noticeable differences in determinism |
This branch has not been deployed
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.
Uses DeepSelect for the DSA indexer top-k in
fp8_indexerwhen it is installed and built for the GPU (SM90, SM100, SM103). Everywhere else it falls back totorch.topk.select_topkpasses the per-row causal endkeas DeepSelect'send, so a row is read only up to its end. The output is unsorted, int32 indices.S_k.abort_when_nan_found=Falsemakes a NaN row write an out-of-range index, which the existing range mask turns into the sentinel.KEY_ALIGNMENTgoes from 16 to 256 keys, because DeepSelect needs a 1 KiB row stride. Padded keys are already masked to -inf.deep_selectis not a dependency yet. The wheel (with sm_90a; upstream builds only sm_100a/sm_103a) comes from feat: build a DeepSelect wheel (sm_90a + sm_100a + sm_103a) prime-kernels#17, which is not released. Until then the import is optional and this path is inactive unlessdeep_selectis importable. Once fix ac ckpt #17 is released, this PR pinsdeep-select, replaces thetry/except ImportErrorwith a plain import, and keeps only the GPU-capability check.Exactness. DeepSelect picks exactly the same logit values as
torch.topkin every row. The index sets differ only when several logits tie at the k-th place. Both choices are valid, andtorch.topkdoes not define which one it picks either. Even withsorted=Truethe order differs from torch in 4-23% of rows because of ties inside the top-k, so bitwise-identical attention outputs are not reachable with any setting. That is why the output is unsorted. The new test checks equal value multisets in all rows and equal index sets in rows without a boundary tie, on integer logits where ties are common.Numbers (H200).
Microbenchmark on fp32 logits from our Triton indexer kernel, top-2048 for GLM-5.3 and top-512 for DS-V4:
endTrainer setup: GLM-5.3 shape with random init, seq 131072, cp4, ep8, fp8 + deepgemm_fp8, AC + offload, compile, fake packed data, 1 node.
Ran:
tests/unit/train/models/test_fp8_indexer.pyon H200, with DeepSelect (4 passed) and without it (2 passed, 2 skipped). Alsoruff check/ruff format --check, andpytest -m "not gpu" tests/unit/orchestrator tests/unit/test_configs.py(301 passed).Not validated: SM100/SM103 (no Blackwell hardware here). Upstream DeepSelect is developed on SM100.
Note
Medium Risk
Changes sparse token selection for DSA training on supported GPUs (alignment and tie-breaking vs torch.topk); fallback path preserves prior top-k behavior when DeepSelect is absent.
Overview
Adds a faster top-k path for the FP8 DSA indexer on Hopper/Blackwell when the optional
deep_selectpackage is importable, with unchanged behavior elsewhere.New
select_topkroutes indexer logits through DeepSelect (per-row causalke, int32 indices, sentinel padding) when the GPU is SM90/SM100/SM103 andtopk ≤ 4096; otherwise it keepstorch.topk.fp8_indexerdelegates to this helper instead of inlining top-k.KEY_ALIGNMENTincreases from 16 to 256 so logit rows meet DeepSelect’s 1 KiB stride; padded keys stay masked as before.A GPU test asserts DeepSelect and
torch.topkreturn the same multiset of logit values (index sets match when there is no tie at the k-th boundary).Reviewed by Cursor Bugbot for commit 7c42198. Bugbot is set up for automated code reviews on this repo. Configure here.