[Discuss] the expected behavior when bias_attr (type of ParamAttr) set to None
Created by: wangguibao
bias_attr
is a function parameter to convolution layers like sequence_conv, conv2d, conv3d etc.
def conv2d(input,
num_filters,
filter_size,
stride=1,
padding=0,
dilation=1,
groups=None,
param_attr=None,
bias_attr=None,
use_cudnn=True,
use_mkldnn=False,
act=None,
name=None)
According to this issue its acceptable to set bias_attr in a lot of ways, especially when set to True/False it will turn on/off using bias entirely.
Today when one user asked if setting bias_attr
to None
(not True
or False
) will turn off using bias, I checked the source code and find that this will actually not, because the LayerHelper.bias_attr()
method will return a ParamAttr object even if the required key doesn't exist:
attr = ParamAttr._to_attr(self.kwargs.get('bias_attr', None))
The problem is in ParamAttr._to_attr()
, which will create a new ParamAttr object when the argument is None:
if arg is None:
return ParamAttr()
Following this logic, when bias_attr
of conv2d() layer is passed in None
, fluid will add an bias.
I'd ask if this is intended behavior, and if so, please make better documentation on sequence_conv
, conv2d
, conv3d
and other alike layers which use bias_attr
as a parameter. Thanks.