From 4676f03cbb77563dcdbd09fa8caf25d4b22d4464 Mon Sep 17 00:00:00 2001 From: LielinJiang <50691816+LielinJiang@users.noreply.github.com> Date: Mon, 12 Oct 2020 10:57:53 +0800 Subject: [PATCH] fix summary (#27820) --- python/paddle/hapi/model_summary.py | 2 +- python/paddle/tests/test_model.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/python/paddle/hapi/model_summary.py b/python/paddle/hapi/model_summary.py index c46a53e910d..30b22a2f32c 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 96c4483a35b..8cd5e172aa0 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) -- GitLab