-
Notifications
You must be signed in to change notification settings - Fork 27
Updated max_pool2d for same size tensors #157
Conversation
ceil_mode); | ||
|
||
return at::detail::make_tensor<NestedTensorImpl>( | ||
torch::nested_tensor::NestedTensor(std::move(res)).to_nested_tensor(nt.nested_dim() - 1)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
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)]: |
There was a problem hiding this comment.
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).
auto nt = self_impl->_data; | ||
auto tensor_node = get_nested_tensor_structure(self); | ||
|
||
if (is_tensor_shape(self)) { |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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
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)