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

[Eager] bilinear_tensor_product yaml #44459

Merged
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
10 changes: 10 additions & 0 deletions paddle/phi/api/yaml/legacy_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@
func : bce_loss
backward : bce_loss_grad

- api : bilinear_tensor_product
args : (Tensor x, Tensor y, Tensor weight, Tensor bias)
output : Tensor
infer_meta :
func : BilinearTensorProductInferMeta
kernel :
func : bilinear_tensor_product
optional : bias
backward : bilinear_tensor_product_grad

# bitwise_and
- api : bitwise_and
args : (Tensor x, Tensor y)
Expand Down
9 changes: 9 additions & 0 deletions paddle/phi/api/yaml/legacy_backward.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@
func : bce_loss_grad
inplace : (out_grad -> input_grad)

- backward_api : bilinear_tensor_product_grad
forward : bilinear_tensor_product (Tensor x, Tensor y, Tensor weight, Tensor bias) -> Tensor(out)
args : (Tensor x, Tensor y, Tensor weight, Tensor out_grad)
output : Tensor(x_grad), Tensor(y_grad), Tensor(weight_grad), Tensor(bias_grad)
infer_meta :
func : BilinearTensorProductGradInferMeta
kernel :
func : bilinear_tensor_product_grad

- backward_api : brelu_grad
forward : brelu (Tensor x, float t_min, float t_max) -> Tensor(out)
args : (Tensor x, Tensor out_grad, float t_min, float t_max)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import numpy as np
import paddle.fluid as fluid
from op_test import OpTest
import paddle


class TestDygraphBilinearTensorProductAPIError(unittest.TestCase):
Expand All @@ -41,6 +42,7 @@ class TestBilinearTensorProductOp(OpTest):

def setUp(self):
self.op_type = "bilinear_tensor_product"
self.python_api = paddle.nn.functional.bilinear
batch_size = 6
size0 = 5
size1 = 4
Expand All @@ -63,10 +65,10 @@ def setUp(self):
self.outputs = {'Out': output + bias}

def test_check_output(self):
self.check_output()
self.check_output(check_eager=True)

def test_check_grad_normal(self):
self.check_grad(['X', 'Y', 'Weight', 'Bias'], 'Out')
self.check_grad(['X', 'Y', 'Weight', 'Bias'], 'Out', check_eager=True)


if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion python/paddle/nn/functional/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,9 @@ def bilinear(x1, x2, weight, bias=None, name=None):

"""

if in_dynamic_mode():
if in_dygraph_mode():
return _C_ops.final_state_bilinear_tensor_product(x1, x2, weight, bias)
elif _non_static_mode():
return _C_ops.bilinear_tensor_product(x1, x2, weight, bias)

check_variable_and_dtype(x1, 'x1', ['float32', 'float64'], 'bilinear')
Expand Down