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

[OpTestPy] add greater grid_sampler 2 op all utest #7994

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
120 changes: 120 additions & 0 deletions lite/tests/unittest_py/op/test_greater_op.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

from numpy.lib.function_base import place
sys.path.append('../')

from auto_scan_test import AutoScanTest, IgnoreReasons
from program_config import TensorConfig, ProgramConfig, OpConfig, CxxConfig, TargetType, PrecisionType, DataLayoutType, Place
import unittest

import hypothesis
from hypothesis import given, settings, seed, example, assume
import hypothesis.strategies as st
import argparse
import numpy as np
from functools import partial


class TestAssignOp(AutoScanTest):
def __init__(self, *args, **kwargs):
AutoScanTest.__init__(self, *args, **kwargs)
host_op_config = [
Place(TargetType.Host, PrecisionType.Any, DataLayoutType.NCHW),
Place(TargetType.Host, PrecisionType.FP32, DataLayoutType.Any)
]
self.enable_testing_on_place(places=host_op_config)

def is_program_valid(self,
program_config: ProgramConfig,
predictor_config: CxxConfig) -> bool:
return True

def sample_program_configs(self, draw):
in_shape = draw(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in_shape -> in_shape_x

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改

st.lists(
st.integers(
min_value=3, max_value=10), min_size=3, max_size=4))
axis = draw(st.sampled_from([-1, 0, 1, 2]))
op_type_str = draw(st.sampled_from(["greater_equal", "greater_than"]))
process_type = draw(
st.sampled_from(["type_int64", "type_float", "type_int32"]))

############### ToDo ####################
assume(process_type != "type_int32")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

将类型约束放在is_program_valid函数中

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改

#########################################

if axis == -1:
in_shape_y = in_shape
else:
in_shape_y = in_shape[axis:]

def generate_data(type, size_list):
if type == "type_int32":
return np.random.randint(
low=0, high=100, size=size_list).astype(np.int32)
elif type == "type_int64":
return np.random.randint(
low=0, high=100, size=size_list).astype(np.int64)
elif type == "type_float":
return np.random.random(size=size_list).astype(np.float32)

def generate_input_x():
return generate_data(process_type, in_shape)

def generate_input_y():
return generate_data(process_type, in_shape_y)

build_ops = OpConfig(
type=op_type_str,
inputs={"X": ["data_x"],
"Y": ["data_y"]},
outputs={"Out": ["output_data"], },
attrs={"axis": axis,
"force_cpu": True})
build_ops.outputs_dtype = {"output_data": np.bool_}

cast_out = OpConfig(
type="cast",
inputs={"X": ["output_data"], },
outputs={"Out": ["cast_data_out"], },
attrs={"in_dtype": int(0),
"out_dtype": int(2)})
cast_out.outputs_dtype = {"cast_data_out": np.int32}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个outputs_dtype为啥不写到opconfig里面呢

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也行,改了


program_config = ProgramConfig(
ops=[build_ops, cast_out],
weights={},
inputs={
"data_x": TensorConfig(data_gen=partial(generate_input_x)),
"data_y": TensorConfig(data_gen=partial(generate_input_y)),
},
outputs=["cast_data_out"])
return program_config

def sample_predictor_configs(self):
return self.get_predictor_configs(), ["greater_equal_and_than"], (1e-5,
1e-5)

def add_ignore_pass_case(self):
pass

def test(self, *args, **kwargs):
self.run_and_statis(quant=False, max_examples=300)


if __name__ == "__main__":
unittest.main(argv=[''])
125 changes: 125 additions & 0 deletions lite/tests/unittest_py/op/test_grid_sampler_op.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
sys.path.append('../')

from auto_scan_test import AutoScanTest, IgnoreReasons
from program_config import TensorConfig, ProgramConfig, OpConfig, CxxConfig, TargetType, PrecisionType, DataLayoutType, Place
import unittest

import hypothesis
from hypothesis import given, settings, seed, example, assume

import numpy as np
from functools import partial
import hypothesis.strategies as st


class TestGridSamplerOp(AutoScanTest):
def __init__(self, *args, **kwargs):
AutoScanTest.__init__(self, *args, **kwargs)
self.enable_testing_on_place(
TargetType.X86,
PrecisionType.FP32,
DataLayoutType.NCHW,
thread=[1, 4])
self.enable_testing_on_place(
TargetType.ARM,
PrecisionType.FP32,
DataLayoutType.NCHW,
thread=[1, 4])
opencl_places = [
Place(TargetType.OpenCL, PrecisionType.FP16,
DataLayoutType.ImageDefault), Place(
TargetType.OpenCL, PrecisionType.FP16,
DataLayoutType.ImageFolder),
Place(TargetType.OpenCL, PrecisionType.FP32, DataLayoutType.NCHW),
Place(TargetType.OpenCL, PrecisionType.Any,
DataLayoutType.ImageDefault), Place(
TargetType.OpenCL, PrecisionType.Any,
DataLayoutType.ImageFolder),
Place(TargetType.OpenCL, PrecisionType.Any, DataLayoutType.NCHW),
Place(TargetType.Host, PrecisionType.FP32)
]
self.enable_testing_on_place(places=opencl_places)

def is_program_valid(self,
program_config: ProgramConfig,
predictor_config: CxxConfig) -> bool:
if predictor_config.target() == TargetType.OpenCL:
if program_config.ops[0].attrs[
"align_corners"] != True or program_config.ops[0].attrs[
"padding_mode"] != "zeros" or program_config.ops[
0].attrs["mode"] != "bilinear":
return False
return True

def sample_program_configs(self, draw):
in_shape1 = draw(
st.lists(
st.integers(
min_value=10, max_value=100),
min_size=4,
max_size=4))

in_shape2 = []
in_shape2.append(in_shape1[0])
in_shape2.append(in_shape1[2])
in_shape2.append(in_shape1[3])
in_shape2.append(2)

align_corners = draw(st.booleans())
mode = draw(st.sampled_from(["bilinear", "nearest"]))
padding_mode = draw(st.sampled_from(["zeros", "reflection", "border"]))
grid_sampler_op = OpConfig(
type="grid_sampler",
inputs={"X": ["input_data"],
"Grid": ["grid_data"]},
outputs={"Output": ["output_data"]},
attrs={
"align_corners": align_corners,
"mode": mode,
"padding_mode": padding_mode
})

program_config = ProgramConfig(
ops=[grid_sampler_op],
weights={"grid_data": TensorConfig(shape=in_shape2)},
inputs={"input_data": TensorConfig(shape=in_shape1)},
outputs=["output_data"])

return program_config

def sample_predictor_configs(self):
return self.get_predictor_configs(), ["grid_sampler"], (1e-5, 1e-5)

def add_ignore_pass_case(self):
def teller1(program_config, predictor_config):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grid_sampler 输出有diff是吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,cpu和gpu都有diff

return True

self.add_ignore_check_case(
# IgnoreReasonsBase.PADDLE_NOT_IMPLEMENTED
# IgnoreReasonsBase.PADDLELITE_NOT_SUPPORT
# IgnoreReasonsBase.ACCURACY_ERROR
teller1,
IgnoreReasons.ACCURACY_ERROR,
"The op output has diff. We need to fix it as soon as possible.")

def test(self, *args, **kwargs):
self.run_and_statis(quant=False, max_examples=300)


if __name__ == "__main__":
unittest.main(argv=[''])