[NPU]Improvement performence for grpo_loss#1174
Merged
Tcc0403 merged 4 commits intolinkedin:mainfrom Apr 16, 2026
Merged
Conversation
Contributor
Author
|
@Tcc0403 please review, thank you. |
Contributor
Author
36 tasks
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 implements Triton kernel-level performance optimizations for the grpo_loss operator.
Details
Unified default tiling by increasing BLOCK_N from 2048 to 4096 across all kernels, improving per-batch computation granularity and reducing loop counts and kernel launch overhead.
Adjusted memory multipliers downward to fit the NPU’s 192KB Unified Buffer (UB) capacity and enhance memory utilization:
Softmax: 6.0 → 3.0
Forward: 10.0 → 4.0
Backward: 12.0 → 8.0
Precompute inv_temp = 1.0 / TEMPERATURE to replace multiple in-loop divisions with single multiplications, reducing floating-point latency.
Simplified backward gradient expression: dlogp = dlogp * dloss * inv_temp instead of the original chained division, lowering the number of floating-point operations.
Changed inner kernel loops from range to tl.static_range to provide explicit loop-unrolling hints to the compiler, optimizing instruction scheduling and pipeline efficiency.
Explicit index type casting: INPUT_IDS cast to int32 to avoid implicit type conversion overhead on NPU.
Unified use of the cols_mask variable to reuse memory access masks, reducing redundant calculations and improving memory access throughput.
Simplified gradient calculation logic: (cols_idx - probs) * dlogp instead of tl.where branching, minimizing branch judgment overhead.
Testing Done
make testto ensure correctnessmake checkstyleto ensure code stylemake test-convergenceto ensure convergence