-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
Replace deprecated logger.warn with warning #16876
Conversation
The documentation is not available anymore as the PR was closed or merged. |
@@ -269,7 +269,7 @@ def set_quantizer(name, mod, quantizer, k, v): | |||
assert hasattr(quantizer_mod, k) | |||
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!
@@ -306,7 +306,7 @@ def __init__(self, **kwargs): | |||
if self.id2label is not None: | |||
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
warn
which is functionally identical towarning
. Aswarn
is deprecated, please do not use it - usewarning
instead.