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

[PyTorch] Miscellaneous fixes for FA3 attention #1174

Merged
merged 29 commits into from
Oct 8, 2024

Conversation

cyanguwa
Copy link
Collaborator

@cyanguwa cyanguwa commented Sep 10, 2024

Description

This PR makes a few changes to the FA3 attention path.

  • Adds descale_q, descale_k and descale_v to FA3 FP8 call. This allows for custom descaling factors instead of the default 1s for q, k and v. This requires FA3 PR 1210 to be in your FA3 installation.
  • Restricts FA3 path to flash_attn_func for FP8 since flash_attn_varlen_func does not support FP8 yet.
  • Fixes the transposes in the qkv_format=sbhd case when fp8_mha=true.
  • Enables sliding window support for FP16/BF16 from FA3 (no FP8 support yet).
  • Improves the messaging when FA3 is not installed, and when it's missing some kwargs. We provide some installation instructions, and remind users to update their installation, in those two cases. This PR targets FA 3.0.0b1, and it's rapidly developing, with more kwargs being added to the API.
  • Casts FA3 output to the same type as cuDNN attention in unit tests.
  • Enables INFO level messaging in CI test to help check correct backends are used for different tests.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refractor

Changes

Please list the changes introduced in this PR:

  • See description above.

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@cyanguwa
Copy link
Collaborator Author

/te-ci pytorch

@cyanguwa cyanguwa marked this pull request as ready for review September 10, 2024 17:24
@cyanguwa
Copy link
Collaborator Author

/te-ci pytorch

@cyanguwa
Copy link
Collaborator Author

FA3: pipeline 18489052

@cyanguwa cyanguwa changed the title [PyTorch] Add qkv descales to FA3 [PyTorch] Miscellaneous fixes for FlashAttention with FA3 Sep 18, 2024
@cyanguwa cyanguwa changed the title [PyTorch] Miscellaneous fixes for FlashAttention with FA3 [PyTorch] Miscellaneous fixes for FA3 FP8 attention Sep 18, 2024
@cyanguwa
Copy link
Collaborator Author

/te-ci pytorch

@cyanguwa
Copy link
Collaborator Author

/te-ci pytorch

@cyanguwa
Copy link
Collaborator Author

FA3 pipeline 18528978

@cyanguwa
Copy link
Collaborator Author

cyanguwa commented Oct 1, 2024

/te-ci pytorch

@xrennvidia
Copy link
Collaborator

LGTM. Only one small question or comment: seems like FA3 only can support FP8 with BSHD/SBHD format, THD format is not supported with FP8. Should we added an assert message for this in TE? Anyway, this will finally trigger error in Tri Dao's code, but I think better to tell users this in TE also.

@cyanguwa
Copy link
Collaborator Author

cyanguwa commented Oct 3, 2024

/te-ci pytorch

@cyanguwa
Copy link
Collaborator Author

cyanguwa commented Oct 3, 2024

FA3: 19002912

@cyanguwa cyanguwa changed the title [PyTorch] Miscellaneous fixes for FA3 FP8 attention [PyTorch] Miscellaneous fixes for FA3 attention Oct 3, 2024
@cyanguwa
Copy link
Collaborator Author

cyanguwa commented Oct 3, 2024

@xrennvidia do you mind taking another look at the PR? I made a couple more changes after your last review. Thanks!

transformer_engine/pytorch/attention.py Outdated Show resolved Hide resolved
transformer_engine/pytorch/attention.py Outdated Show resolved Hide resolved
@cyanguwa
Copy link
Collaborator Author

cyanguwa commented Oct 8, 2024

/te-ci pytorch

@cyanguwa
Copy link
Collaborator Author

cyanguwa commented Oct 8, 2024

FA3: 19123312

@cyanguwa cyanguwa merged commit e762592 into NVIDIA:main Oct 8, 2024
14 of 15 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.

3 participants