Skip to content

Conversation

@zou3519
Copy link
Contributor

@zou3519 zou3519 commented Nov 6, 2019

Stack from ghstack:

In our name inference functions we currently create an extra TensorNames
every time we unify names. This isn't completely necessary.

To do this, I made the following changes:

  • TensorName now has two states, initialized and uninitialized
  • Renamed unifyFromRight to unifyFromRightInplace.

Test Plan:

  • pytest test/test_namedtensor.py -v

Differential Revision: D18453388

In our name inference functions we currently create an extra TensorNames
every time we unify names. This isn't completely necessary.

To do this, I made the following changes:
- TensorName now has two states, initialized and uninitialized
- Renamed unifyFromRight to unifyFromRightInplace.

Test Plan:
- `pytest test/test_namedtensor.py -v`

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Nov 6, 2019
In our name inference functions we currently create an extra TensorNames
every time we unify names. This isn't completely necessary.

To do this, I made the following changes:
- TensorName now has two states, initialized and uninitialized
- Renamed unifyFromRight to unifyFromRightInplace.

Test Plan:
- `pytest test/test_namedtensor.py -v`

ghstack-source-id: ac8f2d5
Pull Request resolved: #29307
@zou3519 zou3519 requested review from gchanan, izdeby and nairbv November 6, 2019 20:16
// to A, `tensor` would have duplicate names [A, A]. Therefore we need to check
// tensor.names [A, None] for the existence of A.
struct CAFFE2_API TensorName {
TensorName()
Copy link
Collaborator

Choose a reason for hiding this comment

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

where is this constructor needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

std::vector<TensorName>::resize resizes the container. If it is resized to a larger size, then the container needs to insert new elements. The value of the new elements is either passed in via resize, or they are default constructed (the TensorName constructor gets called).

Now that I think about it more, there is a good way around this problem that I will go and implement to remove the initialized_ flag. Instead of resizing the container, I can prepend to it names from the other list of names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed the initialized_ flag

In our name inference functions we currently create an extra TensorNames
every time we unify names. This isn't completely necessary.

To do this, I made the following changes:
- TensorName now has two states, initialized and uninitialized
- Renamed unifyFromRight to unifyFromRightInplace.

Test Plan:
- `pytest test/test_namedtensor.py -v`

[ghstack-poisoned]
@zou3519 zou3519 requested a review from nairbv November 11, 2019 17:47
In our name inference functions we currently create an extra TensorNames
every time we unify names. This isn't completely necessary.

To do this, I made the following changes:
- TensorName now has two states, initialized and uninitialized
- Renamed unifyFromRight to unifyFromRightInplace.

Test Plan:
- `pytest test/test_namedtensor.py -v`

[ghstack-poisoned]
int64_t size_difference = longer_size - shorter_size;
bool this_is_longer = names_.size() == longer_size;

if (this_is_longer) {
Copy link
Collaborator

@nairbv nairbv Nov 12, 2019

Choose a reason for hiding this comment

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

nit: I might prefer something like size_diff = std::abs(names.size() - other.names.size()); and if (names.size() > other.names.size()) if that also works, instead of tracking min/max sizes and a bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that sounds reasonable

Copy link
Collaborator

@nairbv nairbv left a comment

Choose a reason for hiding this comment

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

one suggestions but this looks cleaner without the initialized tracking.

In our name inference functions we currently create an extra TensorNames
every time we unify names. This isn't completely necessary.

To do this, I made the following changes:
- TensorName now has two states, initialized and uninitialized
- Renamed unifyFromRight to unifyFromRightInplace.

Test Plan:
- `pytest test/test_namedtensor.py -v`

[ghstack-poisoned]
zdevito pushed a commit to zdevito/ATen that referenced this pull request Nov 13, 2019
Summary:
Pull Request resolved: pytorch/pytorch#29307

In our name inference functions we currently create an extra TensorNames
every time we unify names. This isn't completely necessary.

To do this, I made the following changes:
- TensorName now has two states, initialized and uninitialized
- Renamed unifyFromRight to unifyFromRightInplace.

Test Plan: - `pytest test/test_namedtensor.py -v`

Differential Revision: D18453388

Pulled By: zou3519

fbshipit-source-id: 96c3c6fd9478d57e92e1cf770c864aeac6d29dd2
@facebook-github-bot
Copy link
Contributor

@zou3519 merged this pull request in 5e64cfa.

@facebook-github-bot facebook-github-bot deleted the gh/zou3519/211/head branch November 17, 2019 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants