-
Notifications
You must be signed in to change notification settings - Fork 30.9k
Replace deprecated logger.warn with warning #16876
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
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
| setattr(quantizer_mod, k, v) | ||
| else: | ||
| logger.warn(f"{name} has no {quantizer}") | ||
| logger.warning(f"{name} has no {quantizer}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we don't actively maintain those ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Just covering all grounds!
| num_labels = kwargs.pop("num_labels", None) | ||
| if num_labels is not None and len(self.id2label) != num_labels: | ||
| logger.warn( | ||
| logger.warning( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's our internal logger here no - not Python's logger. So not sure about this change @LysandreJik
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logging module imported in this script is indeed our internal logging module that lives under the utils directory. We see here that the logger is instantiated by invoking the get_logger function from this module:
| logger = logging.get_logger(__name__) |
If we inspect the internal logging module in utils, we see that it first imports the Python logging module:
| import logging |
The
get_logger function simply returns the getLogger function from this Python logging module:transformers/src/transformers/utils/logging.py
Lines 113 to 124 in 72728be
| def get_logger(name: Optional[str] = None) -> logging.Logger: | |
| """ | |
| Return a logger with the specified name. | |
| This function is not supposed to be directly accessed unless you are writing a custom transformers module. | |
| """ | |
| if name is None: | |
| name = _get_library_name() | |
| _configure_library_root_logger() | |
| return logging.getLogger(name) |
Hence, our internal logger is implicitly derived from its parent Python logger, and is simply a wrapper for this module. Consequently, the advice regarding the use of warning in place of warn should still hold.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Referring to @LysandreJik here :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's a good change!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks @sanchit-gandhi!
From Python docs:
There is an obsolete method
warnwhich is functionally identical towarning. Aswarnis deprecated, please do not use it - usewarninginstead.