Skip to content

"This overload of nonzero is deprecated" #2154

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

Closed
LexRillo opened this issue Apr 29, 2020 · 15 comments
Closed

"This overload of nonzero is deprecated" #2154

LexRillo opened this issue Apr 29, 2020 · 15 comments

Comments

@LexRillo
Copy link

🐛 Bug

A change in torch\nn\functional might have change usability of the nonzero function used in fasterrcnn_resnet50_fpn. This produces a warning and slows down processing.

To Reproduce

Steps to reproduce the behavior:

  1. torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)

Produces the following message
C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\functional.py:2854: UserWarning: The default behavior for interpolate/upsample with float scale_factor will change in 1.6.0 to align with other frameworks/libraries, and use scale_factor directly, instead of relying on the computed output size. If you wish to keep the old behavior, please set recompute_scale_factor=True. See the documentation of nn.Upsample for details.
warnings.warn("The default behavior for interpolate/upsample with float scale_factor will change "
..\torch\csrc\utils\python_arg_parser.cpp:756: UserWarning: This overload of nonzero is deprecated:
nonzero(Tensor input, *, Tensor out)
Consider using one of the following signatures instead:
nonzero(Tensor input, *, bool as_tuple)

Expected behavior

The warning is not expected and there is a considerable slowdown compared with previous iterations. I cannot quantify this properly but I have noticed that a task that took +- 5 minutes now takes more than 10.

Environment

Please copy and paste the output from our
environment collection script
(or fill out the checklist below manually).

You can get the script and run it with:

wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
  • PyTorch / torchvision Version (e.g., 1.0 / 0.4.0): pytorch 1.5.0 torchvision 0.5.0
  • OS (e.g., Linux): Windows
  • How you installed PyTorch / torchvision (conda, pip, source): conda
  • Build command you used (if compiling from source): conda install pytorch==1.5.0 torchvision==0.5.0 cudatoolkit=10.0 -c pytorch
  • Python version:3.7
  • CUDA/cuDNN version: py3.7_cuda102_cudnn7_0
  • GPU models and configuration:nvidia GeForce GTX 1050
  • Any other relevant information:

Additional context

@fmassa
Copy link
Member

fmassa commented Apr 29, 2020

Thanks for opening the issue!

I would be surprised that the warning would account for such a large slowdown, but changing the code to use the non-deprecated codepaths sounds good to me.

A PR fixing this would be awesome!

@java-abhinav07
Copy link

java-abhinav07 commented May 25, 2020

Facing the same issue with torchvision.models.detection.keypointrcnn_resnet50_fpn pretrained network. Processing speed is reduced greatly because of the changes in torch.nn.functional.

PyTorch version: 1.5.0
torchvision version: 0.6.0
CPU: Intel i5 8th Gen
OS: Ubuntu 18.04 LTS
Python: 3.7

A fix to stop this warning from triggering would really be appreciated. Thanks!

@sykimm
Copy link

sykimm commented May 29, 2020

I runned collect_env.py and get printed output.

Now, what should I copy and where should I paste it?

@fmassa
Copy link
Member

fmassa commented May 29, 2020

@sykimm copy and paste on github the output of collect_env.py, although I'm not sure if the slowdown is due to the nonzero warning or the Upsample warning

@java-abhinav07
Copy link

java-abhinav07 commented May 31, 2020

@fmassa I'm new to this but I'm keen on contributing and perhaps being able to fix this issue. Having checked repository and the warning, would simply setting recompute_scale_factor = True in the forward function help?

@fmassa
Copy link
Member

fmassa commented Jun 1, 2020

@java-abhinav07 yes, it would help, but one would need to verify that it doesn't change the behavior of the code so that old models still give the same result

@java-abhinav07
Copy link

@fmassa I'll try it locally and get back

@java-abhinav07
Copy link

java-abhinav07 commented Jun 2, 2020

Managed to remove recompute_scale_factor warning. However, the TAT is still high possibly because I'm still getting the overload of nonzero warning. Will create a PR once that's fixed...

> /pytorch/torch/csrc/utils/python_arg_parser.cpp:756: UserWarning: This overload of nonzero is deprecated:
>         nonzero(Tensor input, *, Tensor out)
> Consider using one of the following signatures instead:
>         nonzero(Tensor input, *, bool as_tuple)

PS: The model performance is still the same, verified on multiple images

@fmassa
Copy link
Member

fmassa commented Jun 3, 2020

So seems like the overhead is in nonzero, could you try to see if you could first send a PR changing the nonzero behavior to be the non-deprecated one?

@java-abhinav07
Copy link

Yes, will fix it asap and send in a PR. Albeit, I did take a quick look and it seems like torch.nonzero has been used at multiple places, having changed the same at a couple of instances the time (for my application) was reduced by 0.5s.

@java-abhinav07
Copy link

java-abhinav07 commented Jun 11, 2020

#2314
@fmassa Kindly review the PR, I will add a separate PR for the recompute_scale_factor warning. This fixes the non-zero depreciation warning issue, thanks! and sorry about the delay

@fmassa
Copy link
Member

fmassa commented Sep 24, 2020

Fixed by #2705

@fmassa fmassa closed this as completed Sep 24, 2020
@kashf99
Copy link

kashf99 commented Oct 2, 2020

ValueError: All bounding boxes should have positive height and width. Found invaid box [500.728515625, 533.3333129882812, 231.10546875, 255.2083282470703] for target at index 0.
i am getting this error using detecto for object detection

@fmassa
Copy link
Member

fmassa commented Oct 2, 2020

@kashf99 this is the same as #2740.

@maxfrei750
Copy link
Contributor

@java-abhinav07 Thanks for helping to improve the code. Did you already fix the recompute_scale_factor warning?

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

No branches or pull requests

6 participants