diff --git a/paddle/gserver/layers/CrossEntropyOverBeam.cpp b/paddle/gserver/layers/CrossEntropyOverBeam.cpp index bffcc30154370516e8d767f27a1966949a1fc98e..4acc077035b17fdf5ec06e0d4d916fa0a62f6cba 100644 --- a/paddle/gserver/layers/CrossEntropyOverBeam.cpp +++ b/paddle/gserver/layers/CrossEntropyOverBeam.cpp @@ -28,8 +28,9 @@ void CostForOneSequence::calValidExpandStep() { start, start + goldRowIds_[i - 1] * beamSize_ + goldColIds_[i - 1], [](const real& val) { return val != -1.; }); - } else + } else { goldRowIds_[i] = 0; + } real* start = beams_->candidateIds[i]->getData() + goldRowIds_[i] * beamSize_; @@ -288,7 +289,7 @@ void CrossEntropyOverBeam::copyInputsToCpu() { void CrossEntropyOverBeam::splitBatchBeams() { beamCosts_.resize(batchSize_); - beamPerSeq_.resize(batchSize_, beamExpanCount_); + beamPerSeq_.resize(batchSize_, BeamExpansion(beamExpanCount_)); for (size_t i = 0; i < beamExpanCount_; ++i) { int* seqStarts = @@ -300,8 +301,9 @@ void CrossEntropyOverBeam::splitBatchBeams() { subSeqStarts = getInput(i * 3).subSequenceStartPositions->getMutableData(false); maxLen = getInput(i * 3).subSequenceStartPositions->getSize() - 1; - } else + } else { maxLen = getInput(i).sequenceStartPositions->getSize() - 1; + } for (size_t j = 0; j < batchSize_; ++j) { beamPerSeq_[j].scores[i] = @@ -348,8 +350,9 @@ void CrossEntropyOverBeam::resizeOutput() { inGrad->getWidth(), false, false); - } else + } else { candidateScoreGrad_[i] = std::move(inGrad); + } candidateScoreGrad_[i]->zeroMem(); } } diff --git a/paddle/gserver/layers/CrossEntropyOverBeam.h b/paddle/gserver/layers/CrossEntropyOverBeam.h index 5d0cffee3c159702a2d6b96de710553b0ede9f6a..5643556f43370912a730d9895658d8944f50dced 100644 --- a/paddle/gserver/layers/CrossEntropyOverBeam.h +++ b/paddle/gserver/layers/CrossEntropyOverBeam.h @@ -31,7 +31,7 @@ struct BeamExpansion { size_t expansionCount; - BeamExpansion(int n) { + explicit BeamExpansion(int n) { expansionCount = n; scores.resize(expansionCount); seqInfo.resize(expansionCount); @@ -39,7 +39,7 @@ struct BeamExpansion { scoreGrad.resize(expansionCount); gold.resize(expansionCount); - }; + } }; typedef std::shared_ptr BeamExpansionPtr; @@ -74,7 +74,7 @@ private: CHECK_GT(beams_->seqInfo[beamId]->getSize() - 1, rowId); int* starts = beams_->seqInfo[beamId]->getData(); return starts[rowId] - starts[0]; - }; + } size_t beamSize_; size_t validExpansionCount_;