Closed MichaelMonashev closed 2 years ago
@MichaelMonashev I'm aware of that, but don't think anything can be done in that case other than not using the models with TF same padding emulation. You'll basically end up with a model that fixes the padding for one image size, which is unavoidable based on the way tracing and the padding 'hack' works. Scripting will work with the padding but tracing will make the padding constant for the example input you use.
I bencmarked jit scripting and tracing on various models and input sizes on GPU. Traced model usually faster than scripted one. But this warning makes it look unsafe for end users.
May be adding comment after return max((math.ceil(x / s) - 1) * s + (k - 1) * d + 1 - x, 0)
and if pad_h > 0 or pad_w > 0:
will help?
Some benchmark results: https://pastebin.com/raw/yFWJAPqL https://pastebin.com/raw/Z9AbcmAb https://pastebin.com/raw/C5g4Pefc
Lots of situations where this warning crops up, overall I'm not very pleased with the way this is handled in tracing and think PyTorch should / could do much better, especially the floordiv issue.
I don't know how much a comment would help as reason is complex and there actually is a problem with some of those warnings if you trace a model with that warning and expect it to work well at a different input resolution.
I assume the warning was because of the max
? I assume using torch.max
would already fix the warning for the bool conversion? And the other warning was because of math.ceil
? I assume using torch.ceil
should also fix that warning.
Also, for ceildiv, anyway this code would be better:
def ceildiv(a, b):
return -(-a // b)
The latest code has been implemented as shown below: https://github.com/huggingface/pytorch-image-models/blob/67b0b3d7c7da3dbd76f30375b086ba4a0656811f/timm/layers/padding.py#L19-L23
Describe the bug
Desktop (please complete the following information):