From ae31faaa877ef2c697123add87136b27a8d1410a Mon Sep 17 00:00:00 2001 From: chengduo <30176695+chengduoZH@users.noreply.github.com> Date: Fri, 20 Sep 2019 16:39:12 +0800 Subject: [PATCH] refine optimier function (#19886) test=developt --- python/paddle/fluid/optimizer.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/paddle/fluid/optimizer.py b/python/paddle/fluid/optimizer.py index f7db8ce32b3..e33f5c13be5 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) -- GitLab