|
19 | 19 | import numpy as np
|
20 | 20 | import paddle
|
21 | 21 | import paddle.base as base
|
22 |
| -from tests.op_test import OpTest |
23 |
| -from npu_utils import check_run_big_shape_test |
| 22 | +from tests.op_test import OpTest, convert_float_to_uint16 |
| 23 | +from npu_utils import check_run_big_shape_test, check_soc_version |
24 | 24 |
|
25 | 25 | paddle.enable_static()
|
26 | 26 | SEED = 2021
|
@@ -132,6 +132,45 @@ def config(self):
|
132 | 132 | self.index_type = "int32"
|
133 | 133 |
|
134 | 134 |
|
| 135 | +class TestCase6(TestGatherOp): |
| 136 | + def setUp(self): |
| 137 | + self.set_npu() |
| 138 | + self.place = paddle.CustomPlace("npu", 0) |
| 139 | + self.op_type = "gather" |
| 140 | + self.config() |
| 141 | + xnp = np.random.random(self.x_shape).astype(np.float32) |
| 142 | + self.inputs = { |
| 143 | + "X": convert_float_to_uint16(xnp), |
| 144 | + "Index": np.array(self.index).astype(self.index_type), |
| 145 | + } |
| 146 | + self.outputs = {"Out": convert_float_to_uint16(xnp[self.inputs["Index"]])} |
| 147 | + |
| 148 | + def set_npu(self): |
| 149 | + self.__class__.use_custom_device = True |
| 150 | + |
| 151 | + @check_soc_version |
| 152 | + def test_check_output(self): |
| 153 | + self.check_output_with_place(self.place) |
| 154 | + |
| 155 | + @check_soc_version |
| 156 | + def test_check_grad(self): |
| 157 | + self.check_grad_with_place( |
| 158 | + self.place, |
| 159 | + ["X"], |
| 160 | + "Out", |
| 161 | + max_relative_error=0.006, |
| 162 | + ) |
| 163 | + |
| 164 | + def config(self): |
| 165 | + """ |
| 166 | + For multi-dimension input |
| 167 | + """ |
| 168 | + self.x_shape = (10, 20) |
| 169 | + self.x_type = "bfloat16" |
| 170 | + self.index = [1, 3, 5] |
| 171 | + self.index_type = "int32" |
| 172 | + |
| 173 | + |
135 | 174 | class API_TestGather(unittest.TestCase):
|
136 | 175 | def test_out1(self):
|
137 | 176 | with base.program_guard(base.Program(), base.Program()):
|
|
0 commit comments