Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

Wrong shared weight in fc layer when input is a sequence and the parameter name is manually set

Open will-am opened this issue 9 years ago • 0 comments

Code:

import paddle.v2 as paddle

x1 = paddle.layer.data(name='x1', type=paddle.data_type.dense_vector(3))
x2 = paddle.layer.data(name='x2', type=paddle.data_type.dense_vector(2))

fc = paddle.layer.fc(input=[x1, x2],
                     size=1, 
                     param_attr=paddle.attr.Param(name="w", initial_mean=1.0, initial_std=0.0))

Error message:

Shared parameter "w" does not have same size: 3 vs. 2

This happens because the python wrapper applies the same param_attr to x1 and x2 when the parameter name is manually set. The python wrapper does not check this. This may cause unexpected sharing of weights between x1 and x2. For example, if the dimension of both x1 and x2 is 3, the above code would not raise exception and x1, x2 would share the same weights, which may not be the expect of users.

will-am avatar Sep 26 '17 07:09 will-am