Skip to content

Commit

Permalink
feat: catch exception at verification stage as ORT backend can return…
Browse files Browse the repository at this point in the history
… None
  • Loading branch information
ganler committed Oct 24, 2022
1 parent 5270f9b commit 6e96cb5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions nnsmith/backends/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ def verify_results(
log=traceback.format_exc(),
version=self.version,
)
except Exception:
return BugReport(
testcase=testcase,
system=self.system_name,
symptom=Symptom.EXCEPTION,
stage=Stage.VERIFICATION,
log=traceback.format_exc(),
version=self.version,
)

def verify_testcase(
self, testcase: TestCase, equal_nan=True
Expand Down
15 changes: 13 additions & 2 deletions nnsmith/difftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,20 @@ def assert_allclose(
raise KeyError(f"{actual_name}: {akeys} != {oracle_name}: {dkeys}")

for key in akeys:
lhs = actual[key]
rhs = desired[key]

# check if lhs is np.ndarray
if not isinstance(lhs, np.ndarray):
raise TypeError(f"{actual_name}[{key}] is not np.ndarray but {type(lhs)}")

# check if rhs is np.ndarray
if not isinstance(rhs, np.ndarray):
raise TypeError(f"{oracle_name}[{key}] is not np.ndarray but {type(rhs)}")

testing.assert_allclose(
actual[key],
desired[key],
lhs,
rhs,
equal_nan=equal_nan,
rtol=rtol,
atol=atol,
Expand Down

1 comment on commit 6e96cb5

@ganler
Copy link
Member Author

@ganler ganler commented on 6e96cb5 Oct 25, 2022

Choose a reason for hiding this comment

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

In some edge settings, outputs are optimized out in ONNXRuntime that it returns None. Doing a numpy.testing.assert_allclose with None will throw an exception which terminates the fuzzing loop with an exception. So we need to enhance the exception capture to catch such kinds of bugs.

Corresponding issue: microsoft/onnxruntime#13425

Please sign in to comment.