Skip to content

Commit 7a27667

Browse files
authored
[INTEL_HPU] fix unit test for gather kernel (#1502)
1 parent de248cb commit 7a27667

File tree

1 file changed

+17
-30
lines changed

1 file changed

+17
-30
lines changed

backends/intel_hpu/tests/unittests/test_gather.py

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ def setUp(self):
3939
self.op_type = "gather"
4040
self.config()
4141
xnp = np.random.random(self.x_shape).astype(self.x_type)
42-
self.iintel_hputs = {
42+
self.inputs = {
4343
"X": xnp,
4444
"Index": np.array(self.index).astype(self.index_type),
4545
}
46-
self.outputs = {"Out": self.iintel_hputs["X"][self.iintel_hputs["Index"]]}
46+
self.attrs = {"axis": self.axis}
47+
self.outputs = {"Out": gather_numpy(xnp, self.index, self.axis)}
4748

4849
def set_intel_hpu(self):
4950
self.__class__.use_custom_device = True
@@ -52,43 +53,41 @@ def test_check_output(self):
5253
self.check_output_with_place(self.place)
5354

5455
def test_check_grad(self):
55-
self.check_grad_with_place(
56-
self.place,
57-
["X"],
58-
"Out",
59-
max_relative_error=0.006,
60-
)
56+
pass
6157

6258
def config(self):
6359
"""
64-
For multi-dimension iintel_hput
60+
For multi-dimension input
6561
"""
6662
self.x_shape = (10, 20)
6763
self.x_type = "float32"
6864
self.index = [1, 3, 5]
6965
self.index_type = "int32"
66+
self.axis = 0
7067

7168

7269
class TestCase1(TestGatherOp):
7370
def config(self):
7471
"""
75-
For one dimension iintel_hput
72+
For one dimension input
7673
"""
7774
self.x_shape = 100
7875
self.x_type = "float32"
7976
self.index = [1, 3, 5]
8077
self.index_type = "int32"
78+
self.axis = 0
8179

8280

8381
class TestCase2(TestGatherOp):
8482
def config(self):
8583
"""
86-
For one dimension iintel_hput
84+
For one dimension input
8785
"""
8886
self.x_shape = 100
8987
self.x_type = "int64"
9088
self.index = [1, 3, 5]
9189
self.index_type = "int32"
90+
self.axis = 0
9291

9392
def test_check_grad(self):
9493
pass
@@ -97,40 +96,28 @@ def test_check_grad(self):
9796
class TestCase3(TestGatherOp):
9897
def config(self):
9998
"""
100-
For one dimension iintel_hput
99+
For one dimension input
101100
"""
102101
self.x_shape = 100
103102
self.x_type = "int32"
104103
self.index = [1, 3, 5]
105104
self.index_type = "int32"
105+
self.axis = 0
106106

107107
def test_check_grad(self):
108108
pass
109109

110110

111-
# class TestCase4(TestGatherOp):
112-
# def config(self):
113-
# """
114-
# For one dimension iintel_hput
115-
# """
116-
# self.x_shape = 100
117-
# self.x_type = "bool"
118-
# self.index = [1, 3, 5]
119-
# self.index_type = "int32"
120-
121-
# def test_check_grad(self):
122-
# pass
123-
124-
125-
class TestCase5(TestGatherOp):
111+
class TestCase4(TestGatherOp):
126112
def config(self):
127113
"""
128-
For one dimension iintel_hput
114+
For multi-dimension input
129115
"""
130116
self.x_shape = [4000, 8192]
131117
self.x_type = "float32"
132118
self.index = [1, 3, 5]
133119
self.index_type = "int32"
120+
self.axis = 1
134121

135122

136123
class API_TestGather(unittest.TestCase):
@@ -141,10 +128,10 @@ def test_out1(self):
141128
out = paddle.gather(data1, index)
142129
place = paddle.CustomPlace("intel_hpu", 0)
143130
exe = base.Executor(place)
144-
iintel_hput = np.array([[1, 2], [3, 4], [5, 6]]).astype("float32")
131+
input = np.array([[1, 2], [3, 4], [5, 6]]).astype("float32")
145132
index_1 = np.array([1, 2]).astype("int32")
146133
(result,) = exe.run(
147-
feed={"data1": iintel_hput, "index": index_1}, fetch_list=[out]
134+
feed={"data1": input, "index": index_1}, fetch_list=[out]
148135
)
149136
expected_output = np.array([[3, 4], [5, 6]])
150137
self.assertTrue(np.allclose(result, expected_output))

0 commit comments

Comments
 (0)