-
Notifications
You must be signed in to change notification settings - Fork 369
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
f3aefca
68eea61
164435e
06c77d1
498f052
ea2aa7a
ca8f056
05af947
25360da
fa3220f
623c589
89ad729
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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") |
Outdated
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
Outdated
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.
Just curious, do we need NPUs to test this? I don't think we have any in CI.
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
Autoloadmechinasm, so we do not need to import it explicitly.