Skip to content

Commit

Permalink
fix a bug in CrossEntropyNode where m_leftDivRight is used without
Browse files Browse the repository at this point in the history
allocation.
  • Loading branch information
zhouwangzw committed Oct 3, 2016
1 parent 1b38d9f commit b019f33
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Source/ComputationNetworkLib/TrainingNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ class CrossEntropyNode : public ComputationNodeNonLooping /*ComputationNode*/<El
}
else
{
// Resize m_lefDivRight as it has not been done before.
m_leftDivRight->Resize(InputRef(1).Value());
BackpropToRight(*m_leftDivRight, InputRef(0).ValueFor(fr), InputRef(1).ValueFor(fr), InputRef(1).GradientFor(fr), Gradient());
}
}
Expand Down Expand Up @@ -285,8 +287,8 @@ class CrossEntropyNode : public ComputationNodeNonLooping /*ComputationNode*/<El

virtual void UpdateFunctionMBSize() override
{
// Delay resize of m_leftDivRight to backprop, as it is not allocated for forwardprop.
m_logOfRight->Resize(InputRef(1).Value());
m_leftDivRight->Resize(InputRef(1).Value());
}

// -sum(left_i * log(right_i))
Expand Down Expand Up @@ -315,7 +317,10 @@ class CrossEntropyNode : public ComputationNodeNonLooping /*ComputationNode*/<El
{
auto node = dynamic_pointer_cast<CrossEntropyNode<ElemType>>(nodeP);
node->m_logOfRight->SetValue(*m_logOfRight);
node->m_leftDivRight->SetValue(*m_leftDivRight);
if (m_leftDivRight != nullptr)
{
node->m_leftDivRight->SetValue(*m_leftDivRight);
}
}
}

Expand Down

0 comments on commit b019f33

Please sign in to comment.