From 9ddd6e1fcf3c4d89ec2c9c99fb361746cdca2ce0 Mon Sep 17 00:00:00 2001 From: Brian Liu Date: Wed, 2 Oct 2024 15:20:10 +0000 Subject: [PATCH] #13127: Remove shape_without_padding() pybinding and usage --- .../tt/ttnn_functional_resnet50_large_new_conv_api.py | 8 ++++---- .../tt/ttnn_functional_resnet50_new_conv_api.py | 6 +++--- .../tt/ttnn_functional_resnet50_xlarge_new_conv_api.py | 8 ++++---- .../ttnn_functional_resnet50_xlarge_new_conv_api_24.py | 10 +++++----- .../ttnn_functional_resnet50_xxlarge_new_conv_api.py | 8 ++++---- models/experimental/vgg/vgg_utils.py | 2 +- .../unit_testing/misc/test_downsample.py | 4 ++-- ttnn/cpp/pybind11/pytensor.cpp | 10 ---------- ttnn/tt_lib/fused_ops/max_pool.py | 2 +- 9 files changed, 24 insertions(+), 34 deletions(-) diff --git a/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_large_new_conv_api.py b/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_large_new_conv_api.py index 092124f31c3..f4249ff7677 100644 --- a/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_large_new_conv_api.py +++ b/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_large_new_conv_api.py @@ -703,7 +703,7 @@ def first_run(self, input_tensor, device, batch_size, ops_parallel_config) -> tt print(f"=================================== layer: 4, module: 3") x, x_height, x_width = self.layer4_module3(x, device, batch_size, x_height, x_width, conv_op_cache) - unpadded_shape = x.shape_without_padding() + unpadded_shape = x.shape x = ttnn.untilize_with_unpadding( x, output_tensor_end=( @@ -796,7 +796,7 @@ def first_run(self, input_tensor, device, batch_size, ops_parallel_config) -> tt ) x = self.fc(x) - desired_shape = list(x.shape_without_padding()) + desired_shape = list(x.shape) desired_shape[-1] = 1000 x = ttnn.untilize_with_unpadding( x, @@ -934,7 +934,7 @@ def optimized_run(self, input_tensor, device, batch_size, ops_parallel_config, c print(f"=================================== layer: 4, module: 3") x, x_height, x_width = self.layer4_module3(x, device, batch_size, x_height, x_width, conv_op_cache) - unpadded_shape = x.shape_without_padding() + unpadded_shape = x.shape x = ttnn.untilize_with_unpadding( x, output_tensor_end=( @@ -1028,7 +1028,7 @@ def optimized_run(self, input_tensor, device, batch_size, ops_parallel_config, c ) x = self.fc(x) - desired_shape = list(x.shape_without_padding()) + desired_shape = list(x.shape) desired_shape[-1] = 1000 x = ttnn.untilize_with_unpadding( x, diff --git a/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_new_conv_api.py b/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_new_conv_api.py index 067383c4cd4..57dc0bb35e5 100644 --- a/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_new_conv_api.py +++ b/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_new_conv_api.py @@ -1023,7 +1023,7 @@ def run(self, input_tensor, device, ops_parallel_config, conv_op_cache={}) -> tt ) if is_wormhole_b0() and self.batch_size == 16: - xshape = x.shape_without_padding() + xshape = x.shape x = ttnn.slice(x, [0, 0, 0, 0], [xshape[0], xshape[1], xshape[2], xshape[3]]) layer4_module1_input_shape = ttnn.Shape(x.shape.with_tile_padding()) @@ -1119,7 +1119,7 @@ def run(self, input_tensor, device, ops_parallel_config, conv_op_cache={}) -> tt ) x = ttnn.to_memory_config(x, width_sharded_mem_config) - unpadded_shape = x.shape_without_padding() + unpadded_shape = x.shape x = ttnn.untilize_with_unpadding( x, output_tensor_end=( @@ -1195,7 +1195,7 @@ def run(self, input_tensor, device, ops_parallel_config, conv_op_cache={}) -> tt ) x = self.fc(x) - desired_shape = list(x.shape_without_padding()) + desired_shape = list(x.shape) desired_shape[-1] = 1000 x = ttnn.untilize_with_unpadding( x, diff --git a/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_xlarge_new_conv_api.py b/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_xlarge_new_conv_api.py index 685db516fc5..3d366ea38c9 100644 --- a/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_xlarge_new_conv_api.py +++ b/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_xlarge_new_conv_api.py @@ -699,7 +699,7 @@ def first_run(self, input_tensor, device, batch_size, ops_parallel_config) -> tt print(f"=================================== layer: 4, module: 3") x, x_height, x_width = self.layer4_module3(x, device, batch_size, x_height, x_width, conv_op_cache) - unpadded_shape = x.shape_without_padding() + unpadded_shape = x.shape x = ttnn.untilize_with_unpadding( x, output_tensor_end=( @@ -792,7 +792,7 @@ def first_run(self, input_tensor, device, batch_size, ops_parallel_config) -> tt ) x = self.fc(x) - desired_shape = list(x.shape_without_padding()) + desired_shape = list(x.shape) desired_shape[-1] = 1000 x = ttnn.untilize_with_unpadding( x, @@ -916,7 +916,7 @@ def optimized_run(self, input_tensor, device, batch_size, ops_parallel_config, c x, x_height, x_width = self.layer4_module2(x, device, batch_size, x_height, x_width, conv_op_cache) x, x_height, x_width = self.layer4_module3(x, device, batch_size, x_height, x_width, conv_op_cache) - unpadded_shape = x.shape_without_padding() + unpadded_shape = x.shape x = ttnn.untilize_with_unpadding( x, output_tensor_end=( @@ -1010,7 +1010,7 @@ def optimized_run(self, input_tensor, device, batch_size, ops_parallel_config, c ) x = self.fc(x) - desired_shape = list(x.shape_without_padding()) + desired_shape = list(x.shape) desired_shape[-1] = 1000 x = ttnn.untilize_with_unpadding( x, diff --git a/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_xlarge_new_conv_api_24.py b/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_xlarge_new_conv_api_24.py index 614d22297e1..931d9ff5887 100644 --- a/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_xlarge_new_conv_api_24.py +++ b/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_xlarge_new_conv_api_24.py @@ -686,7 +686,7 @@ def first_run(self, input_tensor, device, batch_size, ops_parallel_config) -> tt eltwise_binary_out_in_place=True, ) - unpadded_shape = x.shape_without_padding() + unpadded_shape = x.shape x = ttnn.slice( x, (0, 0, 0, 0), @@ -728,7 +728,7 @@ def first_run(self, input_tensor, device, batch_size, ops_parallel_config) -> tt print(f"=================================== layer: 4, module: 3") x, x_height, x_width = self.layer4_module3(x, device, batch_size, x_height, x_width, conv_op_cache) - unpadded_shape = x.shape_without_padding() + unpadded_shape = x.shape x = ttnn.untilize_with_unpadding( x, output_tensor_end=( @@ -821,7 +821,7 @@ def first_run(self, input_tensor, device, batch_size, ops_parallel_config) -> tt ) x = self.fc(x) - desired_shape = list(x.shape_without_padding()) + desired_shape = list(x.shape) desired_shape[-1] = 1000 x = ttnn.untilize_with_unpadding( x, @@ -941,7 +941,7 @@ def optimized_run(self, input_tensor, device, batch_size, ops_parallel_config, c x, x_height, x_width = self.layer4_module2(x, device, batch_size, x_height, x_width, conv_op_cache) x, x_height, x_width = self.layer4_module3(x, device, batch_size, x_height, x_width, conv_op_cache) - unpadded_shape = x.shape_without_padding() + unpadded_shape = x.shape x = ttnn.untilize_with_unpadding( x, output_tensor_end=( @@ -1035,7 +1035,7 @@ def optimized_run(self, input_tensor, device, batch_size, ops_parallel_config, c ) x = self.fc(x) - desired_shape = list(x.shape_without_padding()) + desired_shape = list(x.shape) desired_shape[-1] = 1000 x = ttnn.untilize_with_unpadding( x, diff --git a/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_xxlarge_new_conv_api.py b/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_xxlarge_new_conv_api.py index a40b45b4c36..48049b4e2eb 100644 --- a/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_xxlarge_new_conv_api.py +++ b/models/demos/ttnn_resnet/tt/ttnn_functional_resnet50_xxlarge_new_conv_api.py @@ -787,7 +787,7 @@ def first_run(self, input_tensor, device, batch_size, ops_parallel_config) -> tt print(f"=================================== layer: 4, module: 3") x, x_height, x_width = self.layer4_module3(x, device, batch_size, x_height, x_width, conv_op_cache) - unpadded_shape = x.shape_without_padding() + unpadded_shape = x.shape x = ttnn.untilize_with_unpadding( x, output_tensor_end=( @@ -882,7 +882,7 @@ def first_run(self, input_tensor, device, batch_size, ops_parallel_config) -> tt ) x = self.fc(x) - desired_shape = list(x.shape_without_padding()) + desired_shape = list(x.shape) desired_shape[-1] = 1000 x = ttnn.untilize_with_unpadding( x, @@ -1016,7 +1016,7 @@ def optimized_run(self, input_tensor, device, batch_size, ops_parallel_config, c x, x_height, x_width = self.layer4_module2(x, device, batch_size, x_height, x_width, conv_op_cache) x, x_height, x_width = self.layer4_module3(x, device, batch_size, x_height, x_width, conv_op_cache) - unpadded_shape = x.shape_without_padding() + unpadded_shape = x.shape x = ttnn.untilize_with_unpadding( x, output_tensor_end=( @@ -1112,7 +1112,7 @@ def optimized_run(self, input_tensor, device, batch_size, ops_parallel_config, c ) x = self.fc(x) - desired_shape = list(x.shape_without_padding()) + desired_shape = list(x.shape) desired_shape[-1] = 1000 x = ttnn.untilize_with_unpadding( x, diff --git a/models/experimental/vgg/vgg_utils.py b/models/experimental/vgg/vgg_utils.py index a1eec8a6280..37b63b7dc77 100644 --- a/models/experimental/vgg/vgg_utils.py +++ b/models/experimental/vgg/vgg_utils.py @@ -22,7 +22,7 @@ def format_tensor(x, target_layout, device, output_mem_config, pad_value=0.0): else: return ttnn.tilize(x, memory_config=output_mem_config, use_multicore=True) elif x.get_layout() == ttnn.TILE_LAYOUT and target_layout == ttnn.ROW_MAJOR_LAYOUT: - if x.shape.with_tile_padding() != x.shape_without_padding(): + if x.shape.with_tile_padding() != x.shape: return ttnn.format_output_tensor(x, x.shape_without_padding(), device, target_layout, output_mem_config) else: return ttnn.untilize(x, memory_config=output_mem_config, use_multicore=True) diff --git a/tests/tt_eager/python_api_testing/unit_testing/misc/test_downsample.py b/tests/tt_eager/python_api_testing/unit_testing/misc/test_downsample.py index df2c9d1778d..c96973cc5c2 100644 --- a/tests/tt_eager/python_api_testing/unit_testing/misc/test_downsample.py +++ b/tests/tt_eager/python_api_testing/unit_testing/misc/test_downsample.py @@ -147,8 +147,8 @@ def test_run_downsample( out_shape = [1, 1, _nearest_y(batch_size * output_height * output_width, 32), input_channels] assert out_shape == list(out.shape.with_tile_padding()) out_shape_unpadded = [1, 1, batch_size * output_height * output_width, input_channels] - assert out_shape_unpadded == list(out.shape_without_padding()) - out = ttnn.format_output_tensor(out, out.shape_without_padding(), device, ttnn.ROW_MAJOR_LAYOUT) + assert out_shape_unpadded == list(out.shape) + out = ttnn.format_output_tensor(out, out.shape, device, ttnn.ROW_MAJOR_LAYOUT) out = out.cpu() out_debug = out diff --git a/ttnn/cpp/pybind11/pytensor.cpp b/ttnn/cpp/pybind11/pytensor.cpp index 9b390c9cd8d..b02ff536a7d 100644 --- a/ttnn/cpp/pybind11/pytensor.cpp +++ b/ttnn/cpp/pybind11/pytensor.cpp @@ -1591,16 +1591,6 @@ void pytensor_module(py::module &m_tensor) { dtype = tt_tensor.get_dtype() )doc") - .def( - "shape_without_padding", - [](const Tensor &self) { return Shape{self.get_legacy_shape().without_padding()}; }, - R"doc( - Get shape without padding of TT Tensor. - - .. code-block:: python - - dtype = tt_tensor.shape_without_padding() - )doc") .def( "reshape", [](Tensor &self, int N, int C, int H, int W) { return self.reshape(N, C, H, W); }, diff --git a/ttnn/tt_lib/fused_ops/max_pool.py b/ttnn/tt_lib/fused_ops/max_pool.py index f53377f7fc1..a6797211a60 100644 --- a/ttnn/tt_lib/fused_ops/max_pool.py +++ b/ttnn/tt_lib/fused_ops/max_pool.py @@ -28,7 +28,7 @@ def run_max_pool_on_device_wrapper( reshape_2d=False, ): def max_pool_2d(x): - # x_shape_nopad = x.shape_without_padding() + # x_shape_nopad = x.shape # out_shape_nopad = compute_max_pool_shape(kernel_size, stride, padding, x_shape_nopad) # if reshape_2d and channels_last: # x = x.reshape(x_shape_nopad[0], 1, x_shape_nopad[1] * x_shape_nopad[2], x_shape_nopad[3])