未验证 提交 5b3d33bd 编写于 作者: J Jiabin Yang 提交者: GitHub

test=release/1.5, fix problem that get_attr method can't using default mode...

test=release/1.5, fix problem that get_attr method can't using default mode when we call has_attr in dygraph (#19328) (#19414)

* add default getItem

* test=develop, fix has_attr disabled error in Layer

* test=develop, fix GroupNorm and deepcf bug on attrs
上级 07e7ebeb
......@@ -212,6 +212,8 @@ class Layer(core.Layer):
return self._parameters[name]
elif name in self._sub_layers:
return self._sub_layers[name]
else:
return object.__getattribute__(self, name)
def __setattr__(self, name, value):
if isinstance(value, framework.Parameter):
......
......@@ -2403,9 +2403,9 @@ class GroupNorm(layers.Layer):
def forward(self, input):
inputs = {'X': input}
if self._bias:
if self._bias_attr:
inputs['Bias'] = self._bias
if self._scale:
if self._param_attr:
inputs['Scale'] = self._scale
# create output
......
......@@ -405,6 +405,13 @@ class TestImperative(unittest.TestCase):
self.assertTrue(np.allclose(dy_grad_h2h2, static_grad_h2h))
self.assertTrue(np.allclose(dy_grad_i2h2, static_grad_i2h))
def test_layer_attrs(self):
layer = fluid.dygraph.Layer("test")
layer.test_attr = 1
self.assertFalse(hasattr(layer, "whatever"))
self.assertTrue(hasattr(layer, "test_attr"))
self.assertEqual(layer.test_attr, 1)
if __name__ == '__main__':
unittest.main()
......@@ -73,7 +73,6 @@ class MLP(fluid.Layer):
self.add_sublayer(
'match_layer_%d' % i,
fluid.FC(self.full_name(), self._hid_sizes[i], act='relu')))
self._mat
def forward(self, users, items):
users = self._user_latent(users)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册