未验证 提交 b470bd18 编写于 作者: W Wang Bojun 提交者: GitHub

Phi gird sampler migration (#44562)

* add_ymal_utest for phi grid_sampler op
上级 c5a1e49c
...@@ -922,6 +922,18 @@ ...@@ -922,6 +922,18 @@
kernel : kernel :
func : greater_than 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 - api : group_norm
args : (Tensor x, Tensor scale, Tensor bias, float epsilon, int groups, str data_layout) args : (Tensor x, Tensor scale, Tensor bias, float epsilon, int groups, str data_layout)
output : Tensor(y), Tensor(mean), Tensor(variance) output : Tensor(y), Tensor(mean), Tensor(variance)
......
...@@ -848,6 +848,18 @@ ...@@ -848,6 +848,18 @@
data_type : out_grad data_type : out_grad
optional: out, dst_count 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 - 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) 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) args : (Tensor x, Tensor scale, Tensor bias, Tensor y, Tensor mean, Tensor variance, Tensor y_grad, float epsilon, int groups, str data_layout)
......
...@@ -144,6 +144,7 @@ class TestGridSamplerOp(OpTest): ...@@ -144,6 +144,7 @@ class TestGridSamplerOp(OpTest):
self.use_cudnn = False self.use_cudnn = False
self.numeric_grad_delta = 0.0001 self.numeric_grad_delta = 0.0001
self.op_type = 'grid_sampler' self.op_type = 'grid_sampler'
self.python_api = paddle.nn.functional.grid_sample
self.align_corners = True self.align_corners = True
self.padding_mode = "zeros" self.padding_mode = "zeros"
self.mode = "bilinear" self.mode = "bilinear"
...@@ -171,13 +172,14 @@ class TestGridSamplerOp(OpTest): ...@@ -171,13 +172,14 @@ class TestGridSamplerOp(OpTest):
} }
def test_check_output(self): def test_check_output(self):
self.check_output() self.check_output(check_eager=True)
def test_check_grad_normal(self): def test_check_grad_normal(self):
self.check_grad(['X', 'Grid'], self.check_grad(['X', 'Grid'],
'Output', 'Output',
max_relative_error=0.01, 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): def initTestCase(self):
self.x_shape = (2, 3, 8, 8) self.x_shape = (2, 3, 8, 8)
......
...@@ -21,6 +21,7 @@ import numpy as np ...@@ -21,6 +21,7 @@ import numpy as np
from paddle import _C_ops from paddle import _C_ops
from ...device import is_compiled_with_rocm from ...device import is_compiled_with_rocm
from paddle import in_dynamic_mode from paddle import in_dynamic_mode
from paddle.fluid.framework import in_dygraph_mode
from paddle.framework import _non_static_mode from paddle.framework import _non_static_mode
__all__ = [] __all__ = []
...@@ -272,7 +273,10 @@ def grid_sample(x, ...@@ -272,7 +273,10 @@ def grid_sample(x,
x.stop_gradient = False x.stop_gradient = False
grid.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', attrs = ('mode', mode, 'padding_mode', padding_mode, 'align_corners',
align_corners, 'use_cudnn', use_cudnn) align_corners, 'use_cudnn', use_cudnn)
out = getattr(_C_ops, 'grid_sampler')(x, grid, *attrs) out = getattr(_C_ops, 'grid_sampler')(x, grid, *attrs)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册