diff --git a/paddle/fluid/imperative/layer.cc b/paddle/fluid/imperative/layer.cc index e65ac865b291d7591df08418ebb0144ef2e5f33c..bc03285a4c5fe6db2abf2b271d6ddc86e75a9412 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 32abb03e91f380b667f05154de0f5093647feff9..732f0681c4e65006628d51e083a400c0b5bd3d92 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(