Skip to content

Investigate and implement Flash Attention #5

Closed

Description

@0x000011b

For our use-case of fine-tuning LMs on up to 2048 tokens, flash attention might get us a ~2-4x speedup and a VRAM usage reduction of up to 10x. Sounds pretty amazing, so I'd like to give it a shot. Some code inspiration:

Activity

  1. converted this from a draft issue on Feb 19, 2023
  2. moved this from 📋 Backlog to 🏗 In progress in AI/ML Model Backlogon Mar 3, 2023
  3. 0x000011b commented on Mar 6, 2023

    @0x000011b
    Author

    Me and @TearGosling played around with optimizing NeoX by using components from xFormers after I profiled the training code. Results:

    • Usage of the MLP component there causes performance drop and lots of warnings, so we're ignoring this one
    • Usage of flash attention results in:
      • 👍 A decent speedup (~17% IIRC)
      • 👎 A significant increase in training and evaluation loss
      • 😐 No noticeable VRAM savings
    • Usage of the rotary embedding implementation results in:
      • 👍 A decent speedup (when used together with flash attention, gets us over a 20% throughput increase IIRC)
      • 😐 A very minor increase in training loss

    Next steps:

    • Figure out whether the higher loss values with flash attention actually translate to a worse model, or whether they can be accounted for by some other factor we're unaware of.
    • No noticeable VRAM savings with flash attention doesn't make a lot of sense. Investigate whether this is due to e.g. memory fragmentation (since we're not properly pre-allocating memory for dynamic tensor sizes).
  4. 0x000011b commented on May 2, 2023

    @0x000011b
    Author

    Flash attention via xFormers landed on #8. "Lack" of VRAM savings was actually just fragmentation messing us up.

  5. moved this from 🏗 In progress to ✅ Done in AI/ML Model Backlogon May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions