diff --git a/python/paddle/hapi/model.py b/python/paddle/hapi/model.py index 8505544a71f58ea34abfb5edebd5991df1a0cb4f..459d6cd3284e9a5be2a4d9ad08192a6bcc28ef79 100644 --- a/python/paddle/hapi/model.py +++ b/python/paddle/hapi/model.py @@ -638,19 +638,14 @@ class DynamicGraphAdapter(object): if self._nranks > 1: outputs = self.ddp_model.forward(* [to_variable(x) for x in inputs]) - losses = self.model._loss(*(to_list(outputs) + labels)) - losses = to_list(losses) - final_loss = fluid.layers.sum(losses) - final_loss = self.ddp_model.scale_loss(final_loss) - final_loss.backward() - self.ddp_model.apply_collective_grads() else: outputs = self.model.network.forward( * [to_variable(x) for x in inputs]) - losses = self.model._loss(*(to_list(outputs) + labels)) - losses = to_list(losses) - final_loss = fluid.layers.sum(losses) - final_loss.backward() + + losses = self.model._loss(*(to_list(outputs) + labels)) + losses = to_list(losses) + final_loss = fluid.layers.sum(losses) + final_loss.backward() self.model._optimizer.minimize(final_loss) self.model.network.clear_gradients()