mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-24 19:43:35 +00:00
Prevent divide by zero in CUDA implementation of SoftmaxCrossEntropyLossGrad. (#3962)
This commit is contained in:
parent
132ce3a561
commit
a296b16719
1 changed files with 10 additions and 2 deletions
|
|
@ -117,7 +117,11 @@ __global__ void _WeightedSoftmaxCrossEntropyLossGrad(
|
|||
int row = i / C;
|
||||
int d = i % C;
|
||||
CUDA_KERNEL_ASSERT(weight[row] == 0 || (label[row] >= 0 && label[row] < C));
|
||||
output_data[i] = (*dY) * weight[row] * (_Exp(log_prob[i]) - 1.0 * (d == label[row])) / (*normalize_factor);
|
||||
if(0 == *normalize_factor){
|
||||
output_data[i] = 0;
|
||||
} else {
|
||||
output_data[i] = (*dY) * weight[row] * (_Exp(log_prob[i]) - 1.0 * (d == label[row])) / (*normalize_factor);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename Tin>
|
||||
|
|
@ -135,7 +139,11 @@ __global__ void _WeightedReductionNoneSoftmaxCrossEntropyLossGrad(
|
|||
int row = i / C;
|
||||
int d = i % C;
|
||||
CUDA_KERNEL_ASSERT(weight[row] == 0 || (label[row] >= 0 && label[row] < C));
|
||||
output_data[i] = dY[row] * weight[row] * (_Exp(log_prob[i]) - 1.0 * (d == label[row])) / (*normalize_factor);
|
||||
if(0 == *normalize_factor){
|
||||
output_data[i] = 0;
|
||||
} else {
|
||||
output_data[i] = dY[row] * weight[row] * (_Exp(log_prob[i]) - 1.0 * (d == label[row])) / (*normalize_factor);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename Tin>
|
||||
|
|
|
|||
Loading…
Reference in a new issue