Skip to content
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
12 changes: 12 additions & 0 deletions paddle/phi/api/yaml/legacy_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions paddle/phi/api/yaml/legacy_backward.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions python/paddle/fluid/tests/unittests/test_grid_sampler_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def setUp(self):
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"
Expand Down Expand Up @@ -171,13 +172,14 @@ def setUp(self):
}

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)
Expand Down
6 changes: 5 additions & 1 deletion python/paddle/nn/functional/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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__ = []
Expand Down Expand Up @@ -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)
Expand Down