diff --git a/python/paddle/hapi/model_summary.py b/python/paddle/hapi/model_summary.py index c46a53e910df079bc9eddc655010084b26f09684..30b22a2f32c34b4a5d71e189cd8f0db55df080c2 100644 --- a/python/paddle/hapi/model_summary.py +++ b/python/paddle/hapi/model_summary.py @@ -254,7 +254,7 @@ def summary_string(model, input_size, dtypes=None): dtype = dtypes[0] else: dtype = dtypes - return paddle.rand(list(input_size), dtype) + return paddle.cast(paddle.rand(list(input_size)), dtype) else: return [ build_input(i, dtype) for i, dtype in zip(input_size, dtypes) diff --git a/python/paddle/tests/test_model.py b/python/paddle/tests/test_model.py index 96c4483a35ba835d34a81b645037da4ed0120f39..8cd5e172aa06a6abada0a2532f02eb220add1c73 100644 --- a/python/paddle/tests/test_model.py +++ b/python/paddle/tests/test_model.py @@ -501,6 +501,11 @@ class TestModelFunction(unittest.TestCase): rnn = paddle.nn.LSTM(16, 32, 2) paddle.summary(rnn, [(-1, 23, 16), ((2, None, 32), (2, -1, 32))]) + def test_summary_dtype(self): + input_shape = (3, 1) + net = paddle.nn.Embedding(10, 3, sparse=True) + paddle.summary(net, input_shape, dtypes='int64') + def test_summary_error(self): with self.assertRaises(TypeError): nlp_net = paddle.nn.GRU(input_size=2, hidden_size=3, num_layers=3)