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

update inference ut to support nhwc format #39551

Merged
merged 4 commits into from
Feb 17, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ ConvActivationFusePass::ConvActivationFusePass() {
// IsStringIn({"NHWC", "NCHW"}) MobileNetV2 has no this attribute
.AddAttr("data_format")
.IsOptional()
.IsStringIn({"NCHW", "AnyLayout"})
.IsStringIn({"NCHW", "NHWC", "AnyLayout"})
.End();

AddOpCompat(OpCompat("relu"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Conv2DTransposeBiasFusePass::Conv2DTransposeBiasFusePass() {
.IsStringIn({"EXPLICIT", "SAME", "VALID"})
.End()
.AddAttr("data_format")
.IsStringIn({"NCHW"})
.IsStringIn({"NCHW", "NHWC", "AnyLayout"})
.End();

AddOpCompat(OpCompat("elementwise_add"))
Expand All @@ -129,7 +129,7 @@ Conv2DTransposeBiasFusePass::Conv2DTransposeBiasFusePass() {
.IsTensor()
.End()
.AddAttr("axis")
.IsIntIn({1})
.IsIntIn({1, 3})
.End();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ConvConcatReLUFusePass::ConvConcatReLUFusePass() {
.IsType<std::vector<int>>()
.End()
.AddAttr("data_format")
.IsStringIn({"NCHW"})
.IsStringIn({"NCHW", "NHWC", "AnyLayout"})
.End();

AddOpCompat(OpCompat("concat"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ def is_program_valid(self, prog_config):
data_format = prog_config.ops[0].attrs["data_format"]
filter_shape = prog_config.weights["filter"].shape
input_shape = prog_config.inputs["input_x"].shape
if data_format != "NCHW":
return False
if padding_algorithm == "VALID":
if ((input_shape[2] - (dilations[0] * (filter_shape[2] - 1) + 1)) / strides[0] + 1) <= 1 or \
((input_shape[3] - (dilations[1] * (filter_shape[3] - 1) + 1)) / strides[1] + 1) <= 1:
Expand All @@ -80,8 +78,8 @@ def sample_program_config(self, draw):
x_shape = draw(
st.lists(
st.integers(
min_value=1, max_value=100), min_size=4, max_size=4))
x_shape[1] = draw(st.integers(min_value=1, max_value=10))
min_value=5, max_value=100), min_size=4, max_size=4))
x_shape[1] = draw(st.integers(min_value=5, max_value=10))

# 2. Generate legal attr:data_format of conv2d
data_format = draw(st.sampled_from(["NCHW", "NHWC"]))
Expand All @@ -90,7 +88,7 @@ def sample_program_config(self, draw):
f_shape = draw(
st.lists(
st.integers(
min_value=1, max_value=7), min_size=4, max_size=4))
min_value=1, max_value=5), min_size=4, max_size=4))
if data_format == "NCHW":
f_shape[1] = x_shape[1]
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ def is_program_valid(self, prog_config):
data_format = prog_config.ops[0].attrs["data_format"]
filter_shape = prog_config.weights["filter"].shape
input_shape = prog_config.inputs["input_x"].shape
if data_format != "NCHW":
return False
if padding_algorithm == "VALID":
if ((input_shape[2] - (dilations[0] * (filter_shape[2] - 1) + 1)) / strides[0] + 1) <= 1 or \
((input_shape[3] - (dilations[1] * (filter_shape[3] - 1) + 1)) / strides[1] + 1) <= 1:
Expand All @@ -80,8 +78,8 @@ def sample_program_config(self, draw):
x_shape = draw(
st.lists(
st.integers(
min_value=1, max_value=100), min_size=4, max_size=4))
x_shape[1] = draw(st.integers(min_value=1, max_value=10))
min_value=5, max_value=100), min_size=4, max_size=4))
x_shape[1] = draw(st.integers(min_value=5, max_value=10))

# 2. Generate legal attr:data_format of conv2d
data_format = draw(st.sampled_from(["NCHW", "NHWC"]))
Expand All @@ -90,7 +88,7 @@ def sample_program_config(self, draw):
f_shape = draw(
st.lists(
st.integers(
min_value=1, max_value=7), min_size=4, max_size=4))
min_value=1, max_value=4), min_size=4, max_size=4))
if data_format == "NCHW":
f_shape[1] = x_shape[1]
else:
Expand All @@ -100,7 +98,7 @@ def sample_program_config(self, draw):
strides = draw(
st.lists(
st.integers(
min_value=1, max_value=5), min_size=2, max_size=2))
min_value=1, max_value=4), min_size=2, max_size=2))

