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

add cross-entropy-op #2965

Merged
merged 5 commits into from
Jul 21, 2017
Merged

Conversation

jacquesqiao
Copy link
Member

No description provided.

@jacquesqiao jacquesqiao changed the title [WIP] add cross-entropy-op add cross-entropy-op Jul 20, 2017
Copy link
Collaborator

@wangkuiyi wangkuiyi left a 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); }
Copy link
Collaborator

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;
}

Copy link
Member Author

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])
Copy link
Collaborator

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?

Copy link
Member Author

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?

@jacquesqiao jacquesqiao requested review from reyoung and luotao1 July 21, 2017 01:45
Copy link
Contributor

@luotao1 luotao1 left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

和这个PR无关,请问现在的CMakeLists必须一行行手写么?不能对这个目录下的文件进行自动编译么? @gangliao

@jacquesqiao jacquesqiao merged commit 2685765 into PaddlePaddle:develop Jul 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants