From 55e5ab82ec048279ade000a0ef6b89cb8c7f3606 Mon Sep 17 00:00:00 2001 From: wanghuancoder Date: Thu, 21 Jul 2022 17:47:06 +0800 Subject: [PATCH] [Eager] bilinear_tensor_product yaml (#44459) * bilinear_tensor_product yaml --- paddle/phi/api/yaml/legacy_api.yaml | 10 ++++++++++ paddle/phi/api/yaml/legacy_backward.yaml | 9 +++++++++ .../tests/unittests/test_bilinear_tensor_product_op.py | 6 ++++-- python/paddle/nn/functional/common.py | 4 +++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/paddle/phi/api/yaml/legacy_api.yaml b/paddle/phi/api/yaml/legacy_api.yaml index 3e2e0f70a92..69f37c374cf 100644 --- a/paddle/phi/api/yaml/legacy_api.yaml +++ b/paddle/phi/api/yaml/legacy_api.yaml @@ -280,6 +280,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) diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/api/yaml/legacy_backward.yaml index 73749b94870..aa83bb54a03 100644 --- a/paddle/phi/api/yaml/legacy_backward.yaml +++ b/paddle/phi/api/yaml/legacy_backward.yaml @@ -251,6 +251,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) diff --git a/python/paddle/fluid/tests/unittests/test_bilinear_tensor_product_op.py b/python/paddle/fluid/tests/unittests/test_bilinear_tensor_product_op.py index 53019249270..6eb7e8547d2 100644 --- a/python/paddle/fluid/tests/unittests/test_bilinear_tensor_product_op.py +++ b/python/paddle/fluid/tests/unittests/test_bilinear_tensor_product_op.py @@ -18,6 +18,7 @@ import unittest import numpy as np import paddle.fluid as fluid from op_test import OpTest +import paddle class TestDygraphBilinearTensorProductAPIError(unittest.TestCase): @@ -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 @@ -63,10 +65,10 @@ class TestBilinearTensorProductOp(OpTest): 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__": diff --git a/python/paddle/nn/functional/common.py b/python/paddle/nn/functional/common.py index e10a1c10691..b5e34199aaf 100644 --- a/python/paddle/nn/functional/common.py +++ b/python/paddle/nn/functional/common.py @@ -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') -- GitLab