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

[XPU] remove clip of c_softmax_with_cross_entropy op #53734

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,6 @@ struct CSoftmaxWithCrossEntropyProcessGroupFunctor<phi::XPUContext, T> {
};
phi::XPUElementwise<T, XPUType>(
dev_ctx, logits_2d, logits_max, axis, &softmax_2d, f);
ret = xpu::clip<XPUType>(dev_ctx.x_context(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去掉clip会对结果有影响吗?
比如gpu kernel内部处理 了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

咨询过PaddlePaddle同学,回答说里面没有clip。
图片

reinterpret_cast<XPUType*>(softmax_2d.data<T>()),
reinterpret_cast<XPUType*>(softmax_2d.data<T>()),
N * D,
-64.,
0.);
PADDLE_ENFORCE_XDNN_SUCCESS(ret, "clip");
}

// step 3, obtain predict target
Expand Down Expand Up @@ -335,13 +328,6 @@ struct CSoftmaxWithCrossEntropyFunctor<phi::XPUContext, T> {
};
phi::XPUElementwise<T, XPUType>(
dev_ctx, logits_2d, logits_max, axis, &softmax_2d, f);
ret = xpu::clip<XPUType>(dev_ctx.x_context(),
reinterpret_cast<XPUType*>(softmax_2d.data<T>()),
reinterpret_cast<XPUType*>(softmax_2d.data<T>()),
N * D,
-64.,
0.);
PADDLE_ENFORCE_XDNN_SUCCESS(ret, "clip");
}

// step 3, obtain predict target
Expand Down
2 changes: 1 addition & 1 deletion test/xpu/collective_softmax_with_cross_entropy_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def run_trainer(self, args):
# each xpu uses own half of logits
np.random.seed(os.getpid())
logits = np.random.uniform(
low=-10.0, high=10.0, size=(self.batch_size, self.local_elements)
low=-40.0, high=40.0, size=(self.batch_size, self.local_elements)
).astype(np_data_type)
out = exe.run(
train_prog,
Expand Down
6 changes: 3 additions & 3 deletions test/xpu/test_collective_softmax_with_cross_entropy_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def stable_softmax(x):
"""Compute the softmax of vector x in a numerically stable way."""
# clip to shiftx, otherwise, when calc loss with
# log(exp(shiftx)), may get log(0)=INF
shiftx = (x - np.max(x)).clip(-64.0)
shiftx = x - np.max(x)
exps = np.exp(shiftx)
return exps / np.sum(exps)

Expand Down Expand Up @@ -131,13 +131,13 @@ def check_with_place(
# get input data for rank 0
np.random.seed(pid0)
input0 = np.random.uniform(
low=-10.0, high=10.0, size=(self.batch_size, local_elements)
low=-40.0, high=40.0, size=(self.batch_size, local_elements)
).astype(np_data_type)

# get input data for rank 1
np.random.seed(pid1)
input1 = np.random.uniform(
low=-10.0, high=10.0, size=(self.batch_size, local_elements)
low=-40.0, high=40.0, size=(self.batch_size, local_elements)
).astype(np_data_type)

# get combined input data
Expand Down