Skip to content

Non-Causal attention mask support? #696

Closed

Description

@brthor

I am attempting to use a non-causal attention mask for a llama model with Unsloth and looking over the code to find the best way to achieve all the other speedups but use a non-causal attention mask.

I would appreciate some advice on places to look for code changes, prior to stepping through with a debugger.

I see there that the Attention forward still seems to support the attention mask:
https://github.com/unslothai/unsloth/blob/main/unsloth/models/llama.py#L375

But it may be ignored in the forward fn:
https://github.com/unslothai/unsloth/blob/main/unsloth/models/llama.py#L589

Activity

  1. brthor commented on Jun 27, 2024

    @brthor
    Author

    I realized my requirements are different than I at first thought, closing this.

  2. danielhanchen commented on Jul 1, 2024

    @danielhanchen
    Member

    Apologies relocated to SF, hence the delay!

    Ye sadly non causal attention masks are not yet supported - there is a way though - you'll have to fork the project, then edit it to causal = False for FA, and Xformers will need a different causal mask

  3. brthor commented on Jul 1, 2024

    @brthor
    Author

    @danielhanchen I managed to get this working, but actually with a non-causal mask SDPA outperformed xformers by 12% (I didn't test FA). Using the unsloth LlamaAttention w/SDPA gave about 1.5% (fp32) - 2.5% (bf16), perf boost nonetheless.

  4. danielhanchen commented on Jul 2, 2024

    @danielhanchen
    Member

    Interesting!!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions