Skip to content

[batch-rule] householder_product #322

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

Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions functorch/csrc/BatchRulesDecompositions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ TORCH_LIBRARY_IMPL(aten, FT_BATCHED_KEY, m) {
OP_DECOMPOSE(frobenius_norm);
OP_DECOMPOSE(type_as);
OP_DECOMPOSE(linalg_diagonal);
OP_DECOMPOSE(orgqr);

DECOMPOSE_FUNCTIONAL(diag_embed);
DECOMPOSE_FUNCTIONAL(block_diag);
Expand Down
16 changes: 16 additions & 0 deletions functorch/csrc/BatchRulesLinearAlgebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ Tensor linear_decomp(
return result;
}

std::tuple<Tensor, c10::optional<int64_t>>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use EXISTING_BDIM or EXISTING_BDIM_ALL_BOXED for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately neither of them works.

  • EXISTING_BDIM seems to assume that only self has bdim
  • With EXISTING_BDIM_ALL_BOXED we get torch.linalg.householder_product: input.shape[-1] must be greater than or equal to tau.shape[-1]

householder_product_batch_rule(const Tensor &input, c10::optional<int64_t> input_bdim,
const Tensor &tau, c10::optional<int64_t> tau_bdim)
{
auto input_ = moveBatchDimToFront(input, input_bdim);
auto tau_ = moveBatchDimToFront(tau, tau_bdim);

auto batch_size = get_bdim_size2(input, input_bdim, tau, tau_bdim);

input_ = ensure_has_bdim(input_, input_bdim.has_value(), batch_size);
tau_ = ensure_has_bdim(tau_, tau_bdim.has_value(), batch_size);
return std::make_tuple(at::linalg_householder_product(input_, tau_), 0);
}

Tensor addmm_decomp(const Tensor& self, const Tensor& mat1, const Tensor& mat2, const Scalar& beta, const Scalar& alpha) {
// Decomposition that is probably not very fast...
return at::add(self * beta, at::mm(mat1, mat2), alpha);
Expand All @@ -165,6 +179,8 @@ TORCH_LIBRARY_IMPL(aten, FT_BATCHED_KEY, m) {
VMAP_SUPPORT(dot, dot_batch_rule);
VMAP_SUPPORT(mv, mv_batch_rule);
VMAP_SUPPORT(mm, mm_batch_rule);
VMAP_SUPPORT(linalg_householder_product,
householder_product_batch_rule);
m.impl("linear", linear_decomp);

VARIADIC_BDIMS_BOXED(cholesky_solve);
Expand Down
1 change: 0 additions & 1 deletion test/test_vmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3158,7 +3158,6 @@ def test_vmap_exhaustive(self, device, dtype, op):
xfail('linalg.cholesky'),
xfail('linalg.eigvals'),
xfail('linalg.eigvalsh'),
xfail('linalg.householder_product'),
xfail('linalg.inv'),
xfail('linalg.lstsq'),
xfail('linalg.matrix_norm'),
Expand Down