Skip to content
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

Assertion to check if fake tensors have leaked into python #1447

Merged
merged 3 commits into from
Oct 6, 2022
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
4 changes: 4 additions & 0 deletions torchdynamo/variables/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class GraphArg:
example: Any
is_unspecialized: bool

def __post_init__(self):
if isinstance(self.example, torch._subclasses.fake_tensor.FakeTensor):
raise AssertionError("Fake Tensor observed in TorchDynamo Fx graph inputs")

def load(self, tx):
return self.source.reconstruct(tx)

Expand Down
13 changes: 11 additions & 2 deletions torchdynamo/variables/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,17 @@ def call_getattr(
return obj.var_getattr(tx, name).add_options(options)
elif isinstance(obj, variables.TensorVariable) and name == "grad":
if source:
example_value = obj.proxy.node.meta["example_value"].grad
return VariableBuilder(tx, source)(example_value).add_options(options)
# We are going to be raising this tensor as grapharg. So, ensure
# that we have real grad value instead of fake tensor value.
# Walk through the inputs of the subgraph and find if we already
# have the original tensor stored in the graphargs.
for grapharg in tx.output.graphargs:
if grapharg.source == source.base:
example_value = grapharg.example.grad
return VariableBuilder(tx, source)(example_value).add_options(
options
)
unimplemented("tensor grad")
else:
unimplemented("tensor grad")
elif isinstance(
Expand Down