Skip to content

Commit

Permalink
use paddle Tensor instead of numpy array in pd/test_auto_batch_size.p…
Browse files Browse the repository at this point in the history
…y to coverage newly added code
  • Loading branch information
HydrogenSulfate committed Nov 6, 2024
1 parent 39842ff commit 07cd98e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions source/tests/pd/test_auto_batch_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest

import numpy as np
import paddle

from deepmd.pd.utils.auto_batch_size import (
AutoBatchSize,
Expand All @@ -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())

0 comments on commit 07cd98e

Please sign in to comment.