Skip to content

Build Fix: Update abi3 tag to cp310 and minimum python version to 3.10#2532

Merged
drisspg merged 13 commits into
Dao-AILab:mainfrom
aw920h:main
May 22, 2026
Merged

Build Fix: Update abi3 tag to cp310 and minimum python version to 3.10#2532
drisspg merged 13 commits into
Dao-AILab:mainfrom
aw920h:main

Conversation

@aw920h
Copy link
Copy Markdown
Contributor

@aw920h aw920h commented May 2, 2026

Currently, the setup.py script hardcodes a cp39-abi3 tag on the output wheel. Since PyTorch 2.9+ dropped support for Python 3.9, this creates a misleading wheel tag. Installing this wheel in a Python 3.9 environment results in an ImportError: undefined symbol crash due to PyTorch C++ ABI mismatches.

Since Python 3.9 reached EOL in October 2025 and the ecosystem has moved on, this PR simplifies the build process and aligns it with PyTorch's support matrix:
Bumped Python Requirement: Globally updated the wheel tag to cp310 and set python_requires=">=3.10". This officially drops Python 3.9 support and prevents the ABI crash.

Closes Issue #2530


aw920h and others added 4 commits May 2, 2026 03:21
Fix: Remove misleading py_limited_api=cp39 wheel tag for PyTorch extension
Add dynamic ABI tag based on PyTorch version for correct and improved naming of the wheel.
Implement dynamic ABI tagging for PyTorch versions
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the flash_attn_3 build/packaging logic in hopper/setup.py to avoid producing misleading cp39-abi3 wheel tags when building against newer PyTorch versions (e.g., 2.11+) that no longer support Python 3.9, preventing downstream ABI/symbol mismatch crashes.

Changes:

  • Adds PyTorch version detection logic in hopper/setup.py.
  • Dynamically sets bdist_wheel.py_limited_api to cp310 for PyTorch >= 2.11, otherwise cp39.
  • Replaces the previously hardcoded options={"bdist_wheel": {"py_limited_api": "cp39"}} with a computed dynamic_options.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hopper/setup.py Outdated
Comment thread hopper/setup.py Outdated
Comment on lines +710 to +716
# Determine the minimum Python version supported by this PyTorch
if torch_major_minor >= (2, 11):
# PyTorch 2.11 and newer require Python 3.10+
dynamic_abi_tag = "cp310"
else:
# Older PyTorch versions support Python 3.9
dynamic_abi_tag = "cp39"
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.

I applied the first suggestion to fix the parsing logic. For this second suggestion, I'd prefer to keep it simple with this if/else check for now, as it already fixes the immediate PyTorch 2.11 crash without adding complex metadata logic. Let me know if it is required.

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.

Update: Applied the second suggestion in latest commit (cae80f3) and verified its workability.

aw920h and others added 2 commits May 2, 2026 23:49
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@aw920h
Copy link
Copy Markdown
Contributor Author

aw920h commented May 7, 2026

Hi @drisspg, could you please review the changes made for correct tagging based on pytorch version?

@drisspg
Copy link
Copy Markdown
Collaborator

drisspg commented May 7, 2026

@janeyx99

@janeyx99
Copy link
Copy Markdown
Contributor

janeyx99 commented May 8, 2026

This change makes sense and is an improvement from the existing process, but technically, we should target the minimum python supported by the torch specified in TORCH_TARGET_VERSION right?

aw920h added 2 commits May 8, 2026 02:36
Refactor dynamic ABI tag and Python version requirements based on installed PyTorch version and streamline CUDA extension arguments.
Restored some accidentally removed content
@aw920h
Copy link
Copy Markdown
Contributor Author

aw920h commented May 8, 2026

Hi @janeyx99 , You are completely right!
I've updated the PR with the following changes (418670f):

  • The script now first checks os.environ.get("TORCH_TARGET_VERSION") and parses the hex string (e.g., 0x0208... -> 2.8). If it's not set, it safely falls back to parsing torch.__version__. If the resolved target is >= 2.9, it correctly tags the wheel as cp310 and sets python_requires=">=3.10". Otherwise, it falls back to cp39.
  • While testing this, I noticed the logic around line 580 was hardcoded -DTORCH_TARGET_VERSION=0x0209000000000000 ignoring the environment variable if the installed torch was >= 2.9, I updated this.
  • Also removed -DPy_LIMITED_API flag from the compiler arguments that was causing a redefinition warning. The build now correctly and cleanly uses the flag injected by py_limited_api=True.

