-
Notifications
You must be signed in to change notification settings - Fork 349
Add NPU (Ascend) backend support for INT4 weight-only quantization workflow #3172
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
Open
orangeH25
wants to merge
4
commits into
pytorch:main
Choose a base branch
from
orangeH25:quant/int4/wo/0
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f3aefca
Add NPU (Ascend) backend support for INT4 weight-only quantization wo…
orangeH25 68eea61
use torch.ops.npu prefix and drop redundant torch_npu import
orangeH25 164435e
Merge branch 'pytorch:main' into quant/int4/wo/0
orangeH25 06c77d1
Modify test file and update comments
orangeH25 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
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
test/quantization/quantize_/workflows/int4/test_int4_plain_int32_tensor_npu.py
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,113 @@ | ||||||||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||||||||
# All rights reserved. | ||||||||
# | ||||||||
# This source code is licensed under the BSD 3-Clause license found in the | ||||||||
# LICENSE file in the root directory of this source tree. | ||||||||
|
||||||||
import unittest | ||||||||
import tempfile | ||||||||
from packaging import version | ||||||||
|
||||||||
import torch | ||||||||
from torch.testing._internal.common_utils import ( | ||||||||
TestCase, | ||||||||
instantiate_parametrized_tests, | ||||||||
parametrize, | ||||||||
run_tests, | ||||||||
) | ||||||||
|
||||||||
from torchao.quantization import ( | ||||||||
Int4WeightOnlyConfig, | ||||||||
quantize_, | ||||||||
) | ||||||||
from torchao.quantization.quantize_.common import SupportsActivationPreScaling | ||||||||
from torchao.quantization.utils import compute_error | ||||||||
from torchao.utils import ( | ||||||||
torch_version_at_least, | ||||||||
) | ||||||||
|
||||||||
try: | ||||||||
import torch_npu | ||||||||
except ImportError: | ||||||||
torch_npu = None | ||||||||
|
||||||||
|
||||||||
def get_config(group_size): | ||||||||
return Int4WeightOnlyConfig( | ||||||||
group_size=group_size, | ||||||||
int4_packing_format="plain_int32", | ||||||||
) | ||||||||
|
||||||||
|
||||||||
@unittest.skipIf(not torch_version_at_least("2.7.1"), "Need pytorch 2.7.1+") | ||||||||
@unittest.skipIf(torch_npu is None, "torch_npu is not available") | ||||||||
@unittest.skipIf(not torch_npu.npu.is_available(), "NPU not available") | ||||||||
|
@unittest.skipIf(torch_npu is None, "torch_npu is not available") | |
@unittest.skipIf(not torch_npu.npu.is_available(), "NPU not available") | |
@unittest.skipIf(torch.accelerator.current_accelerator(True).type == "npu" and torch.accelerator.is_available(), "NPU not available") |
Comment on lines
38
to
42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove it because there are some strcit version mapping between PyTorch and Torch_NPU
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyTorch provide
Autoload
mechinasm, so we do not need to import it explicitly.