未验证 提交 b8968390 编写于 作者: R Ruibiao Chen 提交者: GitHub

Add yaml for deformable_conv and deformable_conv_v1 OPs (#41644)

* Add yaml for deformable_conv and deformable_conv_v1 OPs

* Add UT

* Add to skipped_phi_api list for infrt
上级 b1adde3d
......@@ -169,6 +169,27 @@ void CrossEntropyWithSoftmaxGradInferMeta(const MetaTensor& label,
logits_grad->set_dtype(softmax.dtype());
}
void DeformableConvGradInferMeta(const MetaTensor& x,
const MetaTensor& offset,
const MetaTensor& filter,
paddle::optional<const MetaTensor&> mask,
const MetaTensor& out_grad,
const std::vector<int>& strides,
const std::vector<int>& paddings,
const std::vector<int>& dilations,
int deformable_groups,
int groups,
int im2col_step,
MetaTensor* dx,
MetaTensor* offset_grad,
MetaTensor* filter_grad,
MetaTensor* mask_grad) {
GeneralTernaryGradInferMeta(x, offset, filter, dx, offset_grad, filter_grad);
if (mask) {
UnchangedInferMeta(mask.get(), mask_grad);
}
}
void GatherNdGradInferMeta(const MetaTensor& x,
const MetaTensor& index,
const MetaTensor& out_grad,
......
......@@ -79,6 +79,22 @@ void CrossEntropyWithSoftmaxGradInferMeta(const MetaTensor& label,
MetaTensor* logits_grad,
MetaConfig config = MetaConfig());
void DeformableConvGradInferMeta(const MetaTensor& x,
const MetaTensor& offset,
const MetaTensor& filter,
paddle::optional<const MetaTensor&> mask,
const MetaTensor& out_grad,
const std::vector<int>& strides,
const std::vector<int>& paddings,
const std::vector<int>& dilations,
int deformable_groups,
int groups,
int im2col_step,
MetaTensor* dx,
MetaTensor* offset_grad,
MetaTensor* filter_grad,
MetaTensor* mask_grad);
void GatherNdGradInferMeta(const MetaTensor& x,
const MetaTensor& index,
const MetaTensor& out_grad,
......
......@@ -968,7 +968,7 @@ set_tests_properties(test_lstm_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_imperative_star_gan_with_gradient_penalty PROPERTIES TIMEOUT 120)
set_tests_properties(test_bicubic_interp_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_deformable_conv_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_deformable_conv_op PROPERTIES TIMEOUT 200)
set_tests_properties(test_nearest_interp_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_profiler PROPERTIES TIMEOUT 120)
set_tests_properties(test_inplace_softmax_with_cross_entropy PROPERTIES TIMEOUT 120)
......@@ -1045,7 +1045,7 @@ set_tests_properties(test_distributed_fused_lamb_op_with_clip PROPERTIES TIMEOUT
set_tests_properties(test_distributed_fused_lamb_op_without_clip PROPERTIES TIMEOUT 120)
set_tests_properties(test_elementwise_min_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_nan_inf PROPERTIES TIMEOUT 120)
set_tests_properties(test_deformable_conv_v1_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_deformable_conv_v1_op PROPERTIES TIMEOUT 300)
set_tests_properties(test_parallel_executor_transformer_auto_growth PROPERTIES TIMEOUT 120)
set_tests_properties(test_py_reader_using_executor PROPERTIES TIMEOUT 120)
set_tests_properties(test_elementwise_add_op PROPERTIES TIMEOUT 120)
......
......@@ -17,6 +17,7 @@ import paddle.nn.functional as F
import paddle.nn.initializer as I
import numpy as np
import unittest
from paddle.fluid.framework import _test_eager_guard
from unittest import TestCase
......@@ -183,6 +184,10 @@ class TestDeformConv2D(TestCase):
self.place = paddle.CUDAPlace(0)
self._test_identity()
def test_identity_with_eager_guard(self):
with _test_eager_guard():
self.test_identity()
class TestDeformConv2DFunctional(TestCase):
batch_size = 4
......@@ -418,6 +423,10 @@ class TestDeformConv2DFunctional(TestCase):
self.place = paddle.CUDAPlace(0)
self._test_identity()
def test_identity_with_eager_guard(self):
with _test_eager_guard():
self.test_identity()
# testcases for DeformConv2D
class TestDeformConv2DWithPadding(TestDeformConv2D):
......
......@@ -14,13 +14,15 @@
from __future__ import print_function
import paddle
import unittest
import numpy as np
import paddle
import paddle.fluid.core as core
import paddle.fluid as fluid
from op_test import OpTest
from paddle.fluid.framework import _test_eager_guard
paddle.enable_static()
def dmc_bilinear(data_im, height, width, h, w):
......@@ -108,8 +110,24 @@ def dconv_im2col_gemm(input, offset, mask, filter, group, conv_param):
return out
def deform_conv2d_wrapper(x,
offset,
weight,
mask=None,
stride=1,
padding=0,
dilation=1,
deformable_groups=1,
groups=1,
im2col_step=1):
return paddle.vision.ops.deform_conv2d(x, offset, weight, None, stride,
padding, dilation, deformable_groups,
groups, mask)
class TestModulatedDeformableConvOp(OpTest):
def setUp(self):
self.python_api = deform_conv2d_wrapper
self.op_type = "deformable_conv"
self.init_type()
self.init_group()
......@@ -148,13 +166,14 @@ class TestModulatedDeformableConvOp(OpTest):
self.outputs = {'Output': output}
def test_check_output(self):
self.check_output()
self.check_output(check_eager=True)
def test_check_grad(self):
self.check_grad(
{'Input', 'Offset', 'Mask', 'Filter'},
'Output',
max_relative_error=0.05)
max_relative_error=0.05,
check_eager=True)
def init_test_case(self):
self.pad = [1, 1]
......@@ -327,6 +346,10 @@ class TestModulatedDeformableConvInvalidInput(unittest.TestCase):
self.assertRaises(ValueError, test_invalid_filter)
def test_error_with_eager_guard(self):
with _test_eager_guard():
self.test_error()
class TestDeformConv2DAPI(unittest.TestCase):
def test_api(self):
......@@ -358,6 +381,10 @@ class TestDeformConv2DAPI(unittest.TestCase):
test_deform_conv2d_v2()
def test_api_with_eager_guard(self):
with _test_eager_guard():
self.test_api()
if __name__ == '__main__':
unittest.main()
......@@ -14,12 +14,13 @@
from __future__ import print_function
import paddle
import unittest
import numpy as np
import paddle.fluid.core as core
import paddle.fluid as fluid
import paddle.fluid.core as core
from op_test import OpTest
from paddle.fluid.framework import _test_eager_guard
def dmc_bilinear(data_im, height, width, h, w):
......@@ -105,8 +106,24 @@ def dconv_im2col_gemm(input, offset, filter, group, conv_param):
return out
def deform_conv2d_wrapper(x,
offset,
weight,
mask=None,
stride=1,
padding=0,
dilation=1,
deformable_groups=1,
groups=1,
im2col_step=1):
return paddle.vision.ops.deform_conv2d(x, offset, weight, None, stride,
padding, dilation, deformable_groups,
groups, mask)
class TestModulatedDeformableConvOp(OpTest):
def setUp(self):
self.python_api = deform_conv2d_wrapper
self.op_type = "deformable_conv_v1"
self.init_type()
self.init_group()
......@@ -142,18 +159,22 @@ class TestModulatedDeformableConvOp(OpTest):
self.outputs = {'Output': output}
def test_check_output(self):
self.check_output()
self.check_output(check_eager=True)
def test_check_grad(self):
self.check_grad(
['Input', 'Offset', 'Filter'], 'Output', max_relative_error=0.05)
['Input', 'Offset', 'Filter'],
'Output',
max_relative_error=0.05,
check_eager=True)
def test_check_grad_no_filter(self):
self.check_grad(
['Input', 'Offset'],
'Output',
max_relative_error=0.1,
no_grad_set=set(['Filter']))
no_grad_set=set(['Filter']),
check_eager=True)
def init_test_case(self):
self.pad = [1, 1]
......@@ -292,6 +313,10 @@ class TestModulatedDeformableConvV1InvalidInput(unittest.TestCase):
self.assertRaises(TypeError, test_invalid_offset)
def test_error_with_eager_guard(self):
with _test_eager_guard():
self.test_error()
if __name__ == '__main__':
unittest.main()
......@@ -451,6 +451,16 @@
func : cumsum
backward : cumsum_grad
- api : deformable_conv
args : (Tensor x, Tensor offset, Tensor filter, Tensor mask, int[] strides, int[] paddings, int[] dilations, int deformable_groups, int groups, int im2col_step)
output : Tensor(out)
infer_meta :
func : DeformableConvInferMeta
kernel :
func : deformable_conv
optional : mask
backward : deformable_conv_grad
- api : depthwise_conv2d_transpose
args : (Tensor x, Tensor filter, int[] strides, int[] paddings, int[] output_padding, int[] output_size, str padding_algorithm, int groups, int[] dilations, str data_format)
output : Tensor(out)
......
......@@ -339,6 +339,16 @@
output : Tensor(x_grad)
invoke : cumsum(out_grad, axis, flatten, exclusive, !reverse)
- backward_api : deformable_conv_grad
forward : deformable_conv(Tensor x, Tensor offset, Tensor filter, Tensor mask, int[] strides, int[] paddings, int[] dilations, int deformable_groups, int groups, int im2col_step) -> Tensor(out)
args : (Tensor x, Tensor offset, Tensor filter, Tensor mask, Tensor out_grad, int[] strides, int[] paddings, int[] dilations, int deformable_groups, int groups, int im2col_step)
output : Tensor(x_grad), Tensor(offset_grad), Tensor(filter_grad), Tensor(mask_grad)
infer_meta :
func : DeformableConvGradInferMeta
kernel :
func : deformable_conv_grad
optional : mask
- backward_api : depthwise_conv2d_transpose_grad
forward : depthwise_conv2d_transpose(Tensor x, Tensor filter, int[] strides, int[] paddings, int[] output_padding, int[] output_size, str padding_algorithm, int groups, int[] dilations, str data_format) -> Tensor(out)
args : (Tensor x, Tensor filter, Tensor out_grad, int[] strides, int[] paddings, int[] output_padding, int[] output_size, str padding_algorithm, int groups, int[] dilations, str data_format)
......
......@@ -558,7 +558,15 @@ def deform_conv2d(x,
use_deform_conv2d_v1 = True if mask is None else False
if _non_static_mode():
if in_dygraph_mode():
pre_bias = _C_ops.final_state_deformable_conv(
x, offset, weight, mask, stride, padding, dilation,
deformable_groups, groups, 1)
if bias is not None:
out = nn.elementwise_add(pre_bias, bias, axis=1)
else:
out = pre_bias
elif _in_legacy_dygraph():
attrs = ('strides', stride, 'paddings', padding, 'dilations', dilation,
'deformable_groups', deformable_groups, 'groups', groups,
'im2col_step', 1)
......
{
"phi_apis":["conj", "dropout", "expand_as", "nll_loss", "psroi_pool", "roi_align", "roi_pool", "label_smooth", "layer_norm"],
"phi_apis":["conj", "deformable_conv", "dropout", "expand_as", "nll_loss", "psroi_pool", "roi_align", "roi_pool", "label_smooth", "layer_norm"],
"phi_kernels":["equal_all"]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册