Skip to content

[fa3] Use Python stable ABI#1662

Merged
tridao merged 5 commits intoDao-AILab:mainfrom
danthe3rd:py_limited_api
May 22, 2025
Merged

[fa3] Use Python stable ABI#1662
tridao merged 5 commits intoDao-AILab:mainfrom
danthe3rd:py_limited_api

Conversation

@danthe3rd
Copy link
Copy Markdown
Contributor

This should enable us to build a single wheel for all python versions
(still requires a different build per OS/PyTorch version)

Comment thread hopper/flash_api.cpp

// Copied from https://github.com/pytorch/pytorch/commit/7931eee5c5ebcdf468bff4d308510b03355cd909
// This is so that we can pass in torch.dtype as a parameter to the function.
#if TORCH_VERSION_MAJOR < 2 || (TORCH_VERSION_MAJOR == 2 && TORCH_VERSION_MINOR < 4)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: I had to remove this because we're no longer using PyBind. This will probably break with PyTorch < 2.4, is this fine, or do we want a backup solution for older PyTorch versions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

that's fine, we won't support pytorhc < 2.4

@danthe3rd danthe3rd changed the title Use Python stable ABI [fa3] Use Python stable ABI May 12, 2025
Comment thread hopper/setup.py
Copy link
Copy Markdown
Contributor

@janeyx99 janeyx99 left a comment

Choose a reason for hiding this comment

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

Looks good from my perspective! Thanks Daniel for taking this on! Did you locally verify this change?

@danthe3rd
Copy link
Copy Markdown
Contributor Author

I created a wheel with cp39, and installed in on a cp39 and cp312 env. The import seemed to work:

python -c "import torch; import flash_attn_3._C"

@janeyx99
Copy link
Copy Markdown
Contributor

I created a wheel with cp39, and installed in on a cp39 and cp312 env. The import seemed to work:

python -c "import torch; import flash_attn_3._C"

Would be best to also run the existing test cases for both envs!

Comment thread hopper/flash_api.cpp Outdated
Co-authored-by: Jane (Yuan) Xu <31798555+janeyx99@users.noreply.github.com>
@tridao tridao merged commit db4baba into Dao-AILab:main May 22, 2025
@ryderhwang
Copy link
Copy Markdown

we are using pytorch 2.7.0 + cuda 12.8 hardware with cuda 12.6 lib + python 3.10 and we are seeing build issues after this commit, have you verified that python3.10 works?

@winglian
Copy link
Copy Markdown

winglian commented Jul 5, 2025

@danthe3rd Could this be backported to FA2 in the meantime too since it seems there are issues with the current wheels #1717 ?

@danthe3rd
Copy link
Copy Markdown
Contributor Author

we are using pytorch 2.7.0 + cuda 12.8 hardware with cuda 12.6 lib + python 3.10 and we are seeing build issues after this commit, have you verified that python3.10 works?

Hi,
thanks for the report @ryderhwang
Can you open a new issue with the corresponding build issue you get? Make sure to include your system configuration + the build log (and tag me please :) )

playerzer0x pushed a commit to Liqhtworks/flash-attention that referenced this pull request Jul 24, 2025
* Use Python stable ABI

* Remove useless macro

* Add 'py_limited_api=True'

* Default value for 'num_splits'

* Update hopper/flash_api.cpp

Co-authored-by: Jane (Yuan) Xu <31798555+janeyx99@users.noreply.github.com>

---------

Co-authored-by: Tri Dao <tridao@users.noreply.github.com>
Co-authored-by: Jane (Yuan) Xu <31798555+janeyx99@users.noreply.github.com>
elewarr pushed a commit to elewarr/flash-attention that referenced this pull request Feb 4, 2026
* Use Python stable ABI

* Remove useless macro

* Add 'py_limited_api=True'

* Default value for 'num_splits'

* Update hopper/flash_api.cpp

Co-authored-by: Jane (Yuan) Xu <31798555+janeyx99@users.noreply.github.com>

---------

Co-authored-by: Tri Dao <tridao@users.noreply.github.com>
Co-authored-by: Jane (Yuan) Xu <31798555+janeyx99@users.noreply.github.com>
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.

5 participants