[perf] Parallelize apply_token_bitmask across vocab tiles - #645
Open
vuuihc wants to merge 1 commit into
Open
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
vuuihc
force-pushed
the
experiment/a5-apply-token-bitmask-ab
branch
2 times, most recently
from
August 12, 2026 12:59
980dd5b to
9f7f51d
Compare
vuuihc
force-pushed
the
experiment/a5-apply-token-bitmask-ab
branch
from
August 12, 2026 16:01
9f7f51d to
e643105
Compare
vuuihc
marked this pull request as ready for review
August 12, 2026 16:02
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.
Motivation
apply_token_bitmaskis used by SGLang structured output to set disallowed token logits to-inf.The current AscendC implementation partitions work only across rows:
Structured decoding commonly has a small effective batch and a large vocabulary. With
batch=1,the current kernel therefore launches one AIV even for 128K-200K vocabularies.
Change
This PR flattens the independent
(row, vocab tile)work space and distributes it with a grid-stride loop:The host chooses an aligned tile size that exposes enough work to cover the available AIVs while respecting
the UB-derived maximum tile size. The implementation uses runtime AIV and UB properties and does not contain
an Ascend 950-specific capability gate.
The production diff is limited to:
The scalar bit-unpacking loop is unchanged and remains a separate optimization opportunity.
Correctness and compatibility
Work items write disjoint
(row, vocab tile)regions, so no cross-core synchronization is required.The production implementation was validated separately from the experiment-only legacy op:
6/624/2421/21Ascend910_9382(A3) compile validation: passedAscend910B1(A2) compile validation: passedpre-commit: passedThe Ascend 950 runtime validation used the latest #632 build baseline because the production PR intentionally
does not include unrelated Ascend 950 build changes. The production implementation itself has no SOC-specific
branch.
Production validation summary
Performance
Environment:
Ascend950PR_9579Ascend950PR_95999.0.02.7.1+cpu2.7.1.post4torch.npu.Event(enable_timing=True)git_status == "")Geometric-mean P50 speedup across all 11 cases: 13.044x. No case regressed.
The speedup decreases as batch grows, matching the expected mechanism: row-only scheduling already exposes
more parallelism at larger batch sizes.
Artifacts:
Related work
apply_token_bitmaskoperator.cc @CarterDuan @ChefWu551 @iforgetmyname