NVIDIA / MinkowskiEngine

Minkowski Engine is an auto-diff neural network library for high-dimensional sparse tensors
https://nvidia.github.io/MinkowskiEngine
Other
2.47k stars 367 forks source link

UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. #400

Open resuly opened 3 years ago

resuly commented 3 years ago

Got this warning with PyTorch 1.9.0+:

site-packages/MinkowskiEngine-0.5.4-py3.8-linux-x86_64.egg/MinkowskiEngine/MinkowskiSparseTensor.py:537: 
UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). 
This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
  coords = coords // tensor_stride

https://github.com/NVIDIA/MinkowskiEngine/blob/bb362c7a037afffdc9682264acd966d234ea1ef6/MinkowskiEngine/MinkowskiSparseTensor.py#L537

There are many similar codes that could lead to this issue.

yueshengbin commented 2 years ago

torch.floor_divide() is deprecated and will be removed in a future PyTorch release. Its name is a misnomer because it actually rounds the quotient towards zero instead of taking its floor. To keep the current behavior use torch.div() with rounding_mode='trunc'. To actually perform floor division, use torch.div() with rounding_mode='floor'.

zzff-sys commented 2 years ago

@resuly @yueshengbin Hello, has your problem been solved? I have the same problem: /opt/conda/lib/python3.7/site-packages/thop/vision/basic_hooks.py:92: UserWarning: floordiv is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor'). kernel = torch.DoubleTensor([*(x[0].shape[2:])]) // torch.DoubleTensor(list((m.output_size,))).squeeze()

Ch3nYe commented 2 years ago

@resuly @yueshengbin Hello, has your problem been solved? I have the same problem: /opt/conda/lib/python3.7/site-packages/thop/vision/basic_hooks.py:92: UserWarning: floordiv is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor'). kernel = torch.DoubleTensor([*(x[0].shape[2:])]) // torch.DoubleTensor(list((m.output_size,))).squeeze()

you can use: kernel = torch.div(torch.DoubleTensor([*(x[0].shape[2:])]) , torch.DoubleTensor(list((m.output_size,))).squeeze(), rounding_mode="floor") this is equals to // in python.