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

Update flash attention section in memory_optimizations.rst #9188

Merged
merged 3 commits into from
May 24, 2024

Conversation

cyanguwa
Copy link
Contributor

What does this PR do ?

Update the flash attention section in memory_optimizations.rst

Collection: [Note which collection this PR will affect]

Changelog

  • Added more information about flash attention implementation in NeMo and Transformer Engine in docs/source/features/memory_optimizations.rst L14-23

Usage

  • N/A

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

Before your PR is "Ready for review"

Pre checks:

  • [x ] Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • [x ] Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • [x ] Documentation

Who can review?

Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information


Turn Flash Attention On and Off
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In the NeMo Framework, Flash Attention is supported through the Transformer Engine with the inclusion of Flash Attention 2. By default, Flash Attention is enabled, but the Transformer Engine may switch to a different kernel if the tensor dimensions are not optimal for Flash Attention. Users can completely disable Flash Attention by setting the environment variable ``NVTE_FLASH_ATTN=0``.
In the NeMo Framework, flash attention is supported through `Transformer Engine <https://github.com/NVIDIA/TransformerEngine/tree/main>`_ with both of the above implementations. Transformer Engine selects the appropriate implementation based on the input information (sequence length, number of heads, head dimension, etc), but when both implementations are applicable, Transformer Engine prefers cuDNN flash attention on Hopper+ architectures, and Tri Dao flash attention on Ampere-based architectures. To disable Tri Dao flash attention, users can set the environment variable ``NVTE_FLASH_ATTN=0``, and to disable cuDNN flash attention, users can set ``NVTE_FUSED_ATTN=0``.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change to:

“In the NeMo Framework, Flash Attention is supported through the Transformer Engine, including both of the implementations mentioned above. The Transformer Engine selects the appropriate implementation based on input information such as sequence length, number of heads, and head dimension. When both implementations are applicable, the Transformer Engine prefers cuDNN flash attention on Hopper+ architectures and Tri Dao flash attention on Ampere-based architectures.

To disable Tri Dao flash attention, set the environment variable NVTE_FLASH_ATTN=0. To disable cuDNN flash attention, set NVTE_FUSED_ATTN=0.”

Copy link
Collaborator

@jgerh jgerh left a comment

Choose a reason for hiding this comment

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

I reviewed the file and made a few copyedits, formatting changes, and paragraph rewrites.

@cyanguwa cyanguwa requested a review from jgerh May 24, 2024 16:49
@ericharper ericharper merged commit c3f19e9 into NVIDIA:main May 24, 2024
9 checks passed
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.

None yet

3 participants