Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#15075: Adding assert for completely invalid reshapes #15846

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,36 +52,6 @@ ttnn::Tensor convert_tile_to_rm(
(tensor.get_dtype() == DataType::BFLOAT8_B) ? ttnn::typecast(new_tensor, tensor.get_dtype()) : new_tensor;
return new_tensor;
}
ttnn::Tensor host_reshape(const ttnn::Tensor& tensor, const ttnn::Shape& shape) {
Copy link
Contributor

Choose a reason for hiding this comment

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

So happy to see this removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RIP - it won't be missed

//This function is due to embedding issue 15558, once the issue is fixed we want to delete it
tt::log_warning("host_reshape is deprecated and will be removed in the near future");
if (!ttnn::has_storage_type_of(tensor, ttnn::StorageType::DEVICE)) {
return tensor.reshape(shape);
}
auto tensor_shape = tensor.shape();
auto layout = tensor.layout();
auto device = tensor.device();
auto memory_config = tensor.memory_config();
auto host_tensor = tensor.cpu();
auto rm_tensor = ttnn::to_layout(host_tensor, ttnn::ROW_MAJOR_LAYOUT, std::nullopt, std::nullopt, (Device*)nullptr);

if (tensor_shape.has_tile_padding()) {
ttnn::Tensor slice_input;
auto host_tensor_4d = unsqueeze_to_4D(rm_tensor);
auto tensor_shape_4d = host_tensor_4d.shape();
ttnn::SmallVector<uint32_t> begins({0, 0, 0, 0});
ttnn::SmallVector<uint32_t> ends(
{tensor_shape_4d[0], tensor_shape_4d[1], tensor_shape_4d[2], tensor_shape_4d[3]});
ttnn::SmallVector<uint32_t> step({1, 1, 1, 1});
host_tensor_4d = ttnn::slice(host_tensor_4d, begins, ends, step, std::nullopt);
host_tensor = squeeze_from_4D(host_tensor_4d, tensor_shape.rank());
}
auto host_reshape_tensor = rm_tensor.reshape(shape);
auto final_layout_tensor =
ttnn::to_layout(host_reshape_tensor, layout, std::nullopt, std::nullopt, (Device*)nullptr);
auto device_tensor = ttnn::data_transfer_to_device(final_layout_tensor, device, memory_config);
return device_tensor;
}

//Wrapper to turn the ND-> MD problem into 3D->3D for tiled and 2D->2D for Row Major

Expand Down Expand Up @@ -399,7 +369,7 @@ ttnn::Tensor ReshapeViewOperation::invoke(
return tensor.reshape(shape);
}
//This is a completely incorrect test but it is due to issue 15558
return detail::host_reshape(tensor, shape);
TT_FATAL(false, "Attempting to reshape between two shapes with different volumes");
}
// Catch-all
// Do the reshape in row-major
Expand Down
Loading