Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Updated max_pool2d for same size tensors #157

Merged
merged 5 commits into from
Jun 2, 2020

Conversation

izdeby
Copy link
Contributor

@izdeby izdeby commented May 29, 2020

Benchmark setup:
C = 256
H/W = 64
Variance = 0

Benchmark results(CPU):

Master:

N = 8
('name', 'max_pool2d_tensor_pad'),('runs', 2867)
('name', 'max_pool2d_nt'),('runs', 362)

N = 16
('name', 'max_pool2d_tensor_pad'),('runs', 2222)
('name', 'max_pool2d_nt'),('runs', 180)

This change:

N = 8
('name', 'max_pool2d_tensor_pad'),('runs', 2869)
('name', 'max_pool2d_nt'),('runs', 2347)

N = 16
('name', 'max_pool2d_tensor_pad'),('runs', 2214)
('name', 'max_pool2d_nt'),('runs', 1639)

ceil_mode);

return at::detail::make_tensor<NestedTensorImpl>(
torch::nested_tensor::NestedTensor(std::move(res)).to_nested_tensor(nt.nested_dim() - 1));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Im concerned about nt.nested_dim() - 1

Copy link
Contributor

Choose a reason for hiding this comment

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

Throw an error if nested_dim() is below 1 (which it never should be)

@izdeby izdeby requested a review from cpuhrsch May 29, 2020 18:49
for nt in [nestedtensor.nested_tensor(inputs), nestedtensor.as_nested_tensor(inputs)]:
nt_res = maxPool2d(nt)
self.assertEqual(nestedtensor.nested_tensor(tensor_res), nt_res)
for nt in [nestedtensor.nested_tensor(inputs), nestedtensor.as_nested_tensor(inputs)]:
Copy link
Contributor

@cpuhrsch cpuhrsch May 29, 2020

Choose a reason for hiding this comment

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

You don't need to check as_nested_tensor anymore since it'll do the same thing as nested_tensor in this case (we changed that in #150).

@izdeby izdeby requested a review from cpuhrsch June 1, 2020 21:31
auto nt = self_impl->_data;
auto tensor_node = get_nested_tensor_structure(self);

if (is_tensor_shape(self)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can make this a method, but I can do that later on as part of further work

ceil_mode);

return at::detail::make_tensor<NestedTensorImpl>(
torch::nested_tensor::NestedTensor(std::move(res)).to_nested_tensor(nt.nested_dim() - 1));
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a helper for wrapping a C++ NestedTensor called wrap_nested_tensor

@cpuhrsch cpuhrsch merged commit 474b0cc into pytorch:master Jun 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants