Skip to content

Add exclusive self-attention(XSA) output modifier - #202

Open
ishaannk wants to merge 3 commits into
meta-pytorch:mainfrom
ishaannk:main
Open

Add exclusive self-attention(XSA) output modifier#202
ishaannk wants to merge 3 commits into
meta-pytorch:mainfrom
ishaannk:main

Conversation

@ishaannk

@ishaannk ishaannk commented May 5, 2026

Copy link
Copy Markdown

Introduces exclusive_output_mod() - a post-output modifier that removes
the self-value projection from attention output, guaranteeing Z ⊥ V.

This is the first output_mod pattern in attention-gym. Existing score_mods
cannot implement XSA because it operates on the weighted-sum output, not
pre-softmax scores.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 5, 2026
Comment thread attn_gym/mods/exclusive_sa.py Outdated
K = self._split_heads(self.W_k(x))
V = self._split_heads(self.W_v(x))

if HAS_FLEX_ATTENTION and (score_mod is not None or block_mask is not None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we can assume flex-attention is always avail

Comment thread attn_gym/mods/latent_attention.py Outdated
@ishaannk

Copy link
Copy Markdown
Author

Hey @drisspg something still wrong?

Comment thread examples/xsa_attention.py Outdated

Q, K, V = make_qkv(T=128)

if HAS_FLEX:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same we shoudl be able to assert we have flex

Comment thread attn_gym/mods/exclusive_sa.py Outdated
return Z


class XSAMultiheadAttention(nn.Module):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I acutally dont want to be pesrscriptve on nn.Module thi sis fine touse int eh examples but I don think we should ship this by default

…sert HAS_FLEX

- Remove XSAMultiheadAttention from attn_gym/mods (not prescriptive on nn.Module)
- Move class into examples/xsa_attention.py where it belongs
- Add assert HAS_FLEX in example_composable() instead of silent SDPA fallback
- Update test import to pull XSAMultiheadAttention from examples

@ishaannk ishaannk left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hey done @drisspg please check and thanks for addressing i am a kid

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

Labels

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.

2 participants