Skip to content

nonzero does not return the expected symint dimensions #3706

Open
@miladm

Description

@miladm

Running xla_y[0].is_symbolic() after torch::Tensor xla_y = torch::nonzero(xla_x); returns false even though we expect true output.

I assume the upstream dynamic shape analysis assigns the correct dynamic property to each dimension of nonzero output tensor. @Krovatkin @Gamrix wdyt?

The full test code:

TEST_F(AtenXlaTensorTest, TestExpandSymInt) {
  torch::Tensor x = torch::rand({5});
  torch::Tensor y = torch::nonzero(x);
  int64_t y0_size = y.sizes()[0];
  torch::Tensor a = torch::rand({3, 4}, torch::TensorOptions(torch::kFloat));
  torch::Tensor b = a.expand({y0_size, 3, 4}, /*implicit=*/false);

  ForEachDevice([&](const torch::Device& device) {
    torch::Tensor xla_x = CopyToDevice(x, device);
    torch::Tensor xla_y = torch::nonzero(xla_x);
    c10::SymInt xla_y0_size = xla_y.sym_sizes()[0];
    torch::Tensor xla_a = CopyToDevice(a, device);
    torch::Tensor xla_b = xla_a.expand_symint(
        c10::SymIntArrayRef({xla_y0_size, c10::SymInt(3), c10::SymInt(4)}),
        /*implicit=*/false);
    AllClose(b, xla_b);
    ExpectCounterNotChanged("aten::.*", cpp_test::GetIgnoredCounters());
    ExpectCounterChanged("xla::expand_symint", cpp_test::GetIgnoredCounters());
  });
}

Metadata

Metadata

Assignees

Labels

dynamismDynamic Shape Features

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions