Skip to content

tensorinv and other linear algebra operators should not do a universal catch all block #53739

@ezyang

Description

@ezyang

In the implementation of tensorinv we have:

  // If the reshaped self is not invertible catch this error
  Tensor result;
  try {
    result = at::inverse(self.reshape({prod_ind_end, prod_ind_end}));
  } catch (...) {
    TORCH_CHECK(false, "Failed to invert the input tensor, because it is singular.");
  }

This is bad code practice. For example, the inner operation could raise an exception because it ran out of memory, and you would still report it as singular. More concretely, this resulted in wrong behavior at https://github.com/pytorch/pytorch/pull/53682/files/29f176c952d5dd5614c933398fe3ed92de690a9e#diff-7e17421f32124016eb8de04dc2f445da5786a28355e1addc72b305466f590180 We shouldn't do a catch all. Ideally, there would be some interface to at::inverse that would let it explicitly signal, e.g., via boolean, that input was singular.

Related #47608

cc @jianyuh @nikitaved @pearu @mruberry @heitorschueroff @walterddr @IvanYashchuk @glaringlee

Metadata

Metadata

Assignees

No one assigned

    Labels

    better-engineeringRelatively self-contained tasks for better engineering contributorsmodule: linear algebraIssues related to specialized linear algebra operations in PyTorch; includes matrix multiply matmultriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions