Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce runtime of unit-tests in windows-trt #60731

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 3 additions & 43 deletions test/ir/inference/test_trt_convert_einsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,12 @@ def sample_program_configs(self):
def generate_input1(dims, batch):
if dims == 1:
return np.ones(shape=[batch]).astype(np.float32)
elif dims == 2:
return np.ones(shape=[batch, 3]).astype(np.float32)
elif dims == 3:
return np.ones((batch, 2, 3)).astype(np.float32)

def generate_equation1(dims):
if dims == 1:
return ["i->"]
elif dims == 2:
# "ij->"
return ["ij->ji", "ij->i", "ij->j"]
elif dims == 3:
# "ijk->","ijk->j","ijk->k"
# error: The current implementation of Einsum doesn't support mask dimensions on multiple contracting/free dimensions
Expand All @@ -60,7 +55,7 @@ def generate_equation1(dims):
]

# Single operand: transpose, sum
for dims in [1, 2, 3]:
for dims in [1, 3]:
for batch in [2]:
equation_list = generate_equation1(dims)
for equation in equation_list:
Expand Down Expand Up @@ -108,16 +103,7 @@ def generate_dynamic_shape(attrs):
self.dynamic_shape.opt_input_shape = {
"operands_data0": [2],
}
elif self.dims == 2:
self.dynamic_shape.min_input_shape = {
"operands_data0": [1, 3],
}
self.dynamic_shape.max_input_shape = {
"operands_data0": [4, 3],
}
self.dynamic_shape.opt_input_shape = {
"operands_data0": [2, 3],
}

elif self.dims == 3:
self.dynamic_shape.min_input_shape = {
"operands_data0": [1, 2, 3],
Expand Down Expand Up @@ -219,18 +205,12 @@ def generate_equation_matrix_vector(dims, vec_shape):
# Doubule operands vector
for dims in [1]:
self.dims = dims
for vec_shape in [[2], [3]]:
for vec_shape in [[2]]:
for batch in [2]:
equation_list = generate_equation_matrix_vector(
dims, vec_shape
)
for equation in equation_list:
if (
dims == 1
and vec_shape != [2]
and equation != "i,j->ij"
) or ((dims == 2 or dims == 3) and vec_shape != [3]):
continue
self.equation = equation
self.dims = dims
dics = [{"equation": equation}, {}]
Expand Down Expand Up @@ -286,19 +266,6 @@ def generate_dynamic_shape(attrs):
"operands_data0": [2],
"operands_data1": [2],
}
elif self.dims == 2:
self.dynamic_shape.min_input_shape = {
"operands_data0": [1, 3],
"operands_data1": [1],
}
self.dynamic_shape.max_input_shape = {
"operands_data0": [4, 3],
"operands_data1": [4],
}
self.dynamic_shape.opt_input_shape = {
"operands_data0": [2, 3],
"operands_data1": [3],
}
elif self.dims == 3:
self.dynamic_shape.min_input_shape = {
"operands_data0": [1, 2, 3],
Expand Down Expand Up @@ -379,13 +346,6 @@ def generate_input_matrix(input_shape):
[[3, 4, 5], [4, 5], "ijk,jk->i"],
[[3, 4, 5], [2, 5], "ijk,lk->ijl"],
[[2, 4, 5, 3], [3, 4, 5], "ijkl,lmn->ijkmn"],
[[3, 4, 5], [4, 5], "ijk,jk->ik"],
[[3, 4, 5], [4, 5], "ijk,jk->ij"],
[[4, 5], [4, 2, 5], "ik,ijk->j"],
[[4, 2, 5], [4, 5], "ijk,ik->jk"],
[[2, 4, 5, 3], [3, 2, 4], "ijkl,lmn->kmn"],
[[2, 4, 5, 3], [3, 2, 4], "ijkl,lmn->ijn"],
[[1, 3, 5], [1, 2, 3, 4], "blq,bhlk->bhlqk"],
]:
self.x_shape = item[0]
self.y_shape = item[1]
Expand Down
4 changes: 2 additions & 2 deletions test/ir/inference/test_trt_convert_grid_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def generate_input2():
return np.random.random([1, 3, 3, 2, 3]).astype(np.float32)

mode = ["bilinear", "nearest"]
padding_mode = ["zeros", "reflection", "border"]
align_corners = [True, False]
padding_mode = ["zeros", "reflection"]
align_corners = [True]
descs = []
for m in mode:
for p in padding_mode:
Expand Down
4 changes: 2 additions & 2 deletions test/ir/inference/test_trt_convert_squeeze2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True

def sample_program_configs(self):
for dims in [2, 3, 4]:
for batch in [3, 4]:
for dims in [4]:
for batch in [4]:
for axes in [[2], [2, 3], [-1]]:
for attr_axis in [True, False]:
self.batch = batch
Expand Down
80 changes: 7 additions & 73 deletions test/ir/inference/test_trt_convert_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,24 @@ def sample_program_configs(self):
def generate_input1(attrs: List[Dict[str, Any]], batch):
if self.dims == 4:
return np.random.random([batch, 3, 24, 24]).astype(np.float32)
elif self.dims == 3:
return np.random.random([batch, 3, 24]).astype(np.float32)
elif self.dims == 2:
return np.random.random([batch, 24]).astype(np.float32)
elif self.dims == 1:
return np.random.random([24]).astype(np.float32)
elif self.dims == 0:
else:
return np.random.random([]).astype(np.float32)

def generate_input2(attrs: List[Dict[str, Any]], batch):
if self.dims == 4:
return np.random.random([batch, 3, 24, 24]).astype(np.float32)
elif self.dims == 3:
return np.random.random([batch, 3, 24]).astype(np.float32)
elif self.dims == 2:
return np.random.random([batch, 24]).astype(np.float32)
elif self.dims == 1:
return np.random.random([24]).astype(np.float32)
elif self.dims == 0:
else:
return np.random.random([]).astype(np.float32)

def generate_input3(attrs: List[Dict[str, Any]], batch):
if self.dims == 4:
return np.random.random([batch, 3, 24, 24]).astype(np.float32)
elif self.dims == 3:
return np.random.random([batch, 3, 24]).astype(np.float32)
elif self.dims == 2:
return np.random.random([batch, 24]).astype(np.float32)
elif self.dims == 1:
return np.random.random([24]).astype(np.float32)
elif self.dims == 0:
else:
return np.random.random([]).astype(np.float32)

for dims in [0, 1, 2, 3, 4]:
for batch in [1, 4]:
for axis in [-2, -1, 0, 1, 2, 3]:
for dims in [0, 4]:
for batch in [1]:
for axis in [-1, 0, 1]:
self.dims = dims
dics = [{"axis": axis}, {}]
ops_config = [
Expand Down Expand Up @@ -136,55 +118,7 @@ def generate_dynamic_shape(attrs):
"stack_input2": [1, 3, 24, 24],
"stack_input3": [1, 3, 24, 24],
}
elif self.dims == 3:
self.dynamic_shape.min_input_shape = {
"stack_input1": [1, 3, 24],
"stack_input2": [1, 3, 24],
"stack_input3": [1, 3, 24],
}
self.dynamic_shape.max_input_shape = {
"stack_input1": [4, 3, 48],
"stack_input2": [4, 3, 48],
"stack_input3": [4, 3, 48],
}
self.dynamic_shape.opt_input_shape = {
"stack_input1": [1, 3, 24],
"stack_input2": [1, 3, 24],
"stack_input3": [1, 3, 24],
}
elif self.dims == 2:
self.dynamic_shape.min_input_shape = {
"stack_input1": [1, 24],
"stack_input2": [1, 24],
"stack_input3": [1, 24],
}
self.dynamic_shape.max_input_shape = {
"stack_input1": [4, 48],
"stack_input2": [4, 48],
"stack_input3": [4, 48],
}
self.dynamic_shape.opt_input_shape = {
"stack_input1": [1, 24],
"stack_input2": [1, 24],
"stack_input3": [1, 24],
}
elif self.dims == 1:
self.dynamic_shape.min_input_shape = {
"stack_input1": [24],
"stack_input2": [24],
"stack_input3": [24],
}
self.dynamic_shape.max_input_shape = {
"stack_input1": [48],
"stack_input2": [48],
"stack_input3": [48],
}
self.dynamic_shape.opt_input_shape = {
"stack_input1": [24],
"stack_input2": [24],
"stack_input3": [24],
}
elif self.dims == 0:
else:
self.dynamic_shape.min_input_shape = {
"stack_input1": [],
"stack_input2": [],
Expand Down
117 changes: 38 additions & 79 deletions test/ir/inference/test_trt_convert_top_k_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,81 +25,50 @@

class TrtConvertTopKV2Test(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
inputs = program_config.inputs
attrs = [
program_config.ops[i].attrs for i in range(len(program_config.ops))
]
if len(inputs['input_data'].shape) <= attrs[0]['axis']:
return False
axis = attrs[0]['axis']
axis = axis if axis >= 0 else axis + len(inputs['input_data'].shape)
if inputs['input_data'].shape[axis] <= attrs[0]['k']:
return False
return True

def sample_program_configs(self):
self.trt_param.workspace_size = 1073741824

def generate_input1(dims, batch, attrs: List[Dict[str, Any]]):
if dims == 1:
return np.random.random([3]).astype(np.float32)
elif dims == 2:
return np.random.random([3, 32]).astype(np.float32)
elif dims == 3:
return np.random.random([3, 32, 32]).astype(np.float32)
else:
return np.random.random([batch, 32, 32, 32]).astype(np.float32)

for dims in [1, 2, 3, 4]:
for batch in [1, 4]:
for k in [1, 3]:
for axis in [-1, 1, 0, 2, 3]:
for largest in [True, False]:
for sort in [True, False]:
self.dims = dims
self.sort = sort
self.axis = axis
dics = [
{
"k": k,
"axis": axis,
"largest": largest,
"sorted": sort,
}
]
ops_config = [
{
"op_type": "top_k_v2",
"op_inputs": {"X": ["input_data"]},
"op_outputs": {
"Out": ["output_data"],
"Indices": ["indices_data"],
},
"op_attrs": dics[0],
"outputs_dtype": {
"indices_data": np.int32
},
}
]
ops = self.generate_op_config(ops_config)

program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input_data": TensorConfig(
data_gen=partial(
generate_input1,
dims,
batch,
dics,
)
)
},
outputs=["output_data", "indices_data"],
return np.random.random([32]).astype(np.float32)
if dims == 4:
return np.random.random([batch, 3, 32, 32]).astype(np.float32)

