未验证 提交 e362095e 编写于 作者: H hong 提交者: GitHub

fix softmax with cross entropy out of bound; test=develop (#25549)

上级 d8fe517b
......@@ -27,9 +27,11 @@ __global__ void CrossEntropyGrad(T* logit_grad, const int64_t* labels,
CUDA_KERNEL_LOOP(index, n * remain) {
int idx_n = index / remain;
int idx_remain = index % remain;
int idx = idx_n * d + labels[index] * remain + idx_remain;
logit_grad[idx] -=
ignore_index == labels[index] ? static_cast<T>(0.) : static_cast<T>(1.);
int tmp = labels[index];
if (ignore_index != tmp) {
int idx = idx_n * d + tmp * remain + idx_remain;
logit_grad[idx] -= static_cast<T>(1.);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册