Skip to content

Clean cross entropy #10280

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

Merged

Conversation

reyoung
Copy link
Collaborator

@reyoung reyoung commented Apr 28, 2018

Unify cross entropy CPU and GPU kernel by platform::ForRange functor. It reduce the lines of code of cross_entropy_op

@reyoung reyoung changed the title Feature/add stable test of cross entropy Clean cross entropy Apr 28, 2018
: dx_(dx), dy_(dy), x_(x), label_(label), num_classes_(num_classes) {}

HOSTDEVICE void operator()(size_t label_id) {
auto x_is_true_offset = label_id * num_classes_ + label_[label_id];
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe label_id is not exact, sample_id may be better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

dx_[x_offset] = x_offset != x_is_true_offset
? static_cast<T>(0)
: -dy_[label_id] / x_[x_offset];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer to write like this:

auto x_is_true_offset = label_id * num_classes_ + label_[label_id];
dx_[x_is_true_offset] = -dy_[label_id] / x_[x_is_true_offset]

and put setting dx_ to zero in here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is slower to use two kernels than one kernel.

reyoung added 3 commits May 2, 2018 17:45
… feature/add_stable_test_of_cross_entropy
…:reyoung/Paddle into feature/add_stable_test_of_cross_entropy
Copy link
Contributor

@chengduoZH chengduoZH left a comment

Choose a reason for hiding this comment

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

Excellent!

@reyoung reyoung merged commit 8a0c7e2 into PaddlePaddle:develop May 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants