Skip to content

[NPU][MLU] fix nearest interpolate unit test bug #716

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

Merged
merged 2 commits into from
Jul 25, 2023
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
9 changes: 6 additions & 3 deletions backends/mlu/tests/unittests/test_nearest_interp_v2_op_mlu.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def setUp(self):
self.out_size = None
self.actual_shape = None
self.init_test_case()
self.data_layout = "NCHW" if len(self.input_shape) == 4 else "NCDHW"
if hasattr(self, "data_layout"):
self.data_layout = "NCHW" if len(self.input_shape) == 4 else "NCDHW"
self.op_type = "nearest_interp_v2"
input_np = np.random.random(self.input_shape).astype("float32")

Expand Down Expand Up @@ -427,10 +428,10 @@ def setUp(self):
self.__class__.use_custom_device = True
self.out_size = None
self.actual_shape = None
self.init_test_case()
self.op_type = "nearest_interp_v2"
self.shape_by_1Dtensor = False
self.scale_by_1Dtensor = False
self.init_test_case()
self.op_type = "nearest_interp_v2"
self.attrs = {
"interp_method": self.interp_method,
"align_corners": self.align_corners,
Expand All @@ -441,6 +442,8 @@ def setUp(self):

if self.scale_by_1Dtensor:
self.inputs["Scale"] = np.array([self.scale]).astype("float32")
out_h = int(self.input_shape[2] * self.scale)
out_w = int(self.input_shape[3] * self.scale)
elif self.scale:
if isinstance(self.scale, float) or isinstance(self.scale, int):
if self.scale > 0:
Expand Down
8 changes: 5 additions & 3 deletions backends/npu/tests/unittests/test_nearest_interp_op_npu.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ def setUp(self):
self.set_npu()
self.out_size = None
self.actual_shape = None
self.init_test_case()
self.op_type = "nearest_interp_v2"
self.shape_by_1Dtensor = False
self.scale_by_1Dtensor = False
self.init_test_case()
self.op_type = "nearest_interp_v2"
self.attrs = {
"interp_method": self.interp_method,
"align_corners": self.align_corners,
Expand All @@ -326,6 +326,8 @@ def setUp(self):

if self.scale_by_1Dtensor:
self.inputs["Scale"] = np.array([self.scale]).astype("float32")
out_h = int(self.input_shape[2] * self.scale)
out_w = int(self.input_shape[3] * self.scale)
elif self.scale:
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个不需要哈,347行已经将self.out_size赋值给self.inputs["OutSize"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

未加上这一行,out_hout_w将没有赋值,在执行365行时,会报UnboundLocalError: local variable 'out_h' referenced before assignment的错误。

Copy link
Collaborator

Choose a reason for hiding this comment

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

好的

if isinstance(self.scale, float) or isinstance(self.scale, int):
if self.scale > 0:
Expand Down Expand Up @@ -420,7 +422,7 @@ def init_test_case(self):
self.input_shape = [3, 2, 32, 16]
self.out_h = 64
self.out_w = 32
self.scale = []
self.scale = 2.0
self.out_size = None
self.align_corners = False
self.scale_by_1Dtensor = True
Expand Down