# 5. Generate legal attr:padding_algorithm of conv2d
padding_algorithm = draw(st.sampled_from(["EXPLICIT", "SAME", "VALID"]))
Expand All @@ -109,7 +107,7 @@ def sample_program_config(self, draw):
padding = draw(
st.lists(
st.integers(
min_value=1, max_value=5), min_size=4, max_size=4))
min_value=1, max_value=4), min_size=4, max_size=4))

# 7. Generate legal attr:groups of conv2d
groups = draw(st.integers(min_value=1, max_value=3))
Expand All @@ -118,7 +116,7 @@ def sample_program_config(self, draw):
dilations = draw(
st.lists(
st.integers(
min_value=1, max_value=5), min_size=2, max_size=2))
min_value=1, max_value=4), min_size=2, max_size=2))

# 9. Generate legal shape of input:bias of elementwise_add
bias_shape = [f_shape[0]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@

class TestConvConcatReluMkldnnFusePass(PassAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
attrs = [
program_config.ops[i].attrs
for i in range(len(program_config.ops))
]
# If the problem has been fixed, the judgment
# needs to be deleted!!!
if attrs[0]['data_format'] == "NHWC":
return False

return True

def sample_program_config(self, draw):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@

class TestConvGeluMkldnnFusePass(PassAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
attrs = [
program_config.ops[i].attrs
for i in range(len(program_config.ops))
]
# If the problem has been fixed, the judgment
# needs to be deleted!!!
if attrs[0]['data_format'] == "NHWC":
return False

return True

def sample_program_config(self, draw):
Expand Down Expand Up @@ -108,19 +99,6 @@ def sample_predictor_configs(self, program_config):
config = self.create_inference_config(use_mkldnn=True)
yield config, ["conv2d"], (1e-5, 1e-5)

# If the problem has been fixed, the judgment
# needs to be deleted!!!
def add_ignore_pass_case(self):
def teller1(program_config, predictor_config):
if program_config.ops[0].attrs['data_format'] == "NHWC":
return True
return False

self.add_ignore_check_case(
teller1, SkipReasons.PASS_ACCURACY_ERROR,
"The output format of conv2d is wrong when data_format attribute is NHWC"
)

def test(self):
self.run_and_statis(quant=False, passes=["conv_gelu_mkldnn_fuse_pass"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@

class TestConvHardSigmoidMkldnnFusePass(PassAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
attrs = [
program_config.ops[i].attrs
for i in range(len(program_config.ops))
]
# If the problem has been fixed, the judgment
# needs to be deleted!!!
if attrs[0]['data_format'] == "NHWC":
return False

return True

def sample_program_config(self, draw):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@

class TestConvHardSwishMkldnnFusePass(PassAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
attrs = [
program_config.ops[i].attrs
for i in range(len(program_config.ops))
]
# If the problem has been fixed, the judgment
# needs to be deleted!!!
if attrs[0]['data_format'] == "NHWC":
return False

return True

def sample_program_config(self, draw):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def is_program_valid(self, program_config: ProgramConfig) -> bool:
for i in range(len(program_config.ops))
]

# If the problem has been fixed, the judgment
# needs to be deleted!!!
if attrs[0]['data_format'] == "NHWC":
if attrs[0]['data_format'] == "NCHW" and attrs[1]["axis"] == 3:
return False
if attrs[0]['data_format'] == "NHWC" and attrs[1]["axis"] == 1:
return False

return True
Expand All @@ -46,7 +46,7 @@ def sample_program_config(self, draw):
groups = draw(st.sampled_from([1, 2, 4, 8]))
paddings = draw(st.sampled_from([[0, 3], [1, 2, 3, 4]]))
strides = draw(st.sampled_from([[1, 1], [2, 2], [1, 2]]))
axis = draw(st.sampled_from([1]))
axis = draw(st.sampled_from([1, 3]))
batch_size = draw(st.integers(min_value=1, max_value=4))

def generate_input():
Expand Down Expand Up @@ -110,7 +110,9 @@ def sample_predictor_configs(self, program_config):

def test(self):
self.run_and_statis(
quant=False, passes=["conv_transpose_bias_mkldnn_fuse_pass"])
quant=False,
max_duration=300,
passes=["conv_transpose_bias_mkldnn_fuse_pass"])


if __name__ == "__main__":
Expand Down