diff --git a/paddle/phi/api/yaml/legacy_api.yaml b/paddle/phi/api/yaml/legacy_api.yaml index 464ea1f00ba96eb9b727cc0c9f086860d45b2197..6408b908130250bd770e824478ea12f01a909f79 100644 --- a/paddle/phi/api/yaml/legacy_api.yaml +++ b/paddle/phi/api/yaml/legacy_api.yaml @@ -922,6 +922,18 @@ kernel : func : greater_than +# grid sample +- api : grid_sample + args : (Tensor x, Tensor grid, str mode, str padding_mode, bool align_corners) + output : Tensor(out) + infer_meta : + func : GridSampleBaseInferMeta + param : [x, grid] + kernel: + func : grid_sample + data_type : x + backward : grid_sample_grad + - api : group_norm args : (Tensor x, Tensor scale, Tensor bias, float epsilon, int groups, str data_layout) output : Tensor(y), Tensor(mean), Tensor(variance) diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/api/yaml/legacy_backward.yaml index 423958399a529970376ee8758b5a37fe4aaead1e..ba8c78edd97ca6c8f06ed065c7f90978f1a290f2 100644 --- a/paddle/phi/api/yaml/legacy_backward.yaml +++ b/paddle/phi/api/yaml/legacy_backward.yaml @@ -848,6 +848,18 @@ data_type : out_grad optional: out, dst_count +# grid sample +- backward_api : grid_sample_grad + forward : grid_sample (Tensor x, Tensor grid, str mode, str padding_mode, bool align_corners) -> Tensor(out) + args : (Tensor x, Tensor grid, Tensor out_grad, str mode, str padding_mode, bool align_corners) + output : Tensor(x_grad), Tensor(grid_grad) + infer_meta : + func : GeneralBinaryGradInferMeta + param : [x, grid] + kernel : + func : grid_sample_grad + data_type : x + - backward_api : group_norm_grad forward : group_norm (Tensor x, Tensor scale, Tensor bias, float epsilon, int groups, str data_layout) -> Tensor(y), Tensor(mean), Tensor(variance) args : (Tensor x, Tensor scale, Tensor bias, Tensor y, Tensor mean, Tensor variance, Tensor y_grad, float epsilon, int groups, str data_layout) diff --git a/python/paddle/fluid/tests/unittests/test_grid_sampler_op.py b/python/paddle/fluid/tests/unittests/test_grid_sampler_op.py index f32387d07a9fd142a42910cd59560dd3e0f37ac4..4b813330b405f9e092075d85d85317fbaf12a2e7 100644 --- a/python/paddle/fluid/tests/unittests/test_grid_sampler_op.py +++ b/python/paddle/fluid/tests/unittests/test_grid_sampler_op.py @@ -144,6 +144,7 @@ class TestGridSamplerOp(OpTest): self.use_cudnn = False self.numeric_grad_delta = 0.0001 self.op_type = 'grid_sampler' + self.python_api = paddle.nn.functional.grid_sample self.align_corners = True self.padding_mode = "zeros" self.mode = "bilinear" @@ -171,13 +172,14 @@ class TestGridSamplerOp(OpTest): } def test_check_output(self): - self.check_output() + self.check_output(check_eager=True) def test_check_grad_normal(self): self.check_grad(['X', 'Grid'], 'Output', max_relative_error=0.01, - numeric_grad_delta=self.numeric_grad_delta) + numeric_grad_delta=self.numeric_grad_delta, + check_eager=True) def initTestCase(self): self.x_shape = (2, 3, 8, 8) diff --git a/python/paddle/nn/functional/vision.py b/python/paddle/nn/functional/vision.py index 521a44f758b862a039c195328f95ade2305b5df1..b1a962845c4c54078056a56cbf4064187cb162ec 100644 --- a/python/paddle/nn/functional/vision.py +++ b/python/paddle/nn/functional/vision.py @@ -21,6 +21,7 @@ import numpy as np from paddle import _C_ops from ...device import is_compiled_with_rocm from paddle import in_dynamic_mode +from paddle.fluid.framework import in_dygraph_mode from paddle.framework import _non_static_mode __all__ = [] @@ -272,7 +273,10 @@ def grid_sample(x, x.stop_gradient = False grid.stop_gradient = False - if in_dynamic_mode(): + if in_dygraph_mode(): + return _C_ops.final_state_grid_sample(x, grid, mode, padding_mode, + align_corners) + elif in_dynamic_mode(): attrs = ('mode', mode, 'padding_mode', padding_mode, 'align_corners', align_corners, 'use_cudnn', use_cudnn) out = getattr(_C_ops, 'grid_sampler')(x, grid, *attrs)