Skip to content
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

[causal attn mask] replaced for loop over tensor with pytorch tensor ops #208

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dabeschte
Copy link

@dabeschte dabeschte commented Jan 29, 2025

The original causal attention mask generation is very slow, especially when the tensor is created on the GPU, because it needs to make 1000s of calls.

I tried to compile it...which works and makes it fast too, but compilation unfortunately also takes a long time when using a long sequence length.

This implementation is ~20-70x faster depending on the sequence lengths and since it is re-created for every SDPA, this accumulates to multiple seconds per step for larger videos

@dabeschte dabeschte changed the title replaced for loop over tensor with pytorch tensor ops [causal attn mask] replaced for loop over tensor with pytorch tensor ops Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant