dygraph模式下,fluid.gradients 报错
Created by: lyp2github
为使您的问题得到快速解决,在建立Issue前,请您先通过如下方式搜索是否有相似问题:【搜索issue关键字】【使用labels筛选】【官方文档】
建立issue时,为快速解决问题,请您根据使用情况给出如下信息:
- 标题:dygraph模式下,fluid.gradients 报错
- 版本、环境信息: 1)PaddlePaddle版本:1.6.1.post97 GPU版本 3)GPU:Tesla P40 cuDNN Version: 7.0, 4)系统环境:CentOS release 6.3 (Final),Python3.6, 2018 x86_64 x86_64 x86_64 GNU/Linux
- 模型信息 #!/usr/bin/env python #-- coding=utf8 -- import paddle.fluid as fluid import numpy as np
if name == 'main': with fluid.dygraph.guard(): rng = np.random.RandomState(0) inp_ = rng.uniform(-1, 1, [3, 2]).astype('float32') w1_ = rng.uniform(-1, 1, [2, 5]).astype('float32') w2_ = rng.uniform(-1, 1, [5, 4]).astype('float32') inp = fluid.dygraph.base.to_variable(inp_) w1 = fluid.dygraph.base.to_variable(w1_) w2 = fluid.dygraph.base.to_variable(w2_) inp.stop_gradient = False w1.stop_gradient = False w2.stop_gradient = False y = fluid.layers.mul(fluid.layers.mul(inp, w1), w2) x = [w1, w2] dfdx_f1 =fluid.gradients(y, x) print(dfdx_f1)
#######################
Traceback (most recent call last):
File "test_torch_dygraph.py", line 51, in
test_mul_grad_paddle_vs_torch()
File "test_torch_dygraph.py", line 37, in test_mul_grad_paddle_vs_torch
dfdx_f1 =fluid.gradients(f, x)
File "/home/users/liuyaping/local/python36/lib/python3.6/site-packages/paddle/fluid/backward.py", line 1350, in gradients
outs = calc_gradient(targets, inputs, target_gradients, no_grad_set)
File "/home/users/liuyaping/local/python36/lib/python3.6/site-packages/paddle/fluid/backward.py", line 1299, in calc_gradient
prog._sync_with_cpp()
File "/home/users/liuyaping/local/python36/lib/python3.6/site-packages/paddle/fluid/framework.py", line 4345, in _sync_with_cpp
block._sync_with_cpp()
File "/home/users/liuyaping/local/python36/lib/python3.6/site-packages/paddle/fluid/framework.py", line 2579, in _sync_with_cpp
op = Operator(self, op_desc)
File "/home/users/liuyaping/local/python36/lib/python3.6/site-packages/paddle/fluid/framework.py", line 1721, in init
"type
to initialized an Operator can not be None.")
ValueError: type
to initialized an Operator can not be None.