未验证 提交 0b879318 编写于 作者: Z zhangbo9674 提交者: GitHub

[FIx bug]layer to 'NoneType' object has no attribute 'place' (#43597) (#43717)

bug:
当class Layer的_buffers中有参数为None的时候,调用to()方法将会报layer to 'NoneType' object has no attribute 'place'的错误。
修复方法:
to()方法增加对_buffers中None类型参数的判断,如果为None,跳过该参数的处理。
上级 af415bc2
......@@ -1582,7 +1582,8 @@ class Layer(object):
blocking)
for key, buf in self._buffers.items():
self._buffers[key] = func(buf, device, dtype, blocking)
if buf is not None:
self._buffers[key] = func(buf, device, dtype, blocking)
self._dtype = dtype
......
......@@ -544,16 +544,25 @@ class TestLayerTo(unittest.TestCase):
else:
self.assertTrue(isinstance(p, paddle.fluid.framework.ParamBase))
def func_test_to_api_none_buffer(self):
model = paddle.nn.Linear(2, 4)
buffer = None
model.register_buffer("buf_name", buffer, persistable=True)
model.to(dtype='float64')
self.assertEqual(model._buffers['buf_name'], None)
def test_main(self):
with _test_eager_guard():
self.funcsetUp()
self.func_test_to_api()
self.func_test_to_api_paddle_dtype()
self.func_test_to_api_numpy_dtype()
self.func_test_to_api_none_buffer()
self.funcsetUp()
self.func_test_to_api()
self.func_test_to_api_paddle_dtype()
self.func_test_to_api_numpy_dtype()
self.func_test_to_api_none_buffer()
if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册