Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MLU] fix log_softmax mode selection. #44669

Merged
merged 1 commit into from
Jul 28, 2022
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
7 changes: 3 additions & 4 deletions paddle/fluid/operators/softmax_op_mlu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ REGISTER_OP_MLU_KERNEL(softmax_grad,
ops::SoftmaxGradMLUKernel<CNNL_SOFTMAX_ACCURATE, float>,
ops::SoftmaxGradMLUKernel<CNNL_SOFTMAX_ACCURATE,
paddle::platform::float16>);
REGISTER_OP_MLU_KERNEL(
log_softmax,
ops::SoftmaxMLUKernel<CNNL_SOFTMAX_LOG, float>,
ops::SoftmaxMLUKernel<CNNL_SOFTMAX_ACCURATE, plat::float16>);
REGISTER_OP_MLU_KERNEL(log_softmax,
ops::SoftmaxMLUKernel<CNNL_SOFTMAX_LOG, float>,
ops::SoftmaxMLUKernel<CNNL_SOFTMAX_LOG, plat::float16>);
REGISTER_OP_MLU_KERNEL(
log_softmax_grad,
ops::SoftmaxGradMLUKernel<CNNL_SOFTMAX_LOG, float>,
Expand Down
35 changes: 35 additions & 0 deletions python/paddle/fluid/tests/unittests/mlu/test_log_softmax_op_mlu.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,41 @@ def set_attrs(self):
self.axis = 1


class TestLogSoftmaxOpFp16(OpTest):

def setUp(self):
self.op_type = 'log_softmax'
self.set_mlu()
self.python_api = F.log_softmax
self.dtype = 'float16'
self.shape = [2, 3, 4, 5]
self.axis = -1
self.set_attrs()

x = np.random.uniform(0.1, 1., self.shape).astype(self.dtype)
out = np.apply_along_axis(ref_log_softmax, self.axis, x)
self.x_grad = ref_log_softmax_grad(x, self.axis)

self.inputs = {'X': x}
self.outputs = {'Out': out}
self.attrs = {'axis': self.axis}

def set_attrs(self):
pass

def set_mlu(self):
self.__class__.use_mlu = True
self.place = paddle.device.MLUPlace(0)

def test_check_output(self):
self.check_output_with_place(self.place, atol=1e-2)

def test_check_grad(self):
self.check_grad_with_place(self.place, ['X'], ['Out'],
user_defined_grads=[self.x_grad],
max_relative_error=0.015)


class TestNNLogSoftmaxAPI(unittest.TestCase):

def setUp(self):
Expand Down