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

There is bug in softmax_with_cross_entropy_op backward. #9119

Closed
qingqing01 opened this issue Mar 15, 2018 · 0 comments
Closed

There is bug in softmax_with_cross_entropy_op backward. #9119

qingqing01 opened this issue Mar 15, 2018 · 0 comments
Assignees

Comments

@qingqing01
Copy link
Contributor

Now the code is as follows:

template <typename T>
__global__ void CrossEntropyGrad(T* logit_grad, const T* loss_grad,
                                 const int64_t* labels, const int batch_size,
                                 const int class_num) {
  int tid = blockIdx.x * blockDim.x + threadIdx.x;
  int sample_idx = tid / class_num;

  if (tid < batch_size) {
    PADDLE_ASSERT(labels[sample_idx] >= 0 && labels[sample_idx] < class_num);
    logit_grad[tid * class_num + labels[tid]] -= static_cast<T>(1.);
  }

  __syncthreads();

  if (tid < batch_size * class_num) {
    logit_grad[tid] *= loss_grad[sample_idx];
  }
}

Actually, this code needs a global synchronization, not __syncthreads(), which is a thread barrier in one block.

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

No branches or pull requests

1 participant