for dims in [1, 4]:
for batch in [1]:
for k in [1]:
self.dims = dims
dics = [{"k": k}]
ops_config = [
{
"op_type": "top_k_v2",
"op_inputs": {"X": ["input_data"]},
"op_outputs": {
"Out": ["output_data"],
"Indices": ["indices_data"],
},
"op_attrs": dics[0],
"outputs_dtype": {"indices_data": np.int32},
}
]
ops = self.generate_op_config(ops_config)

program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input_data": TensorConfig(
data_gen=partial(
generate_input1, dims, batch, dics
)
)
},
outputs=["output_data", "indices_data"],
)

yield program_config
yield program_config

def sample_predictor_configs(
self, program_config
Expand All @@ -109,23 +78,15 @@ def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {"input_data": [1]}
self.dynamic_shape.max_input_shape = {"input_data": [64]}
self.dynamic_shape.opt_input_shape = {"input_data": [32]}
elif self.dims == 2:
self.dynamic_shape.min_input_shape = {"input_data": [1, 1]}
self.dynamic_shape.max_input_shape = {"input_data": [4, 64]}
self.dynamic_shape.opt_input_shape = {"input_data": [3, 10]}
elif self.dims == 3:
self.dynamic_shape.min_input_shape = {"input_data": [1, 1, 1]}
self.dynamic_shape.max_input_shape = {"input_data": [4, 64, 64]}
self.dynamic_shape.opt_input_shape = {"input_data": [3, 10, 10]}
else:
self.dynamic_shape.min_input_shape = {
"input_data": [1, 3, 16, 16]
}
self.dynamic_shape.max_input_shape = {
"input_data": [4, 32, 32, 32]
"input_data": [4, 3, 32, 32]
}
self.dynamic_shape.opt_input_shape = {
"input_data": [4, 3, 32, 32]
"input_data": [1, 3, 32, 32]
}

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

def generate_trt_nodes_num(attrs, dynamic_shape):
if not dynamic_shape and (self.dims == 1 or self.axis == 0):
return 0, 4
if not self.sort:
if not dynamic_shape and self.dims == 1:
return 0, 4
return 1, 3

Expand Down
6 changes: 3 additions & 3 deletions test/ir/inference/test_trt_convert_unsqueeze2.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True

def sample_program_configs(self):
for dims in [2, 3, 4]:
for batch in [3, 4]:
for axes in [[-2, 3], [1], [2], [2, 3]]:
for dims in [2, 4]:
for batch in [4]:
for axes in [[-2, 3], [1]]:
self.batch = batch
self.dims = dims
self.axes = axes
Expand Down