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

[llama] Generate causal mask better #832

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Groverkss
Copy link
Contributor

@Groverkss Groverkss commented Jan 16, 2025

Previously the causal mask was being generated as::

causal_mask = triu(context_len, context_len)
causal_mask = causal_mask[:batch_seqlen, :batch_seqlen]

This is not a good thing to do. This is simply making it harder for the compiler to fuse this "fill like" computation to a dispatch. The slicing with a dynamic dimension is harder to move around.

Instead, it's a better idea to generate the attention mask as:

causal_mask = triu(batch_seqlen, batch_seqlen)

This PR also removes the ability to put the mask in a buffer. This is again a really bad idea. The causal mask computation should never actually materialize outside a dispatch. If the compiler fails to do this, we should see memory usage spikes and fix the compiler.

@Groverkss
Copy link
Contributor Author

Turning into draft since I want to see if we can make the compiler propagate the slice.

@Groverkss Groverkss marked this pull request as draft January 16, 2025 16:22
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