Skip to content

Commit

Permalink
#0: Fix failing UT
Browse files Browse the repository at this point in the history
  • Loading branch information
sankarmanoj-tt committed Dec 21, 2024
1 parent 1007506 commit 83628b8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 1 addition & 3 deletions tests/ttnn/unit_tests/operations/test_new_conv2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,20 +530,18 @@ def test_conv_features_multi_device(
@pytest.mark.parametrize(
"batch_size, output_channels, input_channels, input_height, input_width, filter_height, filter_width, pad_h, pad_w, act_block_w_div",
(
(2, 128, 128, 9, 9, 3, 3, 0, 0, 1),
(2, 128, 256, 9, 9, 3, 3, 1, 1, 1),
(2, 576, 576, 9, 9, 3, 3, 0, 0, 1),
(2, 960, 960, 5, 5, 3, 3, 0, 0, 1),
(2, 256, 2048, 9, 9, 3, 3, 1, 1, 1),
(2, 512, 2048, 17, 17, 3, 3, 1, 1, 1),
(2, 768, 768, 17, 17, 3, 3, 0, 0, 1),
(2, 1280, 2560, 15, 15, 3, 3, 1, 1, 2),
(2, 1280, 2560, 15, 15, 3, 3, 0, 0, 2),
(2, 1280, 1280, 17, 17, 3, 3, 1, 1, 1),
[1, 3024, 1232, 14, 14, 1, 1, 0, 0, 1],
(2, 768, 32, 9, 9, 3, 3, 1, 1, 1),
(2, 64, 128, 9, 9, 3, 3, 1, 1, 1),
(2, 32, 128, 9, 9, 3, 3, 1, 1, 1),
(1, 256, 256, 7, 7, 3, 3, 1, 1, 1),
),
)
@pytest.mark.parametrize(
Expand Down
5 changes: 3 additions & 2 deletions ttnn/cpp/ttnn/operations/conv/conv2d/conv2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ Result conv2d(
const std::optional<const Conv2dConfig>& conv_config_,
const std::optional<const DeviceComputeKernelConfig>& compute_config_,
const std::optional<const MemoryConfig>& memory_config) {
const bool mm_conv = use_matmul_for_1x1_conv(kernel_size, stride, padding, dilation, groups);
Conv2dConfig conv_config = conv_config_.value_or(Conv2dConfig());
const bool mm_conv = use_matmul_for_1x1_conv(kernel_size, stride, padding, dilation, groups) && conv_config.shard_layout.has_value() && conv_config.shard_layout.value() != TensorMemoryLayout::WIDTH_SHARDED;
const uint32_t output_height = ((input_height - kernel_size[0] - ((kernel_size[0] - 1 ) * (dilation[0] - 1)) + 2 * padding[0]) / stride[0]) + 1;
const uint32_t output_width =
((input_width - kernel_size[1] - ((kernel_size[0] - 1) * (dilation[0] - 1)) + 2 * padding[1]) / stride[1]) + 1;

Conv2dConfig conv_config = conv_config_.value_or(Conv2dConfig());
const auto compute_grid_size = device->compute_with_storage_grid_size();

bool auto_shard = false;
Expand Down Expand Up @@ -192,6 +192,7 @@ Result conv2d(

if (bypass_halo) {
if (input_tensor_post_tm.layout() == Layout::TILE) {
input_tensor_post_tm = ttnn::reshape(input_tensor_post_tm, input_tensor_post_tm.get_padded_shape());
input_tensor_post_tm = ttnn::to_layout(
input_tensor_post_tm, Layout::ROW_MAJOR, std::nullopt, std::nullopt, device);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ttnn::Tensor conv_bias_layout_convert(
validate_bias_tensor(bias_tensor_);
if (!is_non_tile_mul_width) {
auto bias_shape = bias_tensor_.get_shape();
TT_FATAL(bias_shape[3] == out_channels && bias_shape[0] == 1 && bias_shape[1] == 1 && bias_shape[2] == 1, "bias shape is not correct");
TT_FATAL(bias_shape[0] == 1 && bias_shape[1] == 1 && bias_shape[2] == 1, "bias shape is not correct");
tt::tt_metal::LegacyShape bias_channels_padded_shape = tt::tt_metal::LegacyShape(
std::array<uint32_t, 4>({1, 1, 32, round_up(out_channels, weight_block_w_ntiles * 32)}));
bias_tensor_ = ttnn::pad(bias_tensor_, bias_channels_padded_shape.to_array_4D(), tt::tt_metal::Array4D{0, 0, 0, 0}, 0);
Expand Down Expand Up @@ -292,7 +292,7 @@ std::pair<ttnn::Tensor, std::optional<ttnn::Tensor>> prepare_conv_weights_biases
bias_tensor_ = bias_tensor.value();
bool is_bias_tensor_is_on_device = ttnn::is_tensor_on_device_or_multidevice(bias_tensor_);
if(!is_bias_tensor_is_on_device) {
bias_tensor_ = conv_bias_layout_convert(bias_tensor_, weights_bias_dtype, weight_block_h_ntiles, weight_block_w_ntiles, input_parallel_config, device, out_channels, is_non_tile_mul_width);
bias_tensor_ = conv_bias_layout_convert(bias_tensor_, weights_bias_dtype, weight_block_h_ntiles, weight_block_w_ntiles, output_parallel_config, device, out_channels_padded, is_non_tile_mul_width);
bias_tensor_ = ttnn::operations::core::to_device(bias_tensor_, device, std::nullopt);
}
}
Expand Down Expand Up @@ -465,14 +465,17 @@ ttnn::Tensor prepare_conv_bias(
shard_orientation,
!use_non_tile_height);

ParallelConfig output_parallel_config =
determine_output_parallel_config(parallel_config, device->compute_with_storage_grid_size(), out_channels, mm_conv);

bool is_non_tile_mul_width = check_non_tile_mul_width(device, conv_config, in_channels);
ttnn::Tensor bias_tensor_ = bias_tensor;
bias_tensor_ = conv_bias_layout_convert(
bias_tensor_,
conv_config.weights_dtype,
opt_conv_op_block_config.act_block_h_ntiles,
weight_block_w_ntiles,
parallel_config,
output_parallel_config,
device,
out_channels,
is_non_tile_mul_width
Expand Down

0 comments on commit 83628b8

Please sign in to comment.