From 07cd98e3c3354f283ec1e71d79e47b0c35ffb8d5 Mon Sep 17 00:00:00 2001 From: HydrogenSulfate <490868991@qq.com> Date: Wed, 6 Nov 2024 13:34:54 +0800 Subject: [PATCH] use paddle Tensor instead of numpy array in pd/test_auto_batch_size.py to coverage newly added code --- source/tests/pd/test_auto_batch_size.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/source/tests/pd/test_auto_batch_size.py b/source/tests/pd/test_auto_batch_size.py index 1033f46d07..966333f47c 100644 --- a/source/tests/pd/test_auto_batch_size.py +++ b/source/tests/pd/test_auto_batch_size.py @@ -2,6 +2,7 @@ import unittest import numpy as np +import paddle from deepmd.pd.utils.auto_batch_size import ( AutoBatchSize, @@ -10,28 +11,28 @@ class TestAutoBatchSize(unittest.TestCase): def test_execute_all(self): - dd0 = np.zeros((10000, 2, 1, 3, 4)) - dd1 = np.ones((10000, 2, 1, 3, 4)) + dd0 = paddle.zeros((10000, 2, 1, 3, 4)) + dd1 = paddle.ones((10000, 2, 1, 3, 4)) auto_batch_size = AutoBatchSize(256, 2.0) def func(dd1): - return np.zeros_like(dd1), np.ones_like(dd1) + return paddle.zeros_like(dd1), paddle.ones_like(dd1) dd2 = auto_batch_size.execute_all(func, 10000, 2, dd1) - np.testing.assert_equal(dd0, dd2[0]) - np.testing.assert_equal(dd1, dd2[1]) + np.testing.assert_equal(dd0.numpy(), dd2[0].numpy()) + np.testing.assert_equal(dd1.numpy(), dd2[1].numpy()) def test_execute_all_dict(self): - dd0 = np.zeros((10000, 2, 1, 3, 4)) - dd1 = np.ones((10000, 2, 1, 3, 4)) + dd0 = paddle.zeros((10000, 2, 1, 3, 4)) + dd1 = paddle.ones((10000, 2, 1, 3, 4)) auto_batch_size = AutoBatchSize(256, 2.0) def func(dd1): return { - "foo": np.zeros_like(dd1), - "bar": np.ones_like(dd1), + "foo": paddle.zeros_like(dd1), + "bar": paddle.ones_like(dd1), } dd2 = auto_batch_size.execute_all(func, 10000, 2, dd1) - np.testing.assert_equal(dd0, dd2["foo"]) - np.testing.assert_equal(dd1, dd2["bar"]) + np.testing.assert_equal(dd0.numpy(), dd2["foo"].numpy()) + np.testing.assert_equal(dd1.numpy(), dd2["bar"].numpy())