Skip to content

[flex attention] pass score_mod to flex_attn - #3789

Merged
tianyu-l merged 2 commits into
pytorch:mainfrom
YassineYousfi:patch-1
Jun 25, 2026
Merged

tianyu-l merged 2 commits into
pytorch:mainfrom
YassineYousfi:patch-1

Conversation

@YassineYousfi

Copy link
Copy Markdown
Contributor

#2145 added score_mod to the signature but did not pass it to the function
there is a comment https://github.com/pytorch/torchtitan/pull/2145/changes#r2625071147 pointing this out but I'm not sure why it is not passed to the flex_attention function

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 25, 2026
@pytorch-bot

pytorch-bot Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@fegin

fegin commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This is fine. I didn't pass it because it is going to be None anyway. We haven't split score_mod for CP. So if score_mod is not None, we will have to raise with CP. But in our current trainer, score_mod is always None.

@YassineYousfi

Copy link
Copy Markdown
Contributor Author

Yes I know it's not an issue in how it's used for CP. We use it for example in inference with fp8, it's nice to be able to use the same components.

def score_mod(score, b, h, q_idx, k_idx, q_scale, k_scale):
    return score.to(torch.float32) * q_scale * k_scale

@tianyu-l
tianyu-l merged commit 2ce2773 into pytorch:main Jun 25, 2026
19 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants