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

torch.max not working #268

Closed
weinixuehao opened this issue Dec 5, 2023 · 2 comments · Fixed by #270
Closed

torch.max not working #268

weinixuehao opened this issue Dec 5, 2023 · 2 comments · Fixed by #270
Labels
bug Something isn't working work/xx-small work that can be done within 1 hour

Comments

@weinixuehao
Copy link

weinixuehao commented Dec 5, 2023

I implement a custom PReLU with the following code.

class PReLU2(nn.Module):
    def __init__(self) -> None:
        super(PReLU2, self).__init__()
        self.weight = nn.Parameter(torch.tensor(0.25))

    def forward(self, x):
        return torch.max(torch.zeros_like(x), x) + self.weight * torch.min(torch.zeros_like(x), x)

Failed to convert with the following exception.

Exception has occurred: RuntimeError       (note: full exception trace is shown but execution is paused at: _run_module_as_main)
shape '[1]' is invalid for input of size 2621440
  File "/Users/mac/workspace/.venv/lib/python3.8/site-packages/tinynn/converter/operators/torch/base.py", line 559, in handle_reduce
    self.output_tensors[0] = self.output_tensors[0].view(1)
  File "/Users/mac/workspace/.venv/lib/python3.8/site-packages/tinynn/converter/operators/torch/aten.py", line 3299, in parse
    self.handle_reduce(tfl.ReduceMaxOperator, args, graph_converter, False)
  File "/Users/mac/workspace/.venv/lib/python3.8/site-packages/tinynn/converter/base.py", line 443, in init_operations
    converter.parse(node, attrs, args, self.common_graph)
  File "/Users/mac/workspace/.venv/lib/python3.8/site-packages/tinynn/converter/base.py", line 480, in convert
    self.init_operations()
  File "/Users/mac/workspace/mobile_model_converter.py", line 16, in convertToTflite
    converter.convert()
  File "/Users/mac/workspace/mobile_model_converter.py", line 82, in <module>
    convertToTflite(deshadowNet, 'deshadow')
  File "/Users/mac/.pyenv/versions/3.8.5/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/mac/.pyenv/versions/3.8.5/lib/python3.8/runpy.py", line 194, in _run_module_as_main (Current frame)

The root of the problem is this torch.max() operator.
image

@peterjc123 peterjc123 added bug Something isn't working work/xx-small work that can be done within 1 hour labels Dec 5, 2023
@peterjc123
Copy link
Collaborator

@weinixuehao Yes, it is because we only support the reduction logic of torch.max/min before (e.g. torch.max(x, dim=-1)). We will add the support for torch.maximum/mininum for transforming elementwise ops first. And then we will fix this issue.

@peterjc123
Copy link
Collaborator

@weinixuehao With #269, it should work if you replace torch.max/min with torch.maximum/minimum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working work/xx-small work that can be done within 1 hour
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants