From 0879cfef5689a2edf0ab0f5ded9edb83cd8787be Mon Sep 17 00:00:00 2001 From: yzhang87 Date: Mon, 19 Jan 2015 16:30:25 -0500 Subject: [PATCH] Fix the bug for MEL when adding a recurrent loop. --- MachineLearning/cn/ComputationNetwork.h | 8 ++++++++ MachineLearning/cn/ComputationNode.h | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/MachineLearning/cn/ComputationNetwork.h b/MachineLearning/cn/ComputationNetwork.h index 524e8a1da..65534e5de 100644 --- a/MachineLearning/cn/ComputationNetwork.h +++ b/MachineLearning/cn/ComputationNetwork.h @@ -1843,6 +1843,13 @@ namespace Microsoft { namespace MSR { namespace CNTK { void ClearCalcOrderCaches() { + for (std::map>::iterator it = m_cacheEvalOrders.begin(); it != m_cacheEvalOrders.end(); ++it) + { + for (auto iter2 = m_cacheEvalOrders[it->first].begin(); iter2 != m_cacheEvalOrders[it->first].end(); iter2++) + { + (*iter2)->clearCache(); + } + } m_cacheEvalOrders.clear(); m_cacheGradientCalcOrders.clear(); } @@ -2043,6 +2050,7 @@ namespace Microsoft { namespace MSR { namespace CNTK { void FormRecurentLoops(const ComputationNodePtr rootNode) { std::vector sourceLoopNodes; + getStrongSCC(rootNode); std::list& nodes = GetEvalOrder(rootNode, sourceLoopNodes); std::list nodesForGrad; diff --git a/MachineLearning/cn/ComputationNode.h b/MachineLearning/cn/ComputationNode.h index a3b577b46..7ec090964 100644 --- a/MachineLearning/cn/ComputationNode.h +++ b/MachineLearning/cn/ComputationNode.h @@ -237,6 +237,16 @@ namespace Microsoft { namespace MSR { namespace CNTK { m_indexInLoop = index; } + void clearCache() + { + m_loopId = -1; + m_visitedOrder = -1; + m_index = -1; + m_lowlink = -1; + m_indexInLoop = 0; + m_visited = false; + m_inStack = false; + } size_t GetIndex() { return m_index;