-
Notifications
You must be signed in to change notification settings - Fork 24.8k
[Intel GPU][pt2e]: Collapse 3D input to 2D for matmul in qlinear_pointwise_binary fusion #148423
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 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
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,92 @@ | ||||
# Owner(s): ["module: intel"] | ||||
|
||||
# This files serves as supplementary tests for the cases in `test/inductor/test_mkldnn_pattern_matcher` | ||||
# This files tests the issue cases that shown only in XPU mode. | ||||
import contextlib | ||||
import torch | ||||
from torch._inductor.test_case import TestCase | ||||
from torch.testing._internal.common_quantization import _generate_qdq_quantized_model | ||||
from torch._inductor import config | ||||
from torch._dynamo.utils import counters | ||||
from torch.testing._internal.common_utils import ( | ||||
instantiate_parametrized_tests, | ||||
run_tests, | ||||
) | ||||
|
||||
@config.patch({"freezing": True}) | ||||
@config.patch({"force_disable_caches": True}) | ||||
class TestXPUInductorQuantizer(TestCase): | ||||
def _clone_inputs(self, inputs): | ||||
def clone(x): | ||||
if not isinstance(x, torch.Tensor): | ||||
return x | ||||
return x.clone() | ||||
|
||||
return tuple(clone(x) for x in inputs) | ||||
|
||||
def _test_common( | ||||
self, | ||||
mod, | ||||
inputs, | ||||
matcher_check_fn, | ||||
atol=1e-5, | ||||
rtol=1.3e-6, | ||||
check_autocast=torch.float32, | ||||
is_qat=False, | ||||
dtype=None, | ||||
is_dynamic=False, | ||||
quantizer=None, | ||||
compile_options={}, # noqa: B006 | ||||
): | ||||
counters.clear() | ||||
torch._dynamo.reset() | ||||
device_type = "xpu" | ||||
if check_autocast == torch.bfloat16: | ||||
maybe_autocast = torch.amp.autocast( | ||||
device_type=device_type, dtype=torch.bfloat16 | ||||
) | ||||
atol, rtol = 1e-2, 1e-2 | ||||
elif check_autocast == torch.float16: | ||||
maybe_autocast = torch.amp.autocast( | ||||
device_type=device_type, dtype=torch.float16 | ||||
) | ||||
atol, rtol = 1e-2, 1e-2 | ||||
else: | ||||
assert check_autocast == torch.float32 | ||||
maybe_autocast = contextlib.nullcontext() | ||||
convert_model = _generate_qdq_quantized_model( | ||||
mod, inputs, is_qat, is_dynamic, quantizer | ||||
) | ||||
with torch.no_grad(), maybe_autocast: | ||||
compiled_model = torch.compile(convert_model) | ||||
ref = compiled_model(*self._clone_inputs(inputs)) | ||||
res = mod(*self._clone_inputs(inputs)) | ||||
relative_err = torch.mean(torch.abs(res - ref) / ref.abs().clamp(1e-6)) | ||||
self.assertTrue(relative_err < 0.1) | ||||
matcher_check_fn() | ||||
|
||||
def test_qlinear_pointwise_binary_3d(self): | ||||
class Model(torch.nn.Module): | ||||
def __init__(self): | ||||
super(Model, self).__init__() | ||||
self.linear = torch.nn.Linear(10, 10) | ||||
self.relu = torch.nn.ReLU() | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for suggestions, since the UT is removed, we may resolve this issue. |
||||
|
||||
def forward(self, x): | ||||
orig = x | ||||
out = self.linear(x) | ||||
return out + orig | ||||
|
||||
def matcher_check_fn(): | ||||
self.assertEqual(counters["inductor"]["qlinear_weight_prepack_matcher_count"], 1) | ||||
self.assertEqual(counters["inductor"]["qlinear_binary_matcher_count"], 1) | ||||
|
||||
mod = Model().xpu() | ||||
inputs = (torch.rand(2, 3, 10, device="xpu"),) | ||||
self._test_common(mod, inputs, matcher_check_fn) | ||||
|
||||
|
||||
instantiate_parametrized_tests(TestXPUInductorQuantizer) | ||||
|
||||
if __name__ == "__main__": | ||||
run_tests() |
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.
@ZhiweiYan-96 , why do we need to add a dedicated test file? I suppose it should reuse other test files. Right?
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.
Appreciation for suggestion, this file is not necessary.. I have removed the file and add 3D cases in
test_mkldnn_pattern_matcher.py