From e2bc3800afb23c2323ada88d5bf79a9ef5f8c929 Mon Sep 17 00:00:00 2001 From: Animesh Jain Date: Wed, 22 May 2024 18:18:52 -0700 Subject: [PATCH] Update base for Update on "[wip] Improve exception support" cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang [ghstack-poisoned] --- torch/_dynamo/variables/tensor.py | 2 +- torch/_dynamo/variables/user_defined.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/torch/_dynamo/variables/tensor.py b/torch/_dynamo/variables/tensor.py index a1adbcf614bca..0b3c554f2a87e 100644 --- a/torch/_dynamo/variables/tensor.py +++ b/torch/_dynamo/variables/tensor.py @@ -363,7 +363,7 @@ def var_getattr(self, tx, name): # For attributes (not methods) that were not caught in the special handling above, # (e.g. tensor.real), we handle these generically, assuming that the output type is # a tensor. - if result is None and name != "grad": + if result is None and name not in ("grad", "grad_fn"): def try_generic_attr_handling(): from .builder import wrap_fx_proxy diff --git a/torch/_dynamo/variables/user_defined.py b/torch/_dynamo/variables/user_defined.py index c23298aa0ff61..2bf7bfc1fdd14 100644 --- a/torch/_dynamo/variables/user_defined.py +++ b/torch/_dynamo/variables/user_defined.py @@ -834,6 +834,10 @@ def var_getattr(self, tx, name): if tx.output.side_effects.has_pending_mutation_of_attr(self, name): return tx.output.side_effects.load_attr(self, name) + if name == "__dict__": + options = {"source": source} + return variables.GetAttrVariable(self, name, **options) + try: subobj = self._getattr_static(name) except AttributeError: