Skip to content

Conversation

@colesbury
Copy link
Member

This adds at::_unsafe_view and uses it in matmul. The _unsafe_view
function is identical to view except that the output is not treated
like a view by the automatic differentiation code. This avoids in-place
modifications triggering the more expensive CopySlices/AsStridedBackward
behavior.

The _unsafe_view function is only safe to use on temporaries that will
be immediately discarded and that do not alias other tensors. Otherwise,
in-place modificatiions may trigger incorrect gradients. The funciton is
not exposed to Python.

See #5169

cc @ngimel @csarofeen

This adds at::_unsafe_view and uses it in matmul. The _unsafe_view
function is identical to view except that the output is not treated
like a view by the automatic differentiation code. This avoids in-place
modifications triggering the more expensive CopySlices/AsStridedBackward
behavior.

The _unsafe_view function is only safe to use on temporaries that will
be immediately discarded and that do not alias other tensors. Otherwise,
in-place modificatiions may trigger incorrect gradients. The funciton is
not exposed to Python.

See pytorch#5169
@colesbury colesbury requested a review from gchanan February 16, 2018 22:42
Copy link
Contributor

@gchanan gchanan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. What do you think about adding something to the function name describing why it's unsafe? unsafe_view_tmp_nonalias or something? I'm sure you can come up with a better name.

@yf225
Copy link
Contributor

yf225 commented Feb 18, 2018

@pytorchbot retest this please

@soumith soumith merged commit 0509f26 into pytorch:master Feb 20, 2018
@colesbury colesbury deleted the unsafe_view branch February 20, 2018 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants