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

fix squeeze op lowering issue when dim is not in sorted order #5751

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
refactor BuildSqueezedDimensions
  • Loading branch information
zpcore committed Nov 7, 2023
commit a92d323f23025ba94ff2c18ef2f51eaeba8b6481
17 changes: 9 additions & 8 deletions torch_xla/csrc/data_ops.cpp
Original file line number Diff line number Diff line change
@@ -165,14 +165,8 @@ xla::XlaOp BuildMaskedFillScalar(xla::XlaOp input, xla::XlaOp mask,

std::vector<int64_t> BuildSqueezedDimensions(
absl::Span<const int64_t> dimensions, int64_t squeeze_dim) {
std::vector<int64_t> output_dimensions;
for (int64_t i = 0; i < dimensions.size(); ++i) {
int64_t dim = dimensions[i];
if (dim != 1 || (i != squeeze_dim && squeeze_dim >= 0)) {
output_dimensions.push_back(dim);
}
}
return output_dimensions;
std::vector<int64_t> squeeze_dims({squeeze_dim});
return BuildSqueezedDimensions(dimensions, squeeze_dims);
}

std::vector<int64_t> BuildSqueezedDimensions(
@@ -182,6 +176,13 @@ std::vector<int64_t> BuildSqueezedDimensions(
size_t i = 0;
for (size_t j = 0; j < dimensions.size(); j++) {
auto dim = dimensions[j];
if (squeeze_dims.size() == 1 && squeeze_dims[0] == -1) {
// Special case where squeeze_dims = {-1}.
if (dim != 1) {
output_dimensions.push_back(dim);
}
continue;
}
if (i == squeeze_dims.size() || j < squeeze_dims[i]) {
output_dimensions.push_back(dim);
continue;