提交 7a42c92d 编写于 作者: C caoying03

fix a bug that memory does not clean.

上级 74d3ca8b
...@@ -53,8 +53,8 @@ size_t CostForOneSequence::initLastExpansion() { ...@@ -53,8 +53,8 @@ size_t CostForOneSequence::initLastExpansion() {
candidates->getData() + height * beamSize_, candidates->getData() + height * beamSize_,
[](const real& val) { return val != -1; }); [](const real& val) { return val != -1; });
/* /*
* if the gold sequence falls off the beam during search, * if the gold sequence falls off the beam during search, add the gold
* add the gold sequence as the last path into all expanded paths. * sequence as the last path into the all expanded candidates.
*/ */
if (goldAsExtraPath_) goldIdsInFinalExpansion_ = pathCount++; if (goldAsExtraPath_) goldIdsInFinalExpansion_ = pathCount++;
...@@ -133,7 +133,7 @@ real CostForOneSequence::globallyNormalizedScore() { ...@@ -133,7 +133,7 @@ real CostForOneSequence::globallyNormalizedScore() {
Matrix::resizeOrCreate( Matrix::resizeOrCreate(
softmaxOut_, 1, pathRowIdsInEachBeam_[0].size(), false, false); softmaxOut_, 1, pathRowIdsInEachBeam_[0].size(), false, false);
softmaxOut_->zero(); softmaxOut_->zeroMem();
MatrixPtr tmp = Matrix::create( MatrixPtr tmp = Matrix::create(
softmaxOut_->getData(), softmaxOut_->getWidth(), 1, false, false); softmaxOut_->getData(), softmaxOut_->getWidth(), 1, false, false);
...@@ -143,6 +143,8 @@ real CostForOneSequence::globallyNormalizedScore() { ...@@ -143,6 +143,8 @@ real CostForOneSequence::globallyNormalizedScore() {
1, 1,
false, false,
false); false);
expandedPathScores_[i]->zeroMem();
IVectorPtr rowIds = IVector::create(pathRowIdsInEachBeam_[i].data(), IVectorPtr rowIds = IVector::create(pathRowIdsInEachBeam_[i].data(),
pathRowIdsInEachBeam_[i].size(), pathRowIdsInEachBeam_[i].size(),
false); false);
...@@ -217,13 +219,16 @@ void CrossEntropyOverBeam::checkInputs() { ...@@ -217,13 +219,16 @@ void CrossEntropyOverBeam::checkInputs() {
const Argument& goldSeq = getInput(i * 3 + 2); const Argument& goldSeq = getInput(i * 3 + 2);
if (i) { if (i) {
CHECK(scores.hasSubseq()) << "Beam expansion expect the first one, " CHECK(scores.hasSubseq()) << "input " << i << " "
"should be a nested sequence"; << inputLayers_[i * 3]->getName()
<< " should be a nested sequence";
CHECK_EQ(getInputValue(i * 3 + 1)->getWidth(), beamSize_); CHECK_EQ(getInputValue(i * 3 + 1)->getWidth(), beamSize_);
CHECK_EQ(scores.getNumSequences(), batchSize_); CHECK_EQ(scores.getNumSequences(), batchSize_);
CHECK_EQ(scores.getNumSubSequences(), selCandidates.getBatchSize()); CHECK_EQ(scores.getNumSubSequences(), selCandidates.getBatchSize());
} else { } else {
CHECK(scores.hasSeq()) << "The first beam expansion should be a sequence"; CHECK(scores.hasSeq()) << "input " << i << " "
<< inputLayers_[i]->getName()
<< " should be a sequence";
batchSize_ = scores.getNumSequences(); batchSize_ = scores.getNumSequences();
beamSize_ = getInputValue(i * 3 + 1)->getWidth(); beamSize_ = getInputValue(i * 3 + 1)->getWidth();
CHECK_EQ(batchSize_, selCandidates.getBatchSize()); CHECK_EQ(batchSize_, selCandidates.getBatchSize());
...@@ -332,7 +337,7 @@ void CrossEntropyOverBeam::splitBatchBeams() { ...@@ -332,7 +337,7 @@ void CrossEntropyOverBeam::splitBatchBeams() {
void CrossEntropyOverBeam::resizeOutput() { void CrossEntropyOverBeam::resizeOutput() {
Matrix::resizeOrCreate(output_.value, batchSize_, 1, false, false); Matrix::resizeOrCreate(output_.value, batchSize_, 1, false, false);
output_.value->zero(); output_.value->zeroMem();
for (size_t i = 0; i < beamExpanCount_; ++i) { for (size_t i = 0; i < beamExpanCount_; ++i) {
MatrixPtr inGrad = getInputGrad(i * 3); MatrixPtr inGrad = getInputGrad(i * 3);
...@@ -344,7 +349,7 @@ void CrossEntropyOverBeam::resizeOutput() { ...@@ -344,7 +349,7 @@ void CrossEntropyOverBeam::resizeOutput() {
false); false);
} else } else
candidateScoreGrad_[i] = std::move(inGrad); candidateScoreGrad_[i] = std::move(inGrad);
candidateScoreGrad_[i]->zero(); candidateScoreGrad_[i]->zeroMem();
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册