Skip to content

Commit 6b96df4

Browse files
digantdesaifacebook-github-bot
authored andcommitted
Dump more stats on output mismatch (#2328)
Summary: Pull Request resolved: #2328 Helps with debugging random numerical issues Reviewed By: mcr229 Differential Revision: D54210764 fbshipit-source-id: 8ed3e4abb508b0b6c33633221606acae14eb0e45
1 parent a62733a commit 6b96df4

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

backends/xnnpack/test/tester/tester.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,25 @@ def _assert_outputs_equal(model_output, ref_output, atol=1e-03, rtol=1e-03):
501501
assert len(model_output) == len(ref_output)
502502

503503
for i in range(len(model_output)):
504+
model = model_output[i]
505+
ref = ref_output[i]
504506
assert torch.allclose(
505-
model_output[i],
506-
ref_output[i],
507+
model,
508+
ref,
507509
atol=atol,
508510
rtol=rtol,
509-
), f" Output {i} does not match reference output. Max difference: {torch.max(torch.abs(model_output[i] - ref_output[i]))}"
511+
), (
512+
f"Output {i} does not match reference output.\n"
513+
f"\tGiven atol: {atol}, rtol: {rtol}.\n"
514+
f"\tOutput tensor shape: {model.shape}, dtype: {model.dtype}\n"
515+
f"\tDifference: max: {torch.max(model-ref)}, abs: {torch.max(torch.abs(model-ref))}.\n"
516+
f"\t-- Model vs. Reference --\n"
517+
f"\t Numel: {model.numel()}, {ref.numel()}\n"
518+
f"\tMedian: {model.median()}, {ref.median()}\n"
519+
f"\t Mean: {model.mean()}, {ref.mean()}\n"
520+
f"\t Max: {model.max()}, {ref.max()}\n"
521+
f"\t Min: {model.min()}, {ref.min()}\n"
522+
)
510523

511524
def compare_outputs(self, atol=1e-03, rtol=1e-03, qtol=0):
512525
"""

0 commit comments

Comments
 (0)