[Dynamo] Fix inspect.getattr_static doesn't work well for torch.utils._cxx_pytree.PyTreeSpec (#120812)

Fixes #118793

Pull Request resolved: https://github.com/pytorch/pytorch/pull/120812
Approved by: https://github.com/zou3519
This commit is contained in:
Yanbo Liang
2024-03-05 09:05:20 +00:00
committed by PyTorch MergeBot
parent 311cc564f6
commit 46c9d646dd
12 changed files with 6 additions and 1 deletions

View File

@ -19,6 +19,11 @@ try:
except ModuleNotFoundError:
np = None
try:
from torch.utils._cxx_pytree import PyTreeSpec
except ImportError:
PyTreeSpec = type(None)
import torch._dynamo.config
import torch.nn
@ -697,7 +702,7 @@ class UserDefinedObjectVariable(UserDefinedVariable):
def _getattr_static(self, name):
if (
isinstance(self.value, torch.nn.Module)
isinstance(self.value, (torch.nn.Module, PyTreeSpec))
or "__slots__" in self.value.__class__.__dict__
or type(self.value) == threading.local
):