I've tested this locally with both PyTorch 2.8 and 2.10, and the compiler flags and final wheel tags are generating perfectly now. Let me know if this looks good to you.

@janeyx99
Copy link
Copy Markdown
Contributor

janeyx99 commented May 8, 2026

The hardcoded 2.9 is intentional! We want people to be able to run with any torch 2.9+!

@aw920h
Copy link
Copy Markdown
Contributor Author

aw920h commented May 8, 2026

@janeyx99 , Thank you for the clarification. I've reverted that specific change to restore the hardcoded -DTORCH_TARGET_VERSION=0x0209...
Also brought back -DPy_LIMITED_API.
The other fixe in the PR remain as mentioned. I've pushed the updated commit. Let me know if this looks correct now!

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.

If we have to update the conditional logic for future versions of torch anyway, is the dynamic setting really that useful? basically, could this PR just bump the python abi3 version to 3.10 and call it a day?

Comment thread hopper/setup.py Outdated
major, minor = map(int, torch.__version__.split('.')[:2])

# Since PyTorch 2.9+ dropped Python 3.9 support
if major >= 2 and minor >= 9:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note that this will require adding more conditionals here for future versions that drop more python support

Comment thread hopper/setup.py Outdated
Comment on lines +603 to +605
if major >= 2 and minor >= 9:
flash_api_source = "flash_api_stable.cpp"
stable_args = ["-DTORCH_TARGET_VERSION=0x0209000000000000"] # Targets minimum runtime version torch 2.9.0
stable_args = ["-DTORCH_TARGET_VERSION=0x0209000000000000"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why this change?

Updated the wheel tag to cp310 and python_requires=">=3.10".
@aw920h
Copy link
Copy Markdown
Contributor Author

aw920h commented May 15, 2026

Hi @janeyx99 , to answer your question on the flash_api_stable.cpp change, I simplified that logic because, realistically, nobody is building against an August 2025 nightly anymore now that stable 2.9 through 2.12 are out. Based on that assumption, a simple major/minor check seemed cleaner and allowed me to easily parse the TORCH_TARGET_VERSION environment variable for cross-compilation. However, I realize that would have broken upon PyTorch 3.0, so it is best if the original parse() logic is kept.

Regarding bumping to cp310 globally, since other libraries have dropped Python 3.9, hardcoding cp310 means we officially drop Python 3.9 support even for users cross-compiling for PyTorch 2.8, Python 3.9 is EOL anyway.

I have simplified the PR to:

  • Globally bump the wheel tag to cp310 and python_requires=">=3.10".
  • Revert the API selection back to your original parse() logic.

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.

update the PR title and description, i think this is good to go

@aw920h aw920h changed the title Build Fix: Dynamically set abi3 tag based on PyTorch compatibility Build Fix: Update abi3 tag to cp310 and minimum python version to 3.10 May 21, 2026
@aw920h
Copy link
Copy Markdown
Contributor Author

aw920h commented May 21, 2026

Done! Title and description have been updated to reflect the final changes. Thanks, @janeyx99!

@drisspg drisspg merged commit 3da76cd into Dao-AILab:main May 22, 2026
reubenconducts pushed a commit to reubenconducts/flash-attention that referenced this pull request Jun 2, 2026
…10 (Dao-AILab#2532)

* Fix: Remove misleading py_limited_api=cp39 wheel tag for PyTorch extension

* Implement dynamic ABI tagging for PyTorch versions

Add dynamic ABI tag based on PyTorch version for correct and improved naming of the wheel.

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Update Python version requirements based on torch metadata

* Refactor setup.py for dynamic ABI and CUDA settings

Refactor dynamic ABI tag and Python version requirements based on installed PyTorch version and streamline CUDA extension arguments.

* Update CUDAExtension compile arguments

Restored some accidentally removed content

* Update setup.py

* Updated setup.py

minor fix: cleaned up the comments

* Brought back Py_LIMITED_API flag to CUDA extension compilation

* Minor fix

* Update setup.py for Python version requirements

Updated the wheel tag to cp310 and python_requires=">=3.10".

---------

Co-authored-by: aw920h <alien@alien.alien>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@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.

4 participants