-
Notifications
You must be signed in to change notification settings - Fork 119
Add converter for aten::_grouped_mm.default
#2805
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 all commits
dc1281d
d61ccf7
df7fe91
0fa4617
3940fa8
74bac5e
4653e05
dc64093
79ebf71
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,61 @@ | |||||
| M = 10 | ||||||
|
|
||||||
|
|
||||||
| def sample_inputs_grouped_mm(op_info, device, dtype, requires_grad, **kwargs): | ||||||
| del op_info | ||||||
| del kwargs | ||||||
|
|
||||||
| make_arg = functools.partial( | ||||||
| torch_testing.make_tensor, | ||||||
| device=device, | ||||||
| dtype=dtype, | ||||||
| requires_grad=requires_grad, | ||||||
| ) | ||||||
|
|
||||||
| cases = [ | ||||||
| # (G, M, K), (G, K, N) | ||||||
| ((2, 3, 4), (2, 4, 5)), | ||||||
| ((1, 2, 2), (1, 2, 1)), | ||||||
| ] | ||||||
|
|
||||||
| for self_shape, mat2_shape in cases: | ||||||
| self_t = make_arg(self_shape) | ||||||
| mat2_t = make_arg(mat2_shape) | ||||||
|
|
||||||
| # Test without bias and without out_dtype | ||||||
| yield opinfo_core.SampleInput(self_t, args=(mat2_t,)) | ||||||
|
|
||||||
| # Test with bias | ||||||
| g, _, _ = self_shape | ||||||
| _, _, n = mat2_shape | ||||||
| bias_t = make_arg((g, 1, n)) | ||||||
| yield opinfo_core.SampleInput(self_t, args=(mat2_t,), kwargs={"bias": bias_t}) | ||||||
|
|
||||||
| # Test with bias and out_dtype | ||||||
| if dtype in (torch.float16, torch.bfloat16): | ||||||
| yield opinfo_core.SampleInput( | ||||||
| self_t, | ||||||
| args=(mat2_t,), | ||||||
| kwargs={"bias": bias_t, "out_dtype": torch.float32}, | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| def _mock_grouped_mm(self, mat2, offs=None, bias=None, out_dtype=None): | ||||||
|
|
||||||
| if hasattr(torch.ops.aten, "_grouped_mm"): | ||||||
| try: | ||||||
| return torch.ops.aten._grouped_mm( | ||||||
| self, mat2, offs=offs, bias=bias, out_dtype=out_dtype | ||||||
| ) | ||||||
| except (TypeError, RuntimeError): | ||||||
| pass | ||||||
| res = torch.matmul(self, mat2) | ||||||
| if bias is not None: | ||||||
| res = res + bias | ||||||
|
Comment on lines
+49
to
+75
Comment on lines
+65
to
+75
|
||||||
| if out_dtype is not None: | ||||||
| res = res.to(out_dtype) | ||||||
| return res | ||||||
|
|
||||||
|
|
||||||
| def sample_inputs_scalar_tensor(op_info, device, dtype, requires_grad, **kwargs): | ||||||
| del op_info | ||||||
| del kwargs | ||||||
|
|
@@ -3142,4 +3197,12 @@ def sample_inputs_masked_scatter(op_info, device, dtype, requires_grad, **kwargs | |||||
| sample_inputs_func=sample_inputs_masked_scatter, | ||||||
| supports_out=False, | ||||||
| ), | ||||||
| opinfo_core.OpInfo( | ||||||
| "ops.aten._grouped_mm", | ||||||
| aten_name="_grouped_mm", | ||||||
| op=_mock_grouped_mm, | ||||||
|
Collaborator
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. Why not use
Suggested change
?
Collaborator
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. Also this
Collaborator
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. |
||||||
| dtypes=common_dtype.floating_types(), | ||||||
| sample_inputs_func=sample_inputs_grouped_mm, | ||||||
| supports_out=False, | ||||||
| ), | ||||||
| ] | ||||||
Uh oh!
There was an error while loading. Please reload this page.