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

Add logging for NO_SUCH_SUBOBJ #125410

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions torch/_dynamo/variables/user_defined.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import threading
import types
import warnings
import logging

from typing import Dict, Generic, List

Expand Down Expand Up @@ -56,6 +57,9 @@
from .dicts import DefaultDictVariable


log = logging.getLogger(__name__)


def is_standard_setattr(val):
return val in (
object.__setattr__,
Expand Down Expand Up @@ -828,6 +832,7 @@ def var_getattr(self, tx, name):
subobj = self._getattr_static(name)
except AttributeError:
subobj = NO_SUCH_SUBOBJ
log.warning(f"NO_SUCH_SUBOBJ: {self.value} {name}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just log the exception with logging.exception?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More user-facing? e.g. "Attribute {name} does not exist on {self.value}, falling back to NO_SUCH_SUBOBJ"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add the log of self.value.__class__?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem like something we should warn on. This is valid user code:

try:
   x = foo.x
except AttributeError:
   x = None

It would be super annoying to emit a warning for this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's pass exc_info=True too to get the full exception stack trace + exception object.

getattr_fn = self._check_for_getattr()
if isinstance(getattr_fn, types.FunctionType):
return variables.UserMethodVariable(
Expand Down