MCPcopy
hub / github.com/huggingface/transformers / warn_once

Function warn_once

src/transformers/testing_utils.py:4318–4330  ·  view source on GitHub ↗

Log a warning message only once per unique message. Uses a global set to track messages that have already been logged to prevent duplicate warning messages from cluttering the output. Args: logger_instance: The logger instance to use for warning. msg: The warning messag

(logger_instance: logging.Logger, msg: str)

Source from the content-addressed store, hash-verified

4316
4317
4318def warn_once(logger_instance: logging.Logger, msg: str) -> None:
4319 """Log a warning message only once per unique message.
4320
4321 Uses a global set to track messages that have already been logged
4322 to prevent duplicate warning messages from cluttering the output.
4323
4324 Args:
4325 logger_instance: The logger instance to use for warning.
4326 msg: The warning message to log.
4327 """
4328 if msg not in _warn_once_logged:
4329 logger_instance.warning(msg)
4330 _warn_once_logged.add(msg)
4331
4332
4333# Named tuple for passing memory stats for logging

Callers

nothing calls this directly

Calls 2

warningMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected