-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
add cross-entropy-op #2965
add cross-entropy-op #2965
Conversation
… cross-entropy-op
… cross-entropy-op
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
template <typename Place, typename T> | ||
class OnehotCrossEntropyOpKernel : public framework::OpKernel { | ||
public: | ||
constexpr T LOG_THRESHOLD() const { return static_cast<T>(1e-20); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be easier to have constant instead of a function here?
I tried the following program builds and runs:
#include <iostream>
template <typename T>
struct Hello {
const T kThreshold = static_cast<T>(1e-20);
};
int main() {
Hello<float> h;
std::cout << h.kThreshold << "\n";
return 0;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constexpr可以实现编译时求值,没有了运行时调用的开销,是觉得这个使用方法不够直接么?
int batch_size = X.dims()[0]; | ||
int class_num = X.dims()[1]; | ||
|
||
// Y[i] = -log(X[i][j]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the code if it is unnecessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the formula for onehot-cross-entropy, I put it here to help readers get an easier understanding of the following computation logic. May be I should write with more detail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -48,6 +48,7 @@ op_library(mul_op SRCS mul_op.cc mul_op.cu) | |||
op_library(rowwise_add_op SRCS rowwise_add_op.cu rowwise_add_op.cc) | |||
op_library(sigmoid_op SRCS sigmoid_op.cu sigmoid_op.cc) | |||
op_library(softmax_op SRCS softmax_op.cc softmax_op.cu) | |||
op_library(cross_entropy_op SRCS cross_entropy_op.cc cross_entropy_op.cu) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
和这个PR无关,请问现在的CMakeLists必须一行行手写么?不能对这个目录下的文件进行自动编译么? @gangliao
No description provided.