Skip to content

Commit d000b47

Browse files
authored
reduce runtime of unit-tests in windows-trt (#60731)
* modify trt test to deal with Timeout * windows
1 parent 35daff5 commit d000b47

File tree

6 files changed

+55
-202
lines changed

6 files changed

+55
-202
lines changed

test/ir/inference/test_trt_convert_einsum.py

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,12 @@ def sample_program_configs(self):
3636
def generate_input1(dims, batch):
3737
if dims == 1:
3838
return np.ones(shape=[batch]).astype(np.float32)
39-
elif dims == 2:
40-
return np.ones(shape=[batch, 3]).astype(np.float32)
4139
elif dims == 3:
4240
return np.ones((batch, 2, 3)).astype(np.float32)
4341

4442
def generate_equation1(dims):
4543
if dims == 1:
4644
return ["i->"]
47-
elif dims == 2:
48-
# "ij->"
49-
return ["ij->ji", "ij->i", "ij->j"]
5045
elif dims == 3:
5146
# "ijk->","ijk->j","ijk->k"
5247
# error: The current implementation of Einsum doesn't support mask dimensions on multiple contracting/free dimensions
@@ -60,7 +55,7 @@ def generate_equation1(dims):
6055
]
6156

6257
# Single operand: transpose, sum
63-
for dims in [1, 2, 3]:
58+
for dims in [1, 3]:
6459
for batch in [2]:
6560
equation_list = generate_equation1(dims)
6661
for equation in equation_list:
@@ -108,16 +103,7 @@ def generate_dynamic_shape(attrs):
108103
self.dynamic_shape.opt_input_shape = {
109104
"operands_data0": [2],
110105
}
111-
elif self.dims == 2:
112-
self.dynamic_shape.min_input_shape = {
113-
"operands_data0": [1, 3],
114-
}
115-
self.dynamic_shape.max_input_shape = {
116-
"operands_data0": [4, 3],
117-
}
118-
self.dynamic_shape.opt_input_shape = {
119-
"operands_data0": [2, 3],
120-
}
106+
121107
elif self.dims == 3:
122108
self.dynamic_shape.min_input_shape = {
123109
"operands_data0": [1, 2, 3],
@@ -219,18 +205,12 @@ def generate_equation_matrix_vector(dims, vec_shape):
219205
# Doubule operands vector
220206
for dims in [1]:
221207
self.dims = dims
222-
for vec_shape in [[2], [3]]:
208+
for vec_shape in [[2]]:
223209
for batch in [2]:
224210
equation_list = generate_equation_matrix_vector(
225211
dims, vec_shape
226212
)
227213
for equation in equation_list:
228-
if (
229-
dims == 1
230-
and vec_shape != [2]
231-
and equation != "i,j->ij"
232-
) or ((dims == 2 or dims == 3) and vec_shape != [3]):
233-
continue
234214
self.equation = equation
235215
self.dims = dims
236216
dics = [{"equation": equation}, {}]
@@ -286,19 +266,6 @@ def generate_dynamic_shape(attrs):
286266
"operands_data0": [2],
287267
"operands_data1": [2],
288268
}
289-
elif self.dims == 2:
290-
self.dynamic_shape.min_input_shape = {
291-
"operands_data0": [1, 3],
292-
"operands_data1": [1],
293-
}
294-
self.dynamic_shape.max_input_shape = {
295-
"operands_data0": [4, 3],
296-
"operands_data1": [4],
297-
}
298-
self.dynamic_shape.opt_input_shape = {
299-
"operands_data0": [2, 3],
300-
"operands_data1": [3],
301-
}
302269
elif self.dims == 3:
303270
self.dynamic_shape.min_input_shape = {
304271
"operands_data0": [1, 2, 3],
@@ -379,13 +346,6 @@ def generate_input_matrix(input_shape):
379346
[[3, 4, 5], [4, 5], "ijk,jk->i"],
380347
[[3, 4, 5], [2, 5], "ijk,lk->ijl"],
381348
[[2, 4, 5, 3], [3, 4, 5], "ijkl,lmn->ijkmn"],
382-
[[3, 4, 5], [4, 5], "ijk,jk->ik"],
383-
[[3, 4, 5], [4, 5], "ijk,jk->ij"],
384-
[[4, 5], [4, 2, 5], "ik,ijk->j"],
385-
[[4, 2, 5], [4, 5], "ijk,ik->jk"],
386-
[[2, 4, 5, 3], [3, 2, 4], "ijkl,lmn->kmn"],
387-
[[2, 4, 5, 3], [3, 2, 4], "ijkl,lmn->ijn"],
388-
[[1, 3, 5], [1, 2, 3, 4], "blq,bhlk->bhlqk"],
389349
]:
390350
self.x_shape = item[0]
391351
self.y_shape = item[1]

test/ir/inference/test_trt_convert_grid_sampler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def generate_input2():
4646
return np.random.random([1, 3, 3, 2, 3]).astype(np.float32)
4747

4848
mode = ["bilinear", "nearest"]
49-
padding_mode = ["zeros", "reflection", "border"]
50-
align_corners = [True, False]
49+
padding_mode = ["zeros", "reflection"]
50+
align_corners = [True]
5151
descs = []
5252
for m in mode:
5353
for p in padding_mode:

test/ir/inference/test_trt_convert_squeeze2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool:
3434
return True
3535

3636
def sample_program_configs(self):
37-
for dims in [2, 3, 4]:
38-
for batch in [3, 4]:
37+
for dims in [4]:
38+
for batch in [4]:
3939
for axes in [[2], [2, 3], [-1]]:
4040
for attr_axis in [True, False]:
4141
self.batch = batch

test/ir/inference/test_trt_convert_stack.py

Lines changed: 7 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -44,42 +44,24 @@ def sample_program_configs(self):
4444
def generate_input1(attrs: List[Dict[str, Any]], batch):
4545
if self.dims == 4:
4646
return np.random.random([batch, 3, 24, 24]).astype(np.float32)
47-
elif self.dims == 3:
48-
return np.random.random([batch, 3, 24]).astype(np.float32)
49-
elif self.dims == 2:
50-
return np.random.random([batch, 24]).astype(np.float32)
51-
elif self.dims == 1:
52-
return np.random.random([24]).astype(np.float32)
53-
elif self.dims == 0:
47+
else:
5448
return np.random.random([]).astype(np.float32)
5549

5650
def generate_input2(attrs: List[Dict[str, Any]], batch):
5751
if self.dims == 4:
5852
return np.random.random([batch, 3, 24, 24]).astype(np.float32)
59-
elif self.dims == 3:
60-
return np.random.random([batch, 3, 24]).astype(np.float32)
61-
elif self.dims == 2:
62-
return np.random.random([batch, 24]).astype(np.float32)
63-
elif self.dims == 1:
64-
return np.random.random([24]).astype(np.float32)
65-
elif self.dims == 0:
53+
else:
6654
return np.random.random([]).astype(np.float32)
6755

6856
def generate_input3(attrs: List[Dict[str, Any]], batch):
6957
if self.dims == 4:
7058
return np.random.random([batch, 3, 24, 24]).astype(np.float32)
71-
elif self.dims == 3:
72-
return np.random.random([batch, 3, 24]).astype(np.float32)
73-
elif self.dims == 2:
74-
return np.random.random([batch, 24]).astype(np.float32)
75-
elif self.dims == 1:
76-
return np.random.random([24]).astype(np.float32)
77-
elif self.dims == 0:
59+
else:
7860
return np.random.random([]).astype(np.float32)
7961

