[CK_TILE] fmha: Add query padding support to backward pass #3097
+1,294
−216
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.
Proposed changes
[CK_TILE] fmha: Add query padding support to backward pass
Introduces support for query sequence padding (q_padding) in the FMHA backward pass kernels.
- Passing
seqlen_q_ptrto the backward kernels to distinguish logical from physical sequence lengths.- Updating
OGradDotO,ConvertQGrad, andDQDKDVkernels to respect logical lengths and handle zero-length sequences.- Aligning LSE indexing in the forward kernel with the padded layout for consistency.
- Adding a new GTest suite (
test_fmha_bwd_kernel_padding.cpp) with comprehensive tests for various padding scenarios, Including zero-length sequences in fwd/bwd group modeUnify sequence length and padding handling
- Replaced
seqstart_padded_*_ptrwith a more robust system that usesseqstart_*_ptrfor physical sequence lengths and introducesseqlen_*_ptrandcu_seqlen_*_ptrfor logical (unpadded) lengths.- Established a clear order of precedence for determining sequence
length: cumulative lengths (
cu_seqlen_*_ptr) take priority,followed by per-sequence lengths (
seqlen_*_ptr), and finallyphysical lengths derived from
seqstart_*_ptr.- Clarified the distinction between "group mode" and "batch mode" and
how sequence lengths are handled in each case.
- Renamed
cu_seqlen_kv_ptrtocu_seqlen_k_ptrfor consistency.- Updated comments and documentation to reflect the new argument
structure and usage.
Checklist
Please put an
xinto 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.clang-formaton all changed filesDiscussion
If this is a relatively large or complex change, feel free to start a discussion by explaining why you chose the solution you did and what alternatives you considered