Warns when performing integer division with div and addcdiv#34570
Warns when performing integer division with div and addcdiv#34570
Conversation
💊 CircleCI build failures summary and remediationsAs of commit 23d9a8b (more details on the Dr. CI page): ✅ None of the build failures appear to be your fault 💚
🚧 4 upstream failures:These were probably caused by upstream breakages:
This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker. This comment has been revised 37 times. |
| if (isIntegralType(result.scalar_type(), /*includeBool=*/ true)) { | ||
| TORCH_WARN_ONCE( | ||
| "Integer division of tensors using div or / is deprecated. ", | ||
| "In a future release div and / will ", |
There was a problem hiding this comment.
nit: I'd just specify the expected versions, I don't see why we'd deviate from the plan and even if we do, it's not the biggest deal.
There was a problem hiding this comment.
Also, did we talk about having a future true_division for PyTorch? (So the error message could say "or import...").
There was a problem hiding this comment.
I'll put up a separate PR shortly for that behavior.
| with self.maybeWarnsRegex(UserWarning, '^Integer division.+is deprecated.+'): | ||
| c = a / b | ||
| c = torch.div(a, b) | ||
| torch.div(a, b, out=o) |
There was a problem hiding this comment.
I'll add some more.
There was a problem hiding this comment.
Hm... I'm not sure how much more it makes sense to add here, actually. Trying to perform division with float inputs and an integral out type will already throw a runtime error.
| TORCH_WARN_ONCE( | ||
| "Integer division of tensors using div or / is deprecated, ", | ||
| "and in a future release div will perform true division as in Python 3. ", | ||
| "Use true_divide or floor_divide (// in Python) instead."); |
There was a problem hiding this comment.
should we say something about "import future"?
There was a problem hiding this comment.
It would leave master in a bad state. I'll rebase #34794 once this is in and update the doc.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: Per title. See related #34570. In PyTorch 1.7 the plan is for torch.div and Python's division operator to perform "true" division, like Python 3, JAX, and NumPy. To facilitate this change, this PR expands true_divide to be a method so it can cover all of torch.div's use cases. New true_divide tests are added to test_torch.py, test_type_promotion.py, and test_sparse.py. Pull Request resolved: #34794 Differential Revision: D20545507 Pulled By: mruberry fbshipit-source-id: 55286f819716c8823d1930441a69008560ac2bd5
…34570) Summary: Per title. In the future we want to make div(), the division operator, and addcdiv perform true division as in Python 3, NumPy, and JAX. To do this without silently breaking users we plan to: - Warn (once) in 1.5 when a user performs integer division using div or addcdiv - RuntimeError in 1.6 when a user attempts to perform integer division using div or addcdiv - Always perform true division in 1.7 using div, /, and addcdiv Users can use true_divide or floor_divide today to explicitly specify the type of division they like. A test for this behavior is added to test_type_promotion. Unfortunately, because we are only warning once (to avoid a deluge) the test only uses maybeWarns Regex. The XLA failure is real but will be solved by pytorch#34552. I'll be sure to land that PR first to avoid temporarily breaking the XLA build. Pull Request resolved: pytorch#34570 Differential Revision: D20529211 Pulled By: mruberry fbshipit-source-id: 65af5a9641c5825175d029e8413c9e1730c661d0
Summary: Per title. See related pytorch#34570. In PyTorch 1.7 the plan is for torch.div and Python's division operator to perform "true" division, like Python 3, JAX, and NumPy. To facilitate this change, this PR expands true_divide to be a method so it can cover all of torch.div's use cases. New true_divide tests are added to test_torch.py, test_type_promotion.py, and test_sparse.py. Pull Request resolved: pytorch#34794 Differential Revision: D20545507 Pulled By: mruberry fbshipit-source-id: 55286f819716c8823d1930441a69008560ac2bd5
UPDATE
BC-breaking release note info:
In a future PyTorch release, torch.div (including the / operator) will perform "true" division as in Python3 and NumPy. Performing integer floor division with torch.div is deprecated. To floor divide integers use torch.floor_divide, instead.
// ------- (PR info below) ------- //
Per title.
In the future we want to make div(), the division operator, and addcdiv perform true division as in Python 3, NumPy, and JAX. To do this without silently breaking users we plan to:
Users can use true_divide or floor_divide today to explicitly specify the type of division they like.
A test for this behavior is added to test_type_promotion. Unfortunately, because we are only warning once (to avoid a deluge) the test only uses maybeWarns Regex.
The XLA failure is real but will be solved by #34552. I'll be sure to land that PR first to avoid temporarily breaking the XLA build.