未验证 提交 fc177d25 编写于 作者: L lijialin03 提交者: GitHub

update LBFGS to adapt to 0D tensor (#55825)

上级 8fc2366c
...@@ -523,7 +523,7 @@ class LBFGS(Optimizer): ...@@ -523,7 +523,7 @@ class LBFGS(Optimizer):
def _add_grad(self, alpha, direction): def _add_grad(self, alpha, direction):
offset = 0 offset = 0
for p in self._params: for p in self._params:
numel = reduce(lambda x, y: x * y, p.shape) numel = reduce(lambda x, y: x * y, p.shape) if p.shape != [] else 1
p = paddle.assign( p = paddle.assign(
p.add( p.add(
direction[offset : offset + numel].reshape(p.shape) * alpha direction[offset : offset + numel].reshape(p.shape) * alpha
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册