Skip to content

Use ModularIndexing instead of ops.masked for shared-reads cat - #180339

Closed
eellison wants to merge 1 commit into
gh/eellison/995/basefrom
gh/eellison/995/head
Closed

eellison wants to merge 1 commit into
gh/eellison/995/basefrom
gh/eellison/995/head

Conversation

@eellison

@eellison eellison commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

When pointwise cat inputs share the same read buffers, use ModularIndexing
for always-valid indices instead of ops.masked. ModularIndexing(r0 - offset,
1, size) simplifies to r0 % size — the same expression regardless of offset.
This lets CSE deduplicate all shared computation across cat branches: loads,
normalization, weight multiplication. Only the final divergent ops (e.g.
rope's mul-sub vs mul-add) remain separate.

For qknorm + rope: 13 loads → 7, 2 rsqrt → 1, 12 masked loads → 0,
3 tl.where → 1. ~10-16% speedup on top of the fusion change.

Authored with Claude.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Apr 14, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180339

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot

pytorch-bot Bot commented Apr 14, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant