Paddle版本 1.8.4(在本地还有aistudio上都进行过尝试,均报错),使用cpu训练,单机单卡,在将一个LoDTensor传入Linear层的时候出现报错:
x type and shape: VarType.LOD_TENSOR VarType.FP32 [56, 25733]
Traceback (most recent call last):
File "paddle_demo.py", line 75, in
patience=config['patience']
File "/home/aistudio/work/train_VASC.py", line 282, in vasc
decoded_x,z_mean = model([fluid.dygraph.base.to_variable(expr_train),tau])
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 461, incall
outputs = self.forward(inputs,kwargs)
File "/home/aistudio/work/train_VASC.py", line 86, in forward
x = self.fc1(x)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 461, incall*
outputs = self.forward(*inputs,**kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/nn.py", line 943, in forward
'transpose_Y', False, "alpha", 1)
TypeError: matmul(): incompatible function arguments. The following argument types are supported:
- (arg0: paddle::imperative::VarBase, arg1: paddle::imperative::VarBase, arg2: paddle::imperative::VarBase, *args) -> paddle::imperative::VarBase
Invoked with: <paddle.fluid.core_avx.VarBase object at 0x7f998f973bb0>, name: "linear_0.w_0"
type {
type: LOD_TENSOR
lod_tensor {
tensor {
data_type: FP32
dims: 25733
dims: 512
}
}
}
persistable: true
, <paddle.fluid.core_avx.VarBase object at 0x7f998f973c30>, 'transpose_X', False, 'transpose_Y', False, 'alpha', 1
其中x type是我打印出传入Linear层的datatype,确实是lodtensor。 我在网络上也搜索了一些类似情况的解决方案,提到的都是忘记使用dygraph.to_variable转化输入数据所以出错了,但是这份代码似乎不是因为参数类型的原因。
self.fc1的实现如下:
self.fc1 = Linear(input_dim=self.in_dim,output_dim=512)
是不是因为某些设置或配置的问题?
6条答案
按热度按时间9njqaruj1#
可以将相关代码贴一下吗?log来看确实是参数类型不匹配的问题。
sy5wg1nm2#
然后调用model的时候是这么用的:
decoded_x,z_mean = model([fluid.dygraph.base.to_variable(expr_train),tau])
全部的代码我有在aistudio分享 链接是 https://aistudio.baidu.com/aistudio/projectdetail/1114094?shared=1
进去之后在终端运行python paddle_demo.py就好了 不过我感觉这个bug和剩下部分的代码应该关系不太大?
iyfamqjs3#
这个dropout是静态图的,动态图Dropout参考:https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/dygraph_cn/Dropout_cn.html#dropout
cnjp1d6j4#
好像还是不行..
Traceback (most recent call last):
File "paddle_demo.py", line 75, in
patience=config['patience']
File "/home/aistudio/work/train_VASC.py", line 283, in vasc
decoded_x,z_mean = model([fluid.dygraph.base.to_variable(expr_train),tau])
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 461, incall
outputs = self.forward(inputs,kwargs)
File "/home/aistudio/work/train_VASC.py", line 87, in forward
x = self.fc1(x)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 461, incall*
outputs = self.forward(*inputs,**kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/nn.py", line 943, in forward
'transpose_Y', False, "alpha", 1)
TypeError: matmul(): incompatible function arguments. The following argument types are supported:
Invoked with: <paddle.fluid.core_avx.VarBase object at 0x7f21c9de66b0>, name: "linear_0.w_0"
type {
type: LOD_TENSOR
lod_tensor {
tensor {
data_type: FP32
dims: 25733
dims: 512
}
}
}
persistable: true
, <paddle.fluid.core_avx.VarBase object at 0x7f21c2709670>, 'transpose_X', False, 'transpose_Y', False, 'alpha', 1
b09cbbtk5#
你的代码需要在动态图guard中声明模型。
请参考1.8的文档熟悉一下动态图使用: https://www.paddlepaddle.org.cn/documentation/docs/zh/beginners_guide/basic_concept/dygraph/DyGraph.html
目前动态图还在快速开发阶段,2.0版本发布后才会趋于稳定,所以变动较大。
vhipe2zx6#
好的,我把model的声明挪进guard之后就没有这歌错误了 谢谢1