Skip to content

Commit

Permalink
make adding eps more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyaming authored and pkuyym committed Jul 5, 2017
1 parent 7ed6463 commit 2bf4f1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions paddle/gserver/layers/CrossChannelNormLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ void CrossChannelNormLayer::forward(PassType passType) {
Matrix::resizeOrCreate(dataBuffer_, batchSize, dataDim, false, useGpu_);
Matrix::resizeOrCreate(spatialBuffer_, 1, spatialDim, false, useGpu_);
Matrix::resizeOrCreate(normBuffer_, batchSize, spatialDim, false, useGpu_);
normBuffer_->zeroMem();
// add eps to avoid overflow
normBuffer_->addScalar(*normBuffer_, 1e-6);

inV->square2(*dataBuffer_);
for (size_t i = 0; i < batchSize; i++) {
const MatrixPtr inVTmp = createSampleMatrix(inV, i, spatialDim);
Expand All @@ -73,7 +71,8 @@ void CrossChannelNormLayer::forward(PassType passType) {

// compute norm.
spatialBuffer_->sumCols(*dataTmp, 1, 0);
spatialBuffer_->add(*normTmp);
// add eps to avoid overflow
spatialBuffer_->add(1e-6);
spatialBuffer_->sqrt2(*spatialBuffer_);
normTmp->copyFrom(*spatialBuffer_);
outVTmp->copyFrom(*inVTmp);
Expand Down
4 changes: 2 additions & 2 deletions paddle/gserver/tests/LayerGradUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ struct TestConfig {
bool testBatchState;
TestConfig()
: biasSize(0),
paramInitialMean(0),
paramInitialStd(1),
paramInitialMean(0.0),
paramInitialStd(1.0),
hasParamInitialValue(false),
testAccumulate(true),
testState(false),
Expand Down

0 comments on commit 2bf4f1b

Please sign in to comment.