diff --git a/python/paddle/fluid/tests/unittests/test_base_layer.py b/python/paddle/fluid/tests/unittests/test_base_layer.py index bb5c691a6e074..dbfb1844fb0c0 100644 --- a/python/paddle/fluid/tests/unittests/test_base_layer.py +++ b/python/paddle/fluid/tests/unittests/test_base_layer.py @@ -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__':