Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions paddle/phi/kernels/impl/concat_grad_kernel_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ void ConcatGradKernel(const Context& dev_ctx,
// get output tensor that the name is not kEmptyVarName
std::vector<DenseTensor*> outputs;
for (size_t j = 0; j < outs.size(); ++j) {
if (outs[j] && outs[j]->numel() != 0UL) {
if (outs[j]) {
dev_ctx.template Alloc<T>(outs[j]);

outputs.push_back(outs[j]);
} else {
outputs.push_back(nullptr);
Expand Down
4 changes: 1 addition & 3 deletions paddle/phi/kernels/xpu/concat_grad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ void ConcatGradKernel(const Context& dev_ctx,
// get output tensor that the name is not kEmptyVarName
std::vector<XPUType*> ptrs(outs.size());
for (size_t j = 0; j < outs.size(); ++j) {
if (outs[j] && outs[j]->numel() != 0UL) {
if (outs[j]) {
dev_ctx.template Alloc<T>(outs[j]);
ptrs[j] = reinterpret_cast<XPUType*>(outs[j]->data<T>());
} else {
ptrs[j] = nullptr;
}
}
PADDLE_ENFORCE_GE(axis,
Expand Down
2 changes: 0 additions & 2 deletions python/paddle/tensor/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,8 +1458,6 @@ def is_in_amp_mode():
else:
input = [input]

if not isinstance(input, paddle.pir.Value):
input = [t for t in input if t.shape.count(0) == 0]
return _C_ops.concat(input, axis)
else:
check_type(input, 'input', (list, tuple, Variable), 'concat')
Expand Down
70 changes: 70 additions & 0 deletions test/legacy_test/test_concat_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,76 @@ def init_test_data(self):
self.axis = 1


class TestConcatOp0Size(TestConcatOp):
def setUp(self):
self.op_type = "concat"
self.python_api = paddle.concat
self.public_python_api = paddle.concat
self.prim_op_type = "prim"
self.if_enable_cinn()
self.dtype = self.get_dtype()
self.init_test_data()
self.inputs = {'X': [('x0', self.x0), ('x1', self.x1), ('x2', self.x2)]}
self.attrs = {'axis': self.axis}
if self.axis < 0:
self.actual_axis = self.axis + len(self.x0.shape)
self.actual_axis = max(0, self.actual_axis)
else:
self.actual_axis = self.axis

self.outputs = {
'Out': np.concatenate(
(self.x0, self.x1, self.x2), axis=self.actual_axis
)
}

def if_enable_cinn(self):
pass

def get_dtype(self):
return "float64"

def test_check_output(self):
self.check_output(check_pir=True)

def test_check_grad(self):
self.check_grad(
['x0'],
'Out',
check_prim=True,
check_pir=True,
check_prim_pir=True,
)
self.check_grad(
['x1'],
'Out',
check_prim=True,
check_pir=True,
check_prim_pir=True,
)
self.check_grad(
['x2'],
'Out',
check_prim=True,
check_pir=True,
check_prim_pir=True,
)

def init_test_data(self):
if self.dtype == np.uint16:
x0 = np.random.random((5, 1, 4, 5)).astype(np.float32)
self.x0 = convert_float_to_uint16(x0)
x1 = np.random.random((5, 0, 4, 5)).astype(np.float32)
self.x1 = convert_float_to_uint16(x1)
x2 = np.random.random((5, 3, 4, 5)).astype(np.float32)
self.x2 = convert_float_to_uint16(x2)
else:
self.x0 = np.random.random((5, 1, 4, 5)).astype(self.dtype)
self.x1 = np.random.random((5, 0, 4, 5)).astype(self.dtype)
self.x2 = np.random.random((5, 3, 4, 5)).astype(self.dtype)
self.axis = 1


def create_test_AxisTensor(parent):
class TestConcatAxisTensor(parent):
def setUp(self):
Expand Down
Loading