diff --git a/paddle/fluid/operators/transpose_op.cc b/paddle/fluid/operators/transpose_op.cc index 35dcb25f6b784dec698a37ab6012671be66d8b88..7320c1314c6f3ba62e581faa08505a01a30c9c49 100644 --- a/paddle/fluid/operators/transpose_op.cc +++ b/paddle/fluid/operators/transpose_op.cc @@ -356,7 +356,9 @@ REGISTER_OP_CPU_KERNEL( ops::TransposeKernel>, ops::TransposeKernel>); + paddle::platform::complex>, + ops::TransposeKernel); REGISTER_OP_CPU_KERNEL( transpose_grad, ops::TransposeGradKernel, @@ -365,7 +367,9 @@ REGISTER_OP_CPU_KERNEL( ops::TransposeGradKernel>, ops::TransposeGradKernel>); + paddle::platform::complex>, + ops::TransposeGradKernel); REGISTER_OPERATOR(transpose2, ops::Transpose2Op, ops::Transpose2OpMaker, ops::Transpose2GradMaker, @@ -383,7 +387,9 @@ REGISTER_OP_CPU_KERNEL( ops::TransposeKernel>, ops::TransposeKernel>); + paddle::platform::complex>, + ops::TransposeKernel); REGISTER_OP_CPU_KERNEL( transpose2_grad, ops::TransposeGradKernel, @@ -394,4 +400,6 @@ REGISTER_OP_CPU_KERNEL( ops::TransposeGradKernel>, ops::TransposeGradKernel>); + paddle::platform::complex>, + ops::TransposeGradKernel); diff --git a/paddle/fluid/operators/transpose_op.cu b/paddle/fluid/operators/transpose_op.cu index 5bcfbee5c53bc9a3b01f21ebe5a360fae2e23372..02e224549a5abfb14729355addeb52824e450570 100644 --- a/paddle/fluid/operators/transpose_op.cu +++ b/paddle/fluid/operators/transpose_op.cu @@ -14,6 +14,7 @@ limitations under the License. */ #include "paddle/fluid/operators/transpose_op.cu.h" #include "paddle/fluid/operators/transpose_op.h" +#include "paddle/fluid/platform/bfloat16.h" #include "paddle/fluid/platform/float16.h" namespace paddle { @@ -87,6 +88,8 @@ REGISTER_OP_CUDA_KERNEL( ops::TransposeGPUKernel, ops::TransposeGPUKernel, ops::TransposeGPUKernel, + ops::TransposeGPUKernel, ops::TransposeGPUKernel>, ops::TransposeGPUKernel, ops::TransposeGradGPUKernel, + ops::TransposeGradGPUKernel, ops::TransposeGradGPUKernel>, ops::TransposeGradGPUKernel, ops::TransposeGPUKernel, ops::TransposeGPUKernel, + ops::TransposeGPUKernel, ops::TransposeGPUKernel>, ops::TransposeGPUKernel, ops::TransposeGradGPUKernel, + ops::TransposeGradGPUKernel, ops::TransposeGradGPUKernel>, ops::TransposeGradGPUKernel, ops::UnbindOpKernel, ops::UnbindOpKernel, - ops::UnbindOpKernel); + ops::UnbindOpKernel, + ops::UnbindOpKernel); diff --git a/paddle/fluid/operators/unbind_op.cu.cc b/paddle/fluid/operators/unbind_op.cu.cc index 15701b54b46062ba9e57455b51f13b535d0493b8..cec7058d3cf52eff55eb88afaa217204a72e4566 100644 --- a/paddle/fluid/operators/unbind_op.cu.cc +++ b/paddle/fluid/operators/unbind_op.cu.cc @@ -20,4 +20,5 @@ REGISTER_OP_CUDA_KERNEL( ops::UnbindOpKernel, ops::UnbindOpKernel, ops::UnbindOpKernel, - ops::UnbindOpKernel); + ops::UnbindOpKernel, + ops::UnbindOpKernel); diff --git a/python/paddle/fluid/tests/unittests/test_transpose_op.py b/python/paddle/fluid/tests/unittests/test_transpose_op.py index 4270bc8de0b1459bb88aff57919a5f0a54643ce3..0fc56726c5d0e57f88ec38db95c76495931d0f26 100644 --- a/python/paddle/fluid/tests/unittests/test_transpose_op.py +++ b/python/paddle/fluid/tests/unittests/test_transpose_op.py @@ -16,10 +16,11 @@ from __future__ import print_function import unittest import numpy as np -from op_test import OpTest +from op_test import OpTest, convert_float_to_uint16 import paddle import paddle.fluid as fluid from paddle.fluid import Program, program_guard +import paddle.fluid.core as core paddle.enable_static() @@ -113,6 +114,39 @@ class TestCase9(TestTransposeOp): self.axis = (6, 1, 3, 5, 0, 2, 4, 7) +class TestTransposeBF16Op(OpTest): + def setUp(self): + self.init_op_type() + self.initTestCase() + self.dtype = np.uint16 + x = np.random.random(self.shape).astype("float32") + + self.inputs = {'X': convert_float_to_uint16(x)} + self.attrs = { + 'axis': list(self.axis), + 'use_mkldnn': self.use_mkldnn, + } + self.outputs = { + 'XShape': convert_float_to_uint16( + np.random.random(self.shape).astype("float32")), + 'Out': self.inputs['X'].transpose(self.axis) + } + + def init_op_type(self): + self.op_type = "transpose2" + self.use_mkldnn = False + + def test_check_output(self): + self.check_output(no_check_set=['XShape']) + + def test_check_grad(self): + pass + + def initTestCase(self): + self.shape = (3, 2) + self.axis = (1, 0) + + class TestTransposeOpBool(TestTransposeOp): def test_check_grad(self): pass diff --git a/python/paddle/fluid/tests/unittests/test_unbind_op.py b/python/paddle/fluid/tests/unittests/test_unbind_op.py index 4a50fa97e6ec9d9b7c947c3f206e0435d4e67e47..e16fb6ddaacd71f1f76a72bd301fe06ce8059214 100644 --- a/python/paddle/fluid/tests/unittests/test_unbind_op.py +++ b/python/paddle/fluid/tests/unittests/test_unbind_op.py @@ -16,7 +16,7 @@ from __future__ import print_function import unittest import numpy as np -from op_test import OpTest +from op_test import OpTest, convert_float_to_uint16 import paddle.fluid as fluid import paddle.tensor as tensor from paddle.fluid import compiler, Program, program_guard, core @@ -154,6 +154,32 @@ class TestUnbindOp4(TestUnbindOp): self.out[1] = self.out[1].reshape((3, 2)) +class TestUnbindBF16Op(OpTest): + def setUp(self): + self._set_op_type() + self.dtype = self.get_dtype() + self.axis = 0 + self.num = 3 + x = np.arange(12).reshape(3, 2, 2).astype(self.dtype) + self.out = np.split(x, self.num, self.axis) + self.inputs = {'X': convert_float_to_uint16(x)} + self.attrs = {'axis': self.axis} + self.outputs = {'Out': [('out%d' % i, convert_float_to_uint16(self.out[i])) \ + for i in range(len(self.out))]} + + def get_dtype(self): + return np.uint16 + + def _set_op_type(self): + self.op_type = "unbind" + + def test_check_output(self): + self.check_output() + + def test_check_grad(self): + pass + + class TestUnbindAxisError(unittest.TestCase): def test_errors(self): with program_guard(Program(), Program()):