Fix PyTorch 2.10 ABI compatibility and build logging#2256
Closed
ussoewwin wants to merge 2 commits intoDao-AILab:mainfrom
Closed
Fix PyTorch 2.10 ABI compatibility and build logging#2256ussoewwin wants to merge 2 commits intoDao-AILab:mainfrom
ussoewwin wants to merge 2 commits intoDao-AILab:mainfrom
Conversation
Contributor
|
@ussoewwin ideally FA2 can also follow the steps of hopper FA3 and be ABI stable with both CPython and libtorch |
Author
|
@janeyx99 Thanks for your technical advice. I have amended the code based on the two PRs. Summary of Changes:
This implementation should now fully comply with the Stable ABI requirements. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FlashAttention PyTorch 2.10+ Compatibility Fixes
This Pull Request addresses build and runtime compatibility issues with PyTorch 2.10 (and upcoming 2.11) on Windows (and potentially Linux).
Problem Description
Building FlashAttention with PyTorch 2.10+ (specifically
2.11.0a0development builds) typically succeeds, but results in runtime errors or DLL load failures when importing the extension.Key issues identified:
<torch/python.h>instead of<torch/extension.h>to reduce compilation time. However, in newer PyTorch versions (2.10+), this configuration seems insufficient for full ABI compatibility for extensions, leading to missing symbols or mismatched definitions at runtime.Recommended Changes for PR
1. C++ Extension Header (csrc/flash_attn/flash_api.cpp)
#include <torch/python.h>with#include <torch/extension.h>.<torch/extension.h>is the standard and recommended header for C++ extensions to ensure ABI compatibility (_GLIBCXX_USE_CXX11_ABI, etc.). The runtime stability gained for PyTorch 2.10+ outweighs the minor increase in compilation time.2. Build Script Improvements (setup.py)
_GLIBCXX_USE_CXX11_ABIstatusVerification
The fixes were verified on the following environment:
2.11.0a0)Verification Script (test_flash_attn.py)
A simple forward pass test was performed to confirm stability: