-
Notifications
You must be signed in to change notification settings - Fork 4
Add tensor-descriptor version of prefill_attention #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ohadeytan
wants to merge
1
commit into
main
Choose a base branch
from
prefill-attn-td
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # prefill_attention conversion notes | ||
|
|
||
| ## Tensor-descriptor conversion | ||
|
|
||
| - Source: original.py → tensor_descriptor.py (kernel `_prefill_attention_kernel_td`) | ||
| - Raw pointer arithmetic (`off_q`/`off_k`/`off_v`/`off_o`, `k_ptrs`/`v_ptrs` | ||
| advanced per iteration) replaced with 3D `tl.make_tensor_descriptor` views over | ||
| the packed `(seq_len, heads, head_dim)` layout. Each descriptor is rebased at | ||
| `cur_batch_in_all_start_index * stride_*bs` so its coordinates run | ||
| `0..cur_batch_seq_len`; the batch start is a scalar folded into the base | ||
| pointer, not a per-row runtime index, so plain `desc.load`/`desc.store` suffice | ||
| (no gather/scatter needed). | ||
| - **Tail masks dropped:** the original's seq-len (`offs_m < seq_len`, | ||
| `pos_k < seq_len` on the load) and head-dim (`mask_d = offs_d < Lk`) masks on | ||
| Q/K/V loads and the O store are redundant — the descriptor `shape` carries both | ||
| boundaries and zero-fills OOB. Zero is the additive identity for the `tl.dot` | ||
| accumulation and for masked-out `qk` (overwritten by the causal `tl.where`), so | ||
| the drop is safe. | ||
| - **Compute masks kept:** causal / sliding-window / valid-position masking | ||
| (`tl.where(mask, qk * sm_scale, -1.0e8)`) is attention *semantics*, not a tail | ||
| fill, so it is preserved verbatim. | ||
| - K is loaded as `(BLOCK_N, BLOCK_DMODEL)` and transposed via `tl.trans` before | ||
| `tl.dot(q, k)`. Descriptors require the last dim contiguous, so K cannot be | ||
| loaded pre-transposed the way the original did via `strides=(1, stride_kbs)`. | ||
| - Last-dim (§4) is satisfied: the contiguous axis is `head_dim` (`BLOCK_DMODEL`), | ||
| ≥ 16 bytes; the length-1 head axis is the middle dim. | ||
| - **Signature change:** added `num_q_heads` / `num_kv_heads` runtime args (needed | ||
| for the descriptor `shape`, which the original never materialized). The wrapper | ||
| passes them only when the target kernel declares them (`arg_names` check) and | ||
| registers the TMA allocator, so it still drives the original kernel unchanged. |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be good to try to lower it with the triton fork to see if these index comparisons and tl.where will be lowered properly.