Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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