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 executor 中 Resize_forward 的实现在 sizes 未指定而使用 size > 1 的 scales 时疑似存在问题 #162

Closed
wusongchao opened this issue Jun 13, 2022 · 3 comments

Comments

@wusongchao
Copy link

如下面的 code snippet 所示,当 resize 操作以 scales 而非 sizes 来规定输出大小时。若传入的 scale 只有一个元素则没什么问题,当输入的scales.numel() > 1时,1089 行只取scale[-2]送进torch.nn.functional.interpolate,即另外一个 dimension 的输入 scale_factor 压根没用上,结果导致后续跟一些 concat 类操作时,由于 dimension 不对,很容易扑街。

看 1088 行其实已经先校验了scales.numel() % 2 == 0,猜测实际上这是一个scales[-2:] -> scales[-2]的 typo?
https://github.com/openppl-public/ppq/blob/0fdea7d4982bc57feb6bb8548c7f012707fbd607/ppq/executor/op/torch/default.py#L1083-L1089

@ZhangZhiPku
Copy link
Collaborator

也可能是众多不起眼的bug中的一个,我看看别人是咋写的...

@ZhangZhiPku
Copy link
Collaborator

  if scales.numel() == 1:
      scales = scales.item()
  else:
      scales = scales.cpu().tolist()
      if len(scales) == 2:
          # 大家相安无事,和平共处
          pass
      elif len(scales) == 4:
          if scales[:2] != [1, 1]:
              raise NotImplementedError(
                  'Can not resize your image with current op, '
                  'cause 4-dimension resize is not implemented with pytorch.')
          scales = scales[2:]
      else:
          raise NotImplementedError(
              'Can not resize your image with current op, '
              f'cause {len(scales)}-dimension resize is not implemented with pytorch.')

你可能需要上面这段代码

@wusongchao
Copy link
Author

@ZhangZhiPku 谢谢

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