Conversation
Previously relied on quantization logger, which caused logs to be suppressed when onnx.autocast was used directly Instead: - Inherit format and level if called from onnx.quantization - Configure independent format and level if called from onnx.autocast Signed-off-by: Gal Hubara Agam <96368689+galagam@users.noreply.github.com>
📝 WalkthroughWalkthroughRefactors the autocast logging configuration to use a hierarchical logger namespace ("modelopt.onnx.autocast") with conditional parent logger inheritance, centralized formatter application, and hybrid propagation logic supporting both standalone and parent-backed usage patterns. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@modelopt/onnx/autocast/logging_config.py`:
- Around line 32-50: The function configure_logging currently treats
level=logging.INFO as "not provided" which breaks explicit INFO uses; change the
signature of configure_logging to use level=None as the default, update the
docstring to state None means "inherit parent or default", and implement logic
in configure_logging so: if parent_logger has handlers and level is None then
set level = parent_logger.level, else if level is None set level = logging.INFO;
also preserve support for string level names by mapping strings to logging
constants before calling logger.setLevel(level) (reference configure_logging,
parent_logger, logger.setLevel).
🧹 Nitpick comments (1)
modelopt/onnx/autocast/logging_config.py (1)
87-91: Consider thatloggerDictmay containPlaceHolderentries.
logging.root.manager.loggerDictis a semi-private API and can containPlaceHolderobjects for intermediate namespace nodes. Callinglogging.getLogger(name)on line 90 safely returns a realLogger, but it also materializes placeholders into full loggers as a side effect. This is unlikely to cause issues in practice, but a defensive check would make the intent clearer:Optional: skip non-Logger entries
for name in logging.root.manager.loggerDict: - if name.startswith("modelopt.onnx.autocast"): - logging.getLogger(name).setLevel(level) + if name.startswith("modelopt.onnx.autocast"): + child = logging.root.manager.loggerDict[name] + if isinstance(child, logging.Logger): + child.setLevel(level)
| def configure_logging(level=logging.INFO, log_file=None): | ||
| """Configure logging for all AutoCast components. | ||
|
|
||
| Args: | ||
| level: The logging level to use (default: logging.INFO). | ||
| level: The logging level to use. Can be a string (e.g., "DEBUG", "INFO") or | ||
| a logging constant (e.g., logging.DEBUG). Default: logging.INFO. | ||
| log_file: Optional path to a log file. If provided, logs will be written to this file | ||
| in addition to stdout (default: None). | ||
| """ | ||
| # Set level for the parent logger and all child loggers | ||
| # Check if parent logger (modelopt.onnx) already has handlers configured | ||
| parent_logger = logging.getLogger("modelopt.onnx") | ||
| parent_has_handlers = len(parent_logger.handlers) > 0 | ||
|
|
||
| # If parent is configured and no explicit level provided, inherit parent's level | ||
| if parent_has_handlers and level == logging.INFO: | ||
| level = parent_logger.level | ||
|
|
||
| # Set level for the autocast logger (accepts both string and int) | ||
| logger.setLevel(level) |
There was a problem hiding this comment.
level == logging.INFO is an unreliable sentinel for "no level provided".
If a caller explicitly passes level=logging.INFO and the parent logger is set to DEBUG, this condition on line 46 will still be True, causing the autocast logger to unexpectedly inherit DEBUG instead of honoring the explicit INFO.
Use None as the default to distinguish "not provided" from "explicitly INFO":
Proposed fix
-def configure_logging(level=logging.INFO, log_file=None):
+def configure_logging(level=None, log_file=None):
"""Configure logging for all AutoCast components.
Args:
- level: The logging level to use. Can be a string (e.g., "DEBUG", "INFO") or
- a logging constant (e.g., logging.DEBUG). Default: logging.INFO.
+ level: The logging level to use. Can be a string (e.g., "DEBUG", "INFO") or
+ a logging constant (e.g., logging.DEBUG). Default: None (inherits from
+ parent logger if configured, otherwise logging.INFO).
log_file: Optional path to a log file. If provided, logs will be written to this file
in addition to stdout (default: None).
"""
# Check if parent logger (modelopt.onnx) already has handlers configured
parent_logger = logging.getLogger("modelopt.onnx")
parent_has_handlers = len(parent_logger.handlers) > 0
- # If parent is configured and no explicit level provided, inherit parent's level
- if parent_has_handlers and level == logging.INFO:
- level = parent_logger.level
+ # Resolve level: inherit from parent if available, otherwise default to INFO
+ if level is None:
+ if parent_has_handlers:
+ level = parent_logger.level
+ else:
+ level = logging.INFO📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def configure_logging(level=logging.INFO, log_file=None): | |
| """Configure logging for all AutoCast components. | |
| Args: | |
| level: The logging level to use (default: logging.INFO). | |
| level: The logging level to use. Can be a string (e.g., "DEBUG", "INFO") or | |
| a logging constant (e.g., logging.DEBUG). Default: logging.INFO. | |
| log_file: Optional path to a log file. If provided, logs will be written to this file | |
| in addition to stdout (default: None). | |
| """ | |
| # Set level for the parent logger and all child loggers | |
| # Check if parent logger (modelopt.onnx) already has handlers configured | |
| parent_logger = logging.getLogger("modelopt.onnx") | |
| parent_has_handlers = len(parent_logger.handlers) > 0 | |
| # If parent is configured and no explicit level provided, inherit parent's level | |
| if parent_has_handlers and level == logging.INFO: | |
| level = parent_logger.level | |
| # Set level for the autocast logger (accepts both string and int) | |
| logger.setLevel(level) | |
| def configure_logging(level=None, log_file=None): | |
| """Configure logging for all AutoCast components. | |
| Args: | |
| level: The logging level to use. Can be a string (e.g., "DEBUG", "INFO") or | |
| a logging constant (e.g., logging.DEBUG). Default: None (inherits from | |
| parent logger if configured, otherwise logging.INFO). | |
| log_file: Optional path to a log file. If provided, logs will be written to this file | |
| in addition to stdout (default: None). | |
| """ | |
| # Check if parent logger (modelopt.onnx) already has handlers configured | |
| parent_logger = logging.getLogger("modelopt.onnx") | |
| parent_has_handlers = len(parent_logger.handlers) > 0 | |
| # Resolve level: inherit from parent if available, otherwise default to INFO | |
| if level is None: | |
| if parent_has_handlers: | |
| level = parent_logger.level | |
| else: | |
| level = logging.INFO | |
| # Set level for the autocast logger (accepts both string and int) | |
| logger.setLevel(level) |
🤖 Prompt for AI Agents
In `@modelopt/onnx/autocast/logging_config.py` around lines 32 - 50, The function
configure_logging currently treats level=logging.INFO as "not provided" which
breaks explicit INFO uses; change the signature of configure_logging to use
level=None as the default, update the docstring to state None means "inherit
parent or default", and implement logic in configure_logging so: if
parent_logger has handlers and level is None then set level =
parent_logger.level, else if level is None set level = logging.INFO; also
preserve support for string level names by mapping strings to logging constants
before calling logger.setLevel(level) (reference configure_logging,
parent_logger, logger.setLevel).
| parent_has_handlers = len(parent_logger.handlers) > 0 | ||
|
|
||
| # If parent is configured and no explicit level provided, inherit parent's level | ||
| if parent_has_handlers and level == logging.INFO: |
There was a problem hiding this comment.
Do we need to check level == logging.INFO or should we just propagate the parent's level?
What does this PR do?
Type of change: Bug fix
Overview:
Previously relied on quantization logger, which caused logs to be suppressed when onnx.autocast was used directly
Instead:
Before your PR is "Ready for review"
Additional Information
Summary by CodeRabbit
Bug Fixes
Chores