Layers.gaussian_random/Layers.gaussian_random_batch_size_like当std参数是一个variable时,会产生很奇怪的报错
Created by: WorldEditors
Fluid 1.6版本, CPU/GPU均可稳定复现 gaussian_random/gaussian_random_batch_size_like两个函数中,如果std是一个variable,会产生如下错误。
Traceback (most recent call last): File "test.py", line 9, in out = fluid.layers.gaussian_random_batch_size_like(x, shape=[-1,2], mean=0.0, std=y, seed=0, dtype='float32') File "/home/yobobobo/tools/miniconda2/envs/wf_env/lib/python3.5/site-packages/paddle/fluid/layers/nn.py", line 13384, in gaussian_random_batch_size_like 'dtype': c_dtype File "/home/yobobobo/tools/miniconda2/envs/wf_env/lib/python3.5/site-packages/paddle/fluid/layer_helper.py", line 43, in append_op return self.main_program.current_block().append_op(*args, **kwargs) File "/home/yobobobo/tools/miniconda2/envs/wf_env/lib/python3.5/site-packages/paddle/fluid/framework.py", line 2459, in append_op attrs=kwargs.get("attrs", None)) File "/home/yobobobo/tools/miniconda2/envs/wf_env/lib/python3.5/site-packages/paddle/fluid/framework.py", line 1837, in init self._update_desc_attr(attr_name, attr_val) File "/home/yobobobo/tools/miniconda2/envs/wf_env/lib/python3.5/site-packages/paddle/fluid/framework.py", line 2012, in _update_desc_attr self.desc._set_attr(name, val) ValueError: vector::reserve
复现代码如下
import paddle
import paddle.fluid as fluid
import numpy as np
x = fluid.layers.data(name='x', shape=[-1,2], append_batch_size=False, lod_level=1, dtype='float32')
y = fluid.layers.data(name='y', shape=[], append_batch_size=False, dtype='float32')
out = fluid.layers.gaussian_random_batch_size_like(x, shape=[-1,2], mean=0.0, std=y, seed=0, dtype='float32')
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
x_d = fluid.create_lod_tensor(np.array([[1, 1], [2, 2],[3, 3],[4, 4]]).astype('float32'), [[1,2,1]], place)
results = exe.run(fluid.default_main_program(), feed={'x':x_d, 'y':1.0}, fetch_list=[out],return_numpy=False)
print("The data of the result: {}.".format(results[0]))
虽然这里将std设为variable实际不被允许,但报错的方式比较奇怪,会造成很大的confuse