[Optimize, NPU] Remove tl.where from _rms_norm_forward/backward_kernel_tiled()#1153
Merged
Tcc0403 merged 1 commit intolinkedin:mainfrom Mar 20, 2026
Merged
[Optimize, NPU] Remove tl.where from _rms_norm_forward/backward_kernel_tiled()#1153Tcc0403 merged 1 commit intolinkedin:mainfrom
Tcc0403 merged 1 commit intolinkedin:mainfrom
Conversation
Contributor
Author
|
@Tcc0403 @TianHao324 PR is ready for review. Thanks. |
Tcc0403
approved these changes
Mar 20, 2026
Collaborator
Tcc0403
left a comment
There was a problem hiding this comment.
Yes, one should always avoid tl.where at best. Thanks for pointing it out.
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
When the
maskhas a large shape,tl.whereis not NPU-friendly intriton-ascend, leading to low kernel performance. When writing kernels, it's best to use alternative logic instead. This can result in significant performance improvements.Will these changes affect accuracy? Since the masking operation has already been applied when loading
X_block, it will not affect the calculation result duringtl.sum.Testing Done
Accuracy first
The shapes in
test_rms_norm.pyare too small to trigger the_rms_norm_forward_kernel_tiledkernel, so we need a new configuration.Env
Results after code modification
Benchmark test
The test cases in
benchmark_rms_norm.pyshould keep the same shapes as those intest_rms_norm.py.Before Optimization
forward

backward

full

memory

all_benchmark_data_raw.csv
After Optimization
forward

backward

full

memory

all_benchmark_data_optimized.csv
make testto ensure correctnessmake checkstyleto ensure code stylemake test-convergenceto ensure convergence