80-
for dims in [0, 1, 2, 3, 4]:
81-
for batch in [1, 4]:
82-
for axis in [-2, -1, 0, 1, 2, 3]:
62+
for dims in [0, 4]:
63+
for batch in [1]:
64+
for axis in [-1, 0, 1]:
8365
self.dims = dims
8466
dics = [{"axis": axis}, {}]
8567
ops_config = [
@@ -136,55 +118,7 @@ def generate_dynamic_shape(attrs):
136118
"stack_input2": [1, 3, 24, 24],
137119
"stack_input3": [1, 3, 24, 24],
138120
}
139-
elif self.dims == 3:
140-
self.dynamic_shape.min_input_shape = {
141-
"stack_input1": [1, 3, 24],
142-
"stack_input2": [1, 3, 24],
143-
"stack_input3": [1, 3, 24],
144-
}
145-
self.dynamic_shape.max_input_shape = {
146-
"stack_input1": [4, 3, 48],
147-
"stack_input2": [4, 3, 48],
148-
"stack_input3": [4, 3, 48],
149-
}
150-
self.dynamic_shape.opt_input_shape = {
151-
"stack_input1": [1, 3, 24],
152-
"stack_input2": [1, 3, 24],
153-
"stack_input3": [1, 3, 24],
154-
}
155-
elif self.dims == 2:
156-
self.dynamic_shape.min_input_shape = {
157-
"stack_input1": [1, 24],
158-
"stack_input2": [1, 24],
159-
"stack_input3": [1, 24],
160-
}
161-
self.dynamic_shape.max_input_shape = {
162-
"stack_input1": [4, 48],
163-
"stack_input2": [4, 48],
164-
"stack_input3": [4, 48],
165-
}
166-
self.dynamic_shape.opt_input_shape = {
167-
"stack_input1": [1, 24],
168-
"stack_input2": [1, 24],
169-
"stack_input3": [1, 24],
170-
}
171-
elif self.dims == 1:
172-
self.dynamic_shape.min_input_shape = {
173-
"stack_input1": [24],
174-
"stack_input2": [24],
175-
"stack_input3": [24],
176-
}
177-
self.dynamic_shape.max_input_shape = {
178-
"stack_input1": [48],
179-
"stack_input2": [48],
180-
"stack_input3": [48],
181-
}
182-
self.dynamic_shape.opt_input_shape = {
183-
"stack_input1": [24],
184-
"stack_input2": [24],
185-
"stack_input3": [24],
186-
}
187-
elif self.dims == 0:
121+
else:
188122
self.dynamic_shape.min_input_shape = {
189123
"stack_input1": [],
190124
"stack_input2": [],

test/ir/inference/test_trt_convert_top_k_v2.py

Lines changed: 38 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -25,81 +25,50 @@
2525

2626
class TrtConvertTopKV2Test(TrtLayerAutoScanTest):
2727
def is_program_valid(self, program_config: ProgramConfig) -> bool:
28-
inputs = program_config.inputs
29-
attrs = [
30-
program_config.ops[i].attrs for i in range(len(program_config.ops))
31-
]
32-
if len(inputs['input_data'].shape) <= attrs[0]['axis']:
33-
return False
34-
axis = attrs[0]['axis']
35-
axis = axis if axis >= 0 else axis + len(inputs['input_data'].shape)
36-
if inputs['input_data'].shape[axis] <= attrs[0]['k']:
37-
return False
3828
return True
3929

4030
def sample_program_configs(self):
4131
self.trt_param.workspace_size = 1073741824
4232

4333
def generate_input1(dims, batch, attrs: List[Dict[str, Any]]):
4434
if dims == 1:
45-
return np.random.random([3]).astype(np.float32)
46-
elif dims == 2:
47-
return np.random.random([3, 32]).astype(np.float32)
48-
elif dims == 3:
49-
return np.random.random([3, 32, 32]).astype(np.float32)
50-
else:
51-
return np.random.random([batch, 32, 32, 32]).astype(np.float32)
52-
53-
for dims in [1, 2, 3, 4]:
54-
for batch in [1, 4]:
55-
for k in [1, 3]:
56-
for axis in [-1, 1, 0, 2, 3]:
57-
for largest in [True, False]:
58-
for sort in [True, False]:
59-
self.dims = dims
60-
self.sort = sort
61-
self.axis = axis
62-
dics = [
63-
{
64-
"k": k,
65-
"axis": axis,
66-
"largest": largest,
67-
"sorted": sort,
68-
}
69-
]
70-
ops_config = [
71-
{
72-
"op_type": "top_k_v2",
73-
"op_inputs": {"X": ["input_data"]},
74-
"op_outputs": {
75-
"Out": ["output_data"],
76-
"Indices": ["indices_data"],
77-
},
78-
"op_attrs": dics[0],
79-
"outputs_dtype": {
80-
"indices_data": np.int32
81-
},
82-
}
83-
]
84-
ops = self.generate_op_config(ops_config)
85-
86-
program_config = ProgramConfig(
87-
ops=ops,
88-
weights={},
89-
inputs={
90-
"input_data": TensorConfig(
91-
data_gen=partial(
92-
generate_input1,
93-
dims,
94-
batch,
95-
dics,
96-
)
97-
)
98-
},
99-
outputs=["output_data", "indices_data"],
35+
return np.random.random([32]).astype(np.float32)
36+
if dims == 4:
37+
return np.random.random([batch, 3, 32, 32]).astype(np.float32)
38+
39+
for dims in [1, 4]:
40+
for batch in [1]:
41+
for k in [1]:
42+
self.dims = dims
43+
dics = [{"k": k}]
44+
ops_config = [
45+
{
46+
"op_type": "top_k_v2",
47+
"op_inputs": {"X": ["input_data"]},
48+
"op_outputs": {
49+
"Out": ["output_data"],
50+
"Indices": ["indices_data"],
51+
},
52+
"op_attrs": dics[0],
53+
"outputs_dtype": {"indices_data": np.int32},
54+
}
55+
]
56+
ops = self.generate_op_config(ops_config)
57+
58+
program_config = ProgramConfig(
59+
ops=ops,
60+
weights={},
61+
inputs={
62+
"input_data": TensorConfig(
63+
data_gen=partial(
64+
generate_input1, dims, batch, dics
10065
)
66+
)
67+
},
68+
outputs=["output_data", "indices_data"],
69+
)
10170

102-
yield program_config
71+
yield program_config
10372

10473
def sample_predictor_configs(
10574
self, program_config
@@ -109,23 +78,15 @@ def generate_dynamic_shape(attrs):
10978
self.dynamic_shape.min_input_shape = {"input_data": [1]}
11079
self.dynamic_shape.max_input_shape = {"input_data": [64]}
11180
self.dynamic_shape.opt_input_shape = {"input_data": [32]}
112-
elif self.dims == 2:
113-
self.dynamic_shape.min_input_shape = {"input_data": [1, 1]}
114-
self.dynamic_shape.max_input_shape = {"input_data": [4, 64]}
115-
self.dynamic_shape.opt_input_shape = {"input_data": [3, 10]}
116-
elif self.dims == 3:
117-
self.dynamic_shape.min_input_shape = {"input_data": [1, 1, 1]}
118-
self.dynamic_shape.max_input_shape = {"input_data": [4, 64, 64]}
119-
self.dynamic_shape.opt_input_shape = {"input_data": [3, 10, 10]}
12081
else:
12182
self.dynamic_shape.min_input_shape = {
12283
"input_data": [1, 3, 16, 16]
12384
}
12485
self.dynamic_shape.max_input_shape = {
125-
"input_data": [4, 32, 32, 32]
86+
"input_data": [4, 3, 32, 32]
12687
}
12788
self.dynamic_shape.opt_input_shape = {
128-
"input_data": [4, 3, 32, 32]
89+
"input_data": [1, 3, 32, 32]
12990
}
13091

13192
def clear_dynamic_shape():
@@ -134,9 +95,7 @@ def clear_dynamic_shape():
13495
self.dynamic_shape.opt_input_shape = {}
13596

13697
def generate_trt_nodes_num(attrs, dynamic_shape):
137-
if not dynamic_shape and (self.dims == 1 or self.axis == 0):
138-
return 0, 4
139-
if not self.sort:
98+
if not dynamic_shape and self.dims == 1:
14099
return 0, 4
141100
return 1, 3
142101

test/ir/inference/test_trt_convert_unsqueeze2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool:
2828
return True
2929

3030
def sample_program_configs(self):
31-
for dims in [2, 3, 4]:
32-
for batch in [3, 4]:
33-
for axes in [[-2, 3], [1], [2], [2, 3]]:
31+
for dims in [2, 4]:
32+
for batch in [4]:
33+
for axes in [[-2, 3], [1]]:
3434
self.batch = batch
3535
self.dims = dims
3636
self.axes = axes

0 commit comments

Comments
 (0)