Skip to content
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

[aten decomp] Update sdpa decom #108371

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions test/test_model_exports_to_core_aten.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Owner(s): ["oncall: mobile"]
import copy

import torch
import torch._export as export

from torch.testing._internal.common_quantization import skip_if_no_torchvision
from torch.testing._internal.common_utils import TestCase


def _get_ops_list(m: torch.fx.GraphModule):
op_list = []
for n in m.graph.nodes:
if n.op == "call_function":
op_list.append(n.target)
return op_list


class TestQuantizePT2EModels(TestCase):
@skip_if_no_torchvision
def test_vit_aten_export(self):
from torchvision.models import vit_b_16 # @manual

m = vit_b_16(weights="IMAGENET1K_V1")
m = m.eval()
input_shape = (1, 3, 224, 224)
example_inputs = (torch.randn(input_shape),)
m = export.capture_pre_autograd_graph(m, copy.deepcopy(example_inputs))
m(*example_inputs)
m = export.export(m, copy.deepcopy(example_inputs))
ops = _get_ops_list(m.graph_module)
non_core_aten_op_found = False
for op in ops:
if "scaled_dot_product" in str(op):
non_core_aten_op_found = True
self.assertFalse(non_core_aten_op_found)
2 changes: 1 addition & 1 deletion torch/_decomp/decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3968,7 +3968,7 @@ def scaled_dot_product_flash_attention(
query, key, value, attn_mask, dropout_p, is_causal, None, scale=scale
)
return (
output,
output.transpose(1, 2),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow this is so weird

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is indeed. flash attnetion, https://fburl.com/38pwyabk, does that while the other one does not. I am gonna check if i trigger non flash variant what happens. But surprising calls to contiguous, https://github.com/pytorch/pytorch/blob/main/torch/nn/functional.py#L5441, does not appear in trace. which is also very weird.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a bug? It would be great to add this explanation in the comment. What's the relationship to decomposition statement in the summary?

logsumexp,
cum_seq_q,
cum_seq_k,
Expand Down
Loading