动态图提取中间变量计算loss报错
Created by: sserdoubleh
- 版本、环境信息: 1)PaddlePaddle版本:1.5.1 2)CPU:Y 3)GPU:N 4)系统环境:请您描述系统类型、版本,例如Mac OS 10.14,Python版本
- 训练信息 1)单机单卡 2)显存信息:X 3)Operator信息
- 复现信息: 复现代码
import paddle.fluid as fluid import paddle.fluid.layers as layers import paddle.fluid.dygraph as dygraph import numpy as np place = fluid.CPUPlace() with dygraph.guard(place): x = np.random.randn(2, 4, 5).astype("float32") x = dygraph.to_variable(x) fc1 = dygraph.FC("fc1", 10, num_flatten_dims=2) fc2 = dygraph.FC("fc2", 10, num_flatten_dims=2) y = fc1(x[:, :2]) z = fc2(x[:, 2:]) loss = layers.reduce_mean(y) optimizer = fluid.optimizer.AdamOptimizer() loss.backward() optimizer.minimize(loss) fc1.clear_gradients() fc2.clear_gradients()
报错 paddle.fluid.core_avx.EnforceNotMet: holder_ should not be null Tensor not initialized yet when Tensor::place() is called. at [/paddle/paddle/fluid/framework/tensor.h:133]
- 问题描述: 对同一个tensor切分成两个走不同的网络,取其中一部分计算loss就会报错 但是把z = fc2(x[:, 2:])注释掉就不会报错了