[Perf] Optimize Ascend prepare_wy_repr_bwd with larger kv tiles, bf16 mmad, and fused a2/dg - #1209
Open
sunyi0505 wants to merge 1 commit into
Open
[Perf] Optimize Ascend prepare_wy_repr_bwd with larger kv tiles, bf16 mmad, and fused a2/dg#1209sunyi0505 wants to merge 1 commit into
sunyi0505 wants to merge 1 commit into
Conversation
… mmad, and fused a2/dg
Contributor
Author
|
@zhiyuan1i This pr is ready for review. Could you please review this PR? Thanks! |
Collaborator
|
LGTM. Optional: the |
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
Speed up the Ascend (
triton_ascend)prepare_wy_repr_bwd_npupipeline. Public API is unchanged; GPU path is untouched.1. Larger K/V tiles for the kv stage (BK=BV up to 256)
BK=BV=256.finalize_k/a2keep a conservative 4.5× slab (max=128) becauseBK=256overflows 192KB UB.Aonce per task instead of reloading it every K/V tile; hoist block-pointer bases; keep K/V/dw/du in input dtype and downcast only for reductions.2. Cube bf16 mmad with fp32
dAaccumulationtl.dot(..., acc=b_dA)in input dtype,dAstays fp32. CopyAbefore downcast so lhs clobber is safe (b_A_c = b_A.to(b_dw.dtype) + 0.0).3. Fuse finalize A2 + dg; drop GM scratch
prepare_wy_repr_bwd_finalize_a2_dg_npucomputesA2 = (k k^T) * betain UB, thendg += row(dA*A2) - col(dA*A2). Removesa2_scr/col_acc_scrand the separate BC-tiled dg kernel.da_gateis full-BT Vector (drop_DG_BLKnested GM).dA_*scratch isempty_like(kernels fully overwrite).Test plan
hardware: Atlas 800T A3(X86)

FLA_NPU_XDIST=1 ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 pytest --exitfirst -n 8 --dist load tests/modules tests/ops/utils tests/ops/test_gdn_kernels.py tests/ops/test_gdn.py tests/ops/test_kda.py tests/ops/test_attnres.py tests/ops/test_solve_tril.py tests/ops/test_gla.py
Benchmark / NCU (kernel changes only)
Breaking changes
Checklist
If you ticked the "minor" box above
Standalone minor PRs are normally not accepted (see No busywork PRs).
Justify here why yours is worth a maintainer's review time — minor PRs without a justification may be closed without review: