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

make_simple_dynamo_backend does not work for single argument models. #3204

Open
ttrouwen-dmatrix opened this issue Apr 22, 2024 · 2 comments

Comments

@ttrouwen-dmatrix
Copy link

Description

make_simple_dynamo_backend does not work for single argument models. To support multiple args, it takes in *inputs. In case of a single torch.Tensor input it will unpack it instead of handling it in its entirety.

Specifically for the example below you will get the following error:

`File "/disk1/ttrouwen/software/compiler/build/torch-mlir/python_packages/dmir_compiler/torch_mlir/dynamo.py", line 144, in dynamo_callable
    result = user_callable(*inputs)
TypeError: backend.<locals>.exec() takes 1 positional argument but 64 were given`

Example

import torch
import torch.nn as nn
import functorch.compile
from torch_mlir.dynamo import make_simple_dynamo_backend

@make_simple_dynamo_backend
def backend(gm, sample_inputs):
    assert len(sample_inputs) == 1
    def exec(inp):
        return gm.forward(inp)
    return exec

class M(nn.Module):
    def __init__(self):
        super().__init__()
        self.l1 = nn.Linear(64, 64)
    def forward(self, inp):
        return self.l1(inp)

c = torch.compile(M(), backend=backend)
c(torch.zeros(64, 64))

For the sake of brevity, this example returns gm.forward and does not use torch-mlir in the backend implementation. However, the bug is also present when torch-mlir is used in the backend.

Possible solution

In the file torch_mlir/dynamo.py the dynamo_callable function takes in *inputs. This should only be the case if len(example_inputs) > 1.

@stellaraccident
Copy link
Collaborator

I'm not aware of anyone who is actively working on/maintaining these paths. Started a thread on discord as the conversation about what to mark as deprecated has looped a couple of times: https://discord.com/channels/636084430946959380/742573221882364009/1232091021450547221

@stellaraccident
Copy link
Collaborator

(but if you see a fix, patches welcome)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants