Skip to content

[Unity] [Bugfix] Fix TypeError in interpolate caused by scale_factor as tuple#15935

Merged
Hzfengsy merged 4 commits intoapache:unityfrom
Thrsu:fix-interpolate-type_error
Oct 17, 2023
Merged

[Unity] [Bugfix] Fix TypeError in interpolate caused by scale_factor as tuple#15935
Hzfengsy merged 4 commits intoapache:unityfrom
Thrsu:fix-interpolate-type_error

Conversation

@Thrsu
Copy link
Contributor

@Thrsu Thrsu commented Oct 16, 2023

This pull request addresses a TypeError that occurs in the interpolate function when the scale_factor parameter is of type tuple. The current implementation fails to handle cases where scale_factor is a tuple, resulting in the error message: "TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'."

This patch allows the interpolate function to handle both scalar and tuple values for the scale_factor parameter without raising a TypeError.

And this bug can be reproduced by the following script:

import torch
from torch import fx
from torch.nn import Module
import tvm
from tvm import relax
from tvm.relax.frontend.torch import from_fx

input_data = torch.randn([1, 2, 4, 4], dtype=torch.float32)
class interpolate(Module):
    def forward(self, input):
        return torch.nn.functional.interpolate(input, size=None, scale_factor=(2.0, 1.0), mode='bilinear', align_corners=False,)

model = interpolate().float()
input_data = [input_data]
input_info = list(zip([list(inp.shape) for inp in input_data], [str(inp.dtype) for inp in input_data]))
fx_model : torch.fx.GraphModule = fx.symbolic_trace(model)
with torch.no_grad():
    mod = from_fx(fx_model, input_info)

Copy link
Member

@jikechao jikechao left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your PR. @Thrsu

@Hzfengsy Hzfengsy merged commit ecb689e into apache:unity Oct 17, 2023
@Thrsu Thrsu deleted the fix-interpolate-type_error branch October 17, 2023 02:35
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

Successfully merging this pull request may close these issues.

3 participants