Skip to content

Add new TensorAxes type, remove TensorOptions::operator==()#27572

Closed
andreaskoepf wants to merge 3 commits intopytorch:masterfrom
andreaskoepf:remove_equal_ops_tensor_options
Closed

Add new TensorAxes type, remove TensorOptions::operator==()#27572
andreaskoepf wants to merge 3 commits intopytorch:masterfrom
andreaskoepf:remove_equal_ops_tensor_options

Conversation

@andreaskoepf
Copy link
Collaborator

As discussed in #25478 the TensorOptions::operator==() and the
corresponding operator!=() had non-obvious comparison semantics.
A new TensorAxes type is added that always holds a full axes
specification consisting of {d_type, device, layout and
is_variable} flag. TensorAxes objects can be safely compared.

Fixes: #25478

@pytorchbot pytorchbot added module: internals Related to internal abstractions in c10 and ATen module: operators labels Oct 8, 2019
As discussed in pytorch#25478 the TensorOptions::operator==() and the
corresponding operator!=() had non-obvious comparison semantics.
A new TensorAxes type is added that always holds a full axes
specification consisting of {d_type, device, layout and
is_variable} flag. TensorAxes objects can be safely compared.

Fixes: pytorch#25478
@andreaskoepf andreaskoepf force-pushed the remove_equal_ops_tensor_options branch from 3b69f8e to 6129fda Compare October 8, 2019 21:47
@andreaskoepf
Copy link
Collaborator Author

(committed while on the go, there seems to be a compile error, will fix later in the hotel, sry).

@andreaskoepf andreaskoepf force-pushed the remove_equal_ops_tensor_options branch from 3fefbae to 5418404 Compare October 9, 2019 02:54
@andreaskoepf
Copy link
Collaborator Author

This PR is now ready for review.

A question that came up is what should happen to' Tensor::options()'. I first added a C10_DEPRECATED_MESSAGE() message to it but since options() is used so widely throughout the PyTorch source I removed the deprecation warning again.

I see the following simple solutions: a) let options() return TensorAxes,
b) replace manually all options() calls by axes() calls.
c) keep axes() and options() on Tensor.

For the time being I resorted to c) - having both TensorAxes axes() and TensorOptions options() property-getter methods on Tensor.

/// `Tensor`. Additionally it indicates whether a `Tensor` is an autograd
/// variable.
///
/// The class is in general immutable but allows to change the representation
Copy link
Contributor

Choose a reason for hiding this comment

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

but allows to change doesn't work grammatically. I think it should be something like but the representation as a whole can be changed via ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@resistor thanks a lot for the comment! As non native speaker the docs part is always 10x harder for me than writing pure code ;-). I highly appreciate any help/corrections on that side! :-)

std::string TensorAxes::toString() const {
std::stringstream ss;
ss << *this;
return ss.str();
Copy link
Contributor

Choose a reason for hiding this comment

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

It may not matter much, but I think this is introducing an extra string copy. The stringstream will have to copy from its internal storage into a temporary string. It would be more efficient to construct a string first, pass it to the by-reference constructor to stringstream, and then return it at the end.

@andreaskoepf
Copy link
Collaborator Author

A new design for TensorAxes might be created in the future as discussed with @ezyang and @VitalyFedyunin. For now we decided that the approach implemented in this PR is not the right way to do it.

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

Labels

module: internals Related to internal abstractions in c10 and ATen

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delete TensorOptions::operator==

3 participants