From 51ca50897a356c65c203fc5e5c3836d00236f740 Mon Sep 17 00:00:00 2001 From: minqiyang Date: Mon, 1 Apr 2019 22:18:40 +0800 Subject: [PATCH] Change the iteration direction in ingrads' map slots test=develop --- paddle/fluid/imperative/layer.cc | 6 +++--- .../fluid/tests/unittests/test_imperative_transformer.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/imperative/layer.cc b/paddle/fluid/imperative/layer.cc index e65ac865b..bc03285a4 100644 --- a/paddle/fluid/imperative/layer.cc +++ b/paddle/fluid/imperative/layer.cc @@ -117,14 +117,14 @@ class Autograd { std::map dep_counts = ComputeDepCounts(var->PreOp()); while (!ready.empty()) { - OpBase* ready_op = ready.back(); - ready.pop_back(); + OpBase* ready_op = ready.front(); + ready.pop_front(); std::map> input_grads = ready_op->ApplyGrad(); for (auto it = input_grads.rbegin(); it != input_grads.rend(); ++it) { const std::vector& ingrads = it->second; - for (int64_t i = ingrads.size() - 1; i >= 0; --i) { + for (size_t i = 0; i < ingrads.size(); ++i) { if (!ingrads[i]) continue; if (ready_op->input_vars_[it->first][i]->IsStopGradient()) { continue; diff --git a/python/paddle/fluid/tests/unittests/test_imperative_transformer.py b/python/paddle/fluid/tests/unittests/test_imperative_transformer.py index 32abb03e9..732f0681c 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_transformer.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_transformer.py @@ -303,7 +303,7 @@ use_py_reader = False sync = False # how many batches we use -batch_num = 2 +batch_num = 50 np.random.seed = 1 src_word_np = np.random.randint( -- GitLab