Skip to content
Snippets Groups Projects
Commit 1ab29f55 authored by Olivier BICHLER's avatar Olivier BICHLER
Browse files

Fix FC backward

parent cd824d73
No related branches found
No related tags found
2 merge requests!166Update 0.5.0 -> 0.6.0,!157Fix FC backward
Pipeline #69557 passed
......@@ -136,15 +136,13 @@ void FCImpl_cpu_backward_kernel(const DimSize_t batchSize,
// bias grad
if (biasesGrad == nullptr) { // no bias
std::fill(biasesGrad, biasesGrad + outputFeatureSize, B(0));
} else {
if (biasesGrad != nullptr) {
for (std::size_t o = 0; o < outputFeatureSize; ++o) { // nb outputs
B sum{0};
for (std::size_t b = 0; b < batchSize; ++b) {
sum += input[b*outputFeatureSize + o];
}
biasesGrad[o] = sum;
biasesGrad[o]+= sum;
}
}
......@@ -155,7 +153,7 @@ void FCImpl_cpu_backward_kernel(const DimSize_t batchSize,
for (std::size_t b = 0; b < batchSize; ++b) {
sum += originalInput[b*inputFeatureSize + c]*input[b*outputFeatureSize + o];
}
weightGrad[o*inputFeatureSize + c] = sum;
weightGrad[o*inputFeatureSize + c]+= sum;
}
}
......@@ -166,7 +164,7 @@ void FCImpl_cpu_backward_kernel(const DimSize_t batchSize,
for (std::size_t o = 0; o < outputFeatureSize; ++o) {
sum += weight[o*inputFeatureSize + c] * input[b*outputFeatureSize + o];
}
output[b*inputFeatureSize + c] = sum;
output[b*inputFeatureSize + c]+= sum;
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment