Skip to content

Commit

Permalink
Beef up error message for pending assert failure (pytorch#126212)
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Z. Yang <ezyang@meta.com>
Pull Request resolved: pytorch#126212
Approved by: https://github.com/Skylion007
  • Loading branch information
ezyang authored and ZelboK committed May 19, 2024
1 parent 0f2db1c commit 6b733b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2796,6 +2796,7 @@
"ConstraintViolationError",
"DynamicDimConstraintPrinter",
"GuardOnDataDependentSymNode",
"PendingUnbackedSymbolNotFound",
"LoggingShapeGuardPrinter",
"RelaxedUnspecConstraint",
"RuntimeAssert",
Expand Down
23 changes: 15 additions & 8 deletions torch/fx/experimental/symbolic_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
class GuardOnDataDependentSymNode(RuntimeError):
pass

class PendingUnbackedSymbolNotFound(RuntimeError):
pass

import sympy
from sympy.printing.str import StrPrinter
from sympy.printing.precedence import precedence, PRECEDENCE
Expand Down Expand Up @@ -602,15 +605,19 @@ def free_unbacked_symbols_with_path(
return r

symbol_to_path = free_unbacked_symbols_with_path(example_value, ())
if not peek:
assert not pending, (
f"pending {pending} not in {example_value} " +
(
repr((example_value.stride(), example_value.storage_offset()))
if isinstance(example_value, torch.Tensor)
else ""
)
if not peek and pending:
extra = (
repr((example_value.stride(), example_value.storage_offset()))
if isinstance(example_value, torch.Tensor)
else ""
)
raise PendingUnbackedSymbolNotFound(
f"Pending unbacked symbols {pending} not in returned outputs {example_value} {extra}.\n"
"Did you accidentally call new_dynamic_size() or item() more times "
"than you needed to in your fake implementation?\n"
"For more help, see https://docs.google.com/document/d/1RWrH-3wLEpzR9kCS6gGBNen_-Fs-8PVbWWFE5AcgeWE/edit"
)

# Why do we have to do some rebinding here? If the original FX node
# wasn't a binding site because you had a memo hit, but post
# translation you aren't a memo hit anymore, there's now a new binding
Expand Down

0 comments on commit 6b733b2

Please sign in to comment.