Skip to content

Add attention sink support for FMHA FWD#3368

Merged
LJ-underdog merged 20 commits intodevelopfrom
lj_attn_sink
Dec 15, 2025
Merged

Add attention sink support for FMHA FWD#3368
LJ-underdog merged 20 commits intodevelopfrom
lj_attn_sink

Conversation

@LJ-underdog
Copy link
Copy Markdown
Contributor

@LJ-underdog LJ-underdog commented Dec 8, 2025

Proposed changes

This is the second attempt to introduce attention sink. The first attempt (#2892) was reverted by (#3250)

Key changes:

  • Added kHasSink boolean parameter throughout the trait hierarchy and pipeline implementations
  • Updated masking logic to support sink-aware bounds checking via GetSinkTileRangeAlongX and IsOutOfSinkBound methods
  • Modified loop calculations in pipelines to handle sink regions separately from regular attention regions
  • Updated code generation scripts to emit sink-enabled kernel variants

Example mask window_size[2,0], sink_size = 2

 x=1/y=3                 
 1 * * * * * * *           1 * * * * * * *  
 1 1 * * * * * *           1 1 * * * * * *
 1 1 1 * * * * *   ---->   1 1 1 * * * * * 
 * 1 1 1 * * * *           1 1 1 1 * * * * 
 * * 1 1 1 * * *           1 1 1 1 1 * * * 
 * * * 1 1 1 * *           1 1 * 1 1 1 * * 
 * * * * 1 1 1 *           1 1 * * 1 1 1 *
 * * * * * 1 1 1           1 1 * * * 1 1 1
 l=2/r=0(tl)               l=2/r=0/s=2(tl)

Checklist

Please put an x into the boxes that apply. You can also fill these out after creating the PR. If you're not sure, please don't hesitate to ask.

  • I have added tests relevant to the introduced functionality, and the unit tests are passing locally
  • I have added the test to REGRESSION_TESTS list defined at the top of CMakeLists.txt in tests/CMakeLists.txt, IF the test takes more than 30 seconds to run.
  • I have added inline documentation which enables the maintainers with understanding the motivation
  • I have removed the stale documentation which is no longer relevant after this pull request
  • (If this change is user-facing) I have added release notes which provide the end users with a brief summary of the improvement from this pull request
  • I have run clang-format on all changed files
  • Any dependent changes have been merged

Updated the pipeline creation logic to include 'sink' parameter in product combinations and adjusted the FmhaFwdPipeline calls accordingly.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reverts a previous revert, re-introducing the "attention sink" feature originally added in PR #2892. The attention sink mechanism allows certain tokens at the beginning of the sequence to always be attended to, regardless of the attention mask pattern.

Key changes:

  • Added kHasSink boolean parameter throughout the trait hierarchy and pipeline implementations
  • Updated masking logic to support sink-aware bounds checking via GetSinkTileRangeAlongX and IsOutOfSinkBound methods
  • Modified loop calculations in pipelines to handle sink regions separately from regular attention regions
  • Updated code generation scripts to emit sink-enabled kernel variants

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
include/ck_tile/ops/fmha/pipeline/tile_fmha_traits.hpp Added kHasSink parameter to trait templates
include/ck_tile/ops/fmha/pipeline/block_fmha_pipeline_*.hpp Updated pipelines to compute sink loop counts and adjust window offsets
include/ck_tile/ops/fmha/kernel/fmha_*_kernel.hpp Added sink_size to kernel argument structures and kernel name generation
include/ck_tile/ops/fmha/block/block_masking.hpp Implemented sink-aware masking methods (GetSinkTileRangeAlongX, IsOutOfSinkBound)
include/ck_tile/ops/fmha/block/variants.hpp Added LogitsSinkMask methods to attention variants
example/ck_tile/01_fmha/fmha_fwd*.hpp Added sink parameters to trait structures and argument passing
example/ck_tile/01_fmha/codegen/ops/*.py Updated code generation to produce sink-enabled kernel instances
example/ck_tile/01_fmha/script/*.sh Added new test scripts for sink functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@illsilin
Copy link
Copy Markdown
Collaborator

illsilin commented Dec 9, 2025

Are the relevant changes ready on the AITER side?
Will this also require changes in the Tri Dao's flash-attention repo?

@LJ-underdog
Copy link
Copy Markdown
Contributor Author

LJ-underdog commented Dec 10, 2025

Are the relevant changes ready on the AITER side? Will this also require changes in the Tri Dao's flash-attention repo?

aiter pr: ROCm/aiter#1272

@LJ-underdog LJ-underdog changed the title Revert "Revert "Add attn sink (#2892)" (#3250)" Add attention sink support for FMHA FWD Dec 10, 2025
LJ-underdog and others added 3 commits December 10, 2025 10:20
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Linjun-AMD <Jun.Lin@amd.com>
@LJ-underdog LJ-underdog requested review from a team and ddembeckAMD as code owners December 10, 2025 02:44
poyenc
poyenc previously approved these changes Dec 12, 2025
@LJ-underdog LJ-underdog merged commit f5573f5 into develop Dec 15, 2025
31 of 37 checks passed
@LJ-underdog LJ-underdog deleted the lj_attn_sink branch December 15, 2025 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants