Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions python/paddle/fluid/dygraph/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,12 @@ def _build_once(self, input):
self._img_filter = self.create_parameter(
dtype=input.dtype, shape=filter_shape, attr=self._param_attr)

self._bias_param = self.create_parameter(
attr=self._bias_attr,
shape=[self._num_filters],
dtype=self._dtype,
is_bias=True)

def forward(self, input):
pre_bias = self._helper.create_variable_for_type_inference(
dtype=input.dtype)
Expand All @@ -2179,7 +2185,18 @@ def forward(self, input):
'use_cudnn': self._use_cudnn
})

pre_act = self._helper.append_bias_op(pre_bias, dim_start=1, dim_end=2)
if self._bias_param is not None:
pre_act = self._helper.create_variable_for_type_inference(
dtype=self._dtype)
self._helper.append_op(
type='elementwise_add',
inputs={'X': [pre_bias],
'Y': [self._bias_param]},
outputs={'Out': [pre_act]},
attrs={'axis': 1})
else:
pre_act = pre_bias

out = self._helper.append_activation(pre_act)
return out

Expand Down Expand Up @@ -2237,6 +2254,12 @@ def _build_once(self, input):
self._filter_param = self.create_parameter(
attr=self._param_attr, shape=filter_shape, dtype=self._dtype)

self._bias_param = self.create_parameter(
attr=self._bias_attr,
shape=[self._num_filters],
dtype=self._dtype,
is_bias=True)

def forward(self, input):
pre_bias = self._helper.create_variable_for_type_inference(self._dtype)
self._helper.append_op(
Expand All @@ -2251,7 +2274,19 @@ def forward(self, input):
'contextStart': -int(self._filter_size // 2),
'contextLength': self._filter_size
})
pre_act = self._helper.append_bias_op(pre_bias)

if self._bias_param is not None:
pre_act = self._helper.create_variable_for_type_inference(
dtype=self._dtype)
self._helper.append_op(
type='elementwise_add',
inputs={'X': [pre_bias],
'Y': [self._bias_param]},
outputs={'Out': [pre_act]},
attrs={'axis': 1})
else:
pre_act = pre_bias

return self._helper.append_activation(pre_act)


Expand Down Expand Up @@ -2614,6 +2649,7 @@ def forward(self, nodes_vector, edge_set):
out = self.create_variable(
name=self._name, dtype=self._dtype, persistable=False)
else:

out = self._helper.create_variable_for_type_inference(
dtype=self._dtype)

Expand Down