diff --git a/python/paddle/fluid/optimizer.py b/python/paddle/fluid/optimizer.py index f7db8ce32b308566bf751f5d4e0ef4b4d4356930..e33f5c13be5df76b6926c22eea4da36539403f44 100644 --- a/python/paddle/fluid/optimizer.py +++ b/python/paddle/fluid/optimizer.py @@ -491,6 +491,10 @@ class Optimizer(object): else: assert (isinstance(callbacks, list)) program = loss.block.program + assert len(loss.shape) == 1 and loss.shape[0] == 1, \ + "The loss.shape should be (1L,), but the current loss.shape is {}. " \ + "Maybe that you should call fluid.layers.mean to process the current loss.".format( + loss.shape) with program_guard(program, startup_program): params_grads = append_backward(loss, parameter_list, no_grad_set, callbacks)