Add more checks to custom Function (#33069)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33069
This PR adds the following:
- Warn when a non-input Tensor is given to `mark_dirty()` as it is not needed.
- Raise an error if we modify inplace an input that is a view and that we have multiple output. This setting is not handled by `CopySlices` and will raise a cryptic error during the backward.
- Raise an error if an input is modified inplace but not returned. That will prevent the graph rewrite from being done correctly.
Test Plan: Imported from OSS
Differential Revision: D19791563
Pulled By: albanD
fbshipit-source-id: 4d8806c27290efe82ef2fe9c8c4dc2b26579abd1