Skip to content

Added addr op decomposition #323

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

Merged
merged 1 commit into from
Dec 8, 2021
Merged
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
9 changes: 9 additions & 0 deletions functorch/csrc/BatchRulesBinaryOps.cpp
Original file line number Diff line number Diff line change
@@ -155,6 +155,14 @@ std::tuple<Tensor,optional<int64_t>> masked_select_batch_rule(
return std::make_tuple(result, 0);
}

Tensor addr_decomposition(
const Tensor& self, const Tensor& vec1, const Tensor& vec2,
const Scalar& beta, const Scalar& alpha) {

auto outer = alpha * vec1.unsqueeze(-1) * vec2.unsqueeze(-2);
return self * beta + outer;
}

TORCH_LIBRARY_IMPL(aten, FT_BATCHED_KEY, m) {
#define BINARY_POINTWISE2(op, overload) \
VMAP_SUPPORT(#op"."#overload, BINARY_POINTWISE_BATCH_RULE(ATEN_FN2(op, overload)));
@@ -193,6 +201,7 @@ TORCH_LIBRARY_IMPL(aten, FT_BATCHED_KEY, m) {
BINARY_SCALAR_2(add, Tensor, Scalar);
POINTWISE_BOXED(addcdiv);
POINTWISE_BOXED(addcmul);
m.impl("addr", addr_decomposition);
BINARY_POINTWISE(atan2);
BINARY_SCALAR_2(bitwise_and, Tensor, Scalar);
BINARY_POINTWISE2(bitwise_or, Tensor);
1 change: 0 additions & 1 deletion test/test_ops.py
Original file line number Diff line number Diff line change
@@ -570,7 +570,6 @@ def test_vmapjvp(self, device, dtype, op):
@skipOps('TestOperators', 'test_vmapvjp_has_batch_rule', vmapvjp_fail.union({
xfail('view_as_complex'),
xfail('__getitem__'),
xfail('addr'),
xfail('cdist'),
xfail('cholesky'),
xfail('clamp'),
1 change: 0 additions & 1 deletion test/test_vmap.py
Original file line number Diff line number Diff line change
@@ -3099,7 +3099,6 @@ def test_vmap_exhaustive(self, device, dtype, op):

@ops(functorch_lagging_op_db + additional_op_db, allowed_dtypes=(torch.float,))
@skipOps('TestVmapOperatorsOpInfo', 'test_op_has_batch_rule', vmap_fail.union({
xfail('addr'),
xfail('cdist'),
xfail('complex'),
xfail('copysign'),