-
Notifications
You must be signed in to change notification settings - Fork 24.8k
[torch][ao] Do not crash numerics debugger if the shape of the tensors do not match #149330
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -318,10 +318,28 @@ def compare_results( | |
) | ||
continue | ||
actual_name, actual_stack, actual_stats = actual_results[debug_handle] | ||
for a, b in zip(actual_stats, ref_stats): | ||
if ( | ||
isinstance(a, torch.Tensor) | ||
and isinstance(b, torch.Tensor) | ||
and a.shape != b.shape | ||
): | ||
log.warning( | ||
"Cannot compare tensors with different shapes: actual=%s vs ref=%s", | ||
a.shape, | ||
b.shape, | ||
) | ||
try: | ||
results = [ | ||
QuantizationComparisonResult(actual=a, ref=b) | ||
for a, b in zip(actual_stats, ref_stats) | ||
# Only compare objects if they're both collections, or both single | ||
# tensors of the same shape. | ||
# TODO: use torch.fx.node.map_aggregate for the collection of | ||
# comparison results instead. | ||
if not isinstance(a, torch.Tensor) | ||
or not isinstance(b, torch.Tensor) | ||
or a.shape == b.shape | ||
Comment on lines
+340
to
+342
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also with this, some of the mismatches will be ignored, that's probably not what we want I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to ignore mismatches if they were comparing this of different types, or when the tensors have different shapes, because it's a problem with the debug handles at that point |
||
] | ||
except Exception as e: | ||
# Add extra information for an exception from QuantizationComparisonResult | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we raise exception here instead of ignore the error
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, because this type of error would typically indicate the debug handle was placed on the wrong nodes to compare before and after. Debug handles should always produce tensors of the same shape.
But debug handle errors should not prevent reporting of other accuracy errors, which an exception would do