Build Fix: Update abi3 tag to cp310 and minimum python version to 3.10#2532
Conversation
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
There was a problem hiding this comment.
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_apitocp310for PyTorch>= 2.11, otherwisecp39. - Replaces the previously hardcoded
options={"bdist_wheel": {"py_limited_api": "cp39"}}with a computeddynamic_options.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # 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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Update: Applied the second suggestion in latest commit (cae80f3) and verified its workability.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Hi @drisspg, could you please review the changes made for correct tagging based on pytorch version? |
|
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? |
Refactor dynamic ABI tag and Python version requirements based on installed PyTorch version and streamline CUDA extension arguments.
Restored some accidentally removed content
|
Hi @janeyx99 , You are completely right!
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. |
|
The hardcoded 2.9 is intentional! We want people to be able to run with any torch 2.9+! |
|
@janeyx99 , Thank you for the clarification. I've reverted that specific change to restore the hardcoded -DTORCH_TARGET_VERSION=0x0209... |
minor fix: cleaned up the comments
janeyx99
left a comment
There was a problem hiding this comment.
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?
| major, minor = map(int, torch.__version__.split('.')[:2]) | ||
|
|
||
| # Since PyTorch 2.9+ dropped Python 3.9 support | ||
| if major >= 2 and minor >= 9: |
There was a problem hiding this comment.
Note that this will require adding more conditionals here for future versions that drop more python support
| 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"] |
Updated the wheel tag to cp310 and python_requires=">=3.10".
|
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:
|
janeyx99
left a comment
There was a problem hiding this comment.
update the PR title and description, i think this is good to go
|
Done! Title and description have been updated to reflect the final changes. Thanks, @janeyx99! |
…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>
Currently, the setup.py script hardcodes a
cp39-abi3tag 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