Skip to content
Open
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
18 changes: 12 additions & 6 deletions backends/vulkan/runtime/graph/ops/impl/Squeeze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,27 @@ void add_squeeze_copy_dims_node(
const ValueRef out) {
const int64_t in_dim = graph.dim_of(in);
const std::vector<int64_t> in_sizes = graph.sizes_of(in);
const std::vector<int64_t> out_sizes = graph.sizes_of(in);

const std::vector<int64_t> dims = graph.extract_int_or_symint_list(dims_ref);
std::vector<int64_t> squeeze_dims;
// Filter out edge cases that we don't need squeeze:
// 1. The size of squeeze dim is larger than 1.
// 2. Squeeze outter most dim
// For these cases, just pass input to output via clone.
// Filter out the edge case that we don't need to squeeze: the size of the
// squeeze dim is larger than 1. For that case, just pass input to output via
// clone.
//
// Note that the outermost dim must NOT be excluded here. Routing it to
// add_clone_node() leaves the output unresized at runtime, because
// resize_clone_node() only propagates sizes when input and output have the
// same dim count -- which is never true for a squeeze. Under dynamic shapes
// the output then keeps its upper-bound extents while consumers read it at
// the real size, silently producing wrong values. add_permute_node()'s
// resize function handles the rank-reducing case explicitly.
for (int i = 0; i < dims.size(); ++i) {
// adjust negative dims
int64_t dim_val = dims.at(i);
if (dim_val < 0) {
dim_val += in_dim;
}
if (dims.at(i) != 0 && in_sizes.at(dim_val) == 1) {
if (in_sizes.at(dim_val) == 1) {
squeeze_dims.push_back(dim_val);
}
}
Expand Down
Loading