-
Notifications
You must be signed in to change notification settings - Fork 363
generalize torch compatibility check #3042
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Empty file.
82 changes: 82 additions & 0 deletions
82
scripts/test_torch_version_torchao_version_compatibility.sh
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # Testing compatibility | ||
liangel-02 marked this conversation as resolved.
Show resolved
Hide resolved
liangel-02 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # We know that torchao .so files built using PyTorch 2.8.0 are not ABI compatible with PyTorch 2.9+. (see #2919) | ||
| # If the version of torch is not compatible with the version of torchao, | ||
| # we expect to skip loading the .so files and a warning should be logged but no error | ||
|
|
||
| PREV_TORCH_VERSION = 2.8.0 | ||
| PREV_TORCHAO_VERSION = 0.13.0 | ||
|
|
||
| # Function to check torchao import with configurable expectations | ||
| check_torchao_import() { | ||
| local expect_warning="$1" | ||
| local warning_text="$2" | ||
| local torch_incompatible="${3:-}" | ||
|
|
||
| if [ -n "$torch_incompatible" ]; then | ||
| output=$(TORCH_INCOMPATIBLE=1 python -c "import torchao" 2>&1) | ||
| else | ||
| output=$(python -c "import torchao" 2>&1) | ||
| fi | ||
| exit_code=$? | ||
|
|
||
| if [ $exit_code -ne 0 ]; then | ||
| echo "ERROR: Failed to import torchao" | ||
| echo "Output: $output" | ||
| exit 1 | ||
| fi | ||
|
|
||
| warning_found=false | ||
| if [ -n "$warning_text" ] && echo "$output" | grep -i "$warning_text" > /dev/null; then | ||
| echo "Output: $output" | ||
| warning_found=true | ||
| fi | ||
|
|
||
| if [ "$expect_warning" != "$warning_found" ]; then | ||
| echo echo "FAILURE: expect_warning is $expect_warning but warning_found is $warning_found with message $output" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| ## prev torch version, prev torchao version | ||
| # Uninstall torch | ||
| pip uninstall torch | ||
| # Uninstall torchao | ||
| pip uninstall torchao | ||
| # Install prev compatible version of torch | ||
| pip install PREV_TORCH_VERSION | ||
| # Installs prev compatible version of torchao | ||
| pip install PREV_TORCHAO_VERSION | ||
| # hould import successfully without warning | ||
| check_torchao_import "false" "" | ||
|
|
||
| ## current torch, current torchao | ||
| # Uninstall torch | ||
| pip uninstall torch | ||
| # Uninstall torchao | ||
| pip uninstall torchao | ||
| # Install specific compatible version of torch (nightly 2.9.0dev) | ||
| pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu129 | ||
| # Build torchao from source | ||
| python setup.py develop | ||
| # Should import successfully without warning | ||
| check_torchao_import "false" "" | ||
| ## prev torch, torchao from source (do not rebuild), env var = True | ||
| # Uninstall torch | ||
| pip uninstall torch | ||
| # Install incompatible version of torch | ||
| pip install torch==PREV_TORCH_VERSION | ||
| # Should import with warning because optional env var is set to true | ||
liangel-02 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| check_torchao_import "true" "Skipping import of cpp extensions due to incompatible torch version" "TORCHAO_SKIP_LOADING_SO_FILES=1" | ||
|
|
||
|
|
||
| # current torch, prev torchao | ||
| # Uninstall torch | ||
| pip uninstall torch | ||
| # Uninstall torchao | ||
| pip uninstall torchao | ||
| # Install non-ABI stable torch version | ||
| pip install torch==2.9.0 | ||
| # Installs incompatible torchao | ||
| pip install torchao==PREV_TORCHAO_VERSION | ||
| # Should import with specific warning | ||
| check_torchao_import "true" "Skipping import of cpp extensions due to incompatible torch version" | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.