Skip to content

Commit

Permalink
[FIx bug]layer to 'NoneType' object has no attribute 'place' (PaddleP…
Browse files Browse the repository at this point in the history
…addle#43597)

* refine layer to

* refine code

* add ut
  • Loading branch information
zhangbo9674 authored and sneaxiy committed Jun 27, 2022
1 parent 3697ed7 commit 713fb7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/paddle/fluid/dygraph/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,8 @@ def _apply(self, func, device, dtype, blocking, include_sublayers=True):
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

Expand Down
9 changes: 9 additions & 0 deletions python/paddle/fluid/tests/unittests/test_base_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,16 +559,25 @@ def func_test_to_api_numpy_dtype(self):
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__':
Expand Down

0 comments on commit 713fb7d

Please sign in to comment.