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

[dynamo] Detect mkldnn_max_pool2d/mkldnn view errors at tracing time #127111

Open
williamwen42 opened this issue May 24, 2024 · 1 comment
Open
Labels
low priority We're unlikely to get around to doing this in the near future module: dynamo module: fakeTensor oncall: pt2 triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@williamwen42
Copy link
Member

williamwen42 commented May 24, 2024

Discovered with #126341

Original repro: PYTORCH_TEST_WITH_DYNAMO=1 pytest test/test_mkldnn.py::TestMkldnnCPU::test_max_pool_unsupported_cpu and PYTORCH_TEST_WITH_DYNAMO=1 pytest test/test_mkldnn.py::TestMkldnnCPU::test_view_cpu.

Minified repro:

import torch

def f(x):
    try:
        x = x.view(x.size(0), -1)
    except:
        return x + 1
    return x + 2

opt_f = torch.compile(f, backend="eager")
x = torch.randn(3, 4, 5, dtype=torch.float32).to_mkldnn()
opt_f(x)

Output:

$ TORCH_LOGS="graph_code" python playground3.py 
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code] TRACED GRAPH
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]  ===== __compiled_fn_1 =====
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]  /data/users/williamwen/pytorch2/torch/fx/_lazy_graph_module.py class GraphModule(torch.nn.Module):
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]     def forward(self, L_x_: "f32[3, 4, 5]"):
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         l_x_ = L_x_
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         # File: /data/users/williamwen/pytorch2/playground3.py:5 in f, code: x = x.view(x.size(0), -1)
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         x: "f32[3, 20]" = l_x_.view(3, -1);  l_x_ = None
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         # File: /data/users/williamwen/pytorch2/playground3.py:8 in f, code: return x + 2
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         add: "f32[3, 20]" = x + 2;  x = None
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         return (add,)
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code]         
V0524 11:17:22.046000 139963880933184 torch/_dynamo/output_graph.py:1277] [0/0] [__graph_code] 
Traceback (most recent call last):
  File "/data/users/williamwen/pytorch2/playground3.py", line 12, in <module>
    opt_f(x)
  File "/data/users/williamwen/pytorch2/torch/_dynamo/eval_frame.py", line 414, in _fn
    return fn(*args, **kwargs)
  File "/data/users/williamwen/pytorch2/playground3.py", line 3, in f
    def f(x):
  File "/data/users/williamwen/pytorch2/torch/_dynamo/eval_frame.py", line 548, in _fn
    return fn(*args, **kwargs)
  File "<eval_with_key>.1", line 6, in forward
RuntimeError: Currently Mkldnn tensor does not support view. Change to use reshape instead

cc @ezyang @msaroufim @bdhirsh @anijain2305 @chauhang @eellison @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng

@williamwen42 williamwen42 added low priority We're unlikely to get around to doing this in the near future triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module oncall: pt2 module: dynamo labels May 24, 2024
@ezyang
Copy link
Contributor

ezyang commented May 25, 2024

Part of the problem is probably we aren't fakeifying mkldnn tensors into mkldnn fake tensors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low priority We're unlikely to get around to doing this in the near future module: dynamo module: fakeTensor oncall: pt2 triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

2 participants