Logging Utilities¶
fusion_bench.utils.rich_utils
¶
display_available_styles()
¶
Display all available styles in a grid.
Source code in fusion_bench/utils/rich_utils.py
enforce_tags(cfg, save_to_file=False)
¶
Prompts user to input tags from command line if no tags are provided in config.
:param cfg: A DictConfig composed by Hydra.
:param save_to_file: Whether to export tags to the hydra output folder. Default is False.
Source code in fusion_bench/utils/rich_utils.py
get_syntax_theme()
¶
Return (theme_name, background_color) suited to the current terminal.
Use this instead of hard-coding "monokai" when creating
:class:rich.syntax.Syntax objects.
Source code in fusion_bench/utils/rich_utils.py
print_bordered(message, title=None, style='blue', code_style=None, *, expand=True, theme=None, background_color='default', print_fn=print, format_code=True)
¶
Print a message with a colored border.
Parameters:
-
message(str) –The message to print.
-
title(str, default:None) –The title of the panel. Defaults to None.
-
style(str, default:'blue') –The color style for the border. Defaults to "cyan".
-
code_style(str, default:None) –The syntax highlighting style if the message is code. Set to None for plain text. Defaults to "python".
-
theme(str, default:None) –Syntax highlighting theme. Defaults to auto-detection based on terminal background (dark theme for dark terminals, light theme for light terminals).
Source code in fusion_bench/utils/rich_utils.py
print_code(message, title=None, code_style=None, *, expand=True, theme=None, background_color='default', print_fn=print)
¶
Print code or plain text with optional syntax highlighting.
Parameters:
-
message(str) –The message or code to print.
-
title(str, default:None) –Optional title associated with this output. Currently not used by this function, but kept for API compatibility. Defaults to None.
-
code_style(str, default:None) –The language/lexer name for syntax highlighting (for example,
"python"). IfNone, the message is rendered as plain text without syntax highlighting. Defaults toNone. -
expand(bool, default:True) –Placeholder flag for API symmetry with other printing helpers. It is not used in the current implementation. Defaults to True.
-
theme(str, default:None) –Name of the Rich syntax highlighting theme to use when
code_styleis provided. Defaults to auto-detection based on terminal background. -
background_color(str, default:'default') –Background color style to apply to the code block when using syntax highlighting. Defaults to
"default". -
print_fn(Callable, default:print) –Function used to render the resulting Rich object. Defaults to :func:
rich.print.
Source code in fusion_bench/utils/rich_utils.py
print_config_tree(cfg, print_order=('data', 'model', 'callbacks', 'logger', 'trainer', 'path', 'extras'), resolve=False, save_to_file=False, *, theme=None, background_color='default')
¶
Prints the contents of a DictConfig as a tree structure using the Rich library.
Parameters:
-
cfg(DictConfig) –A DictConfig composed by Hydra.
-
print_order(Sequence[str], default:('data', 'model', 'callbacks', 'logger', 'trainer', 'path', 'extras')) –Determines in what order config components are printed. Defaults to
("data", "model", "callbacks", "logger", "trainer", "paths", "extras"). -
resolve(bool, default:False) –Whether to resolve reference fields of DictConfig. Defaults to
False. -
save_to_file(bool, default:False) –Whether to export config to the hydra output folder. Defaults to
False. -
theme(str, default:None) –The theme to use for syntax highlighting. Defaults to auto-detection based on terminal background.
-
background_color(str, default:'default') –The background color to use for syntax highlighting. Defaults to "default".
Returns:
-
None–None
Source code in fusion_bench/utils/rich_utils.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
print_config_yaml(cfg, resolve=False, output_path=False, *, theme=None, background_color='default')
¶
Prints the contents of a DictConfig as a YAML string using the Rich library.
Parameters:
-
cfg(DictConfig) –A DictConfig composed by Hydra.
-
resolve(bool, default:False) –Whether to resolve reference fields of DictConfig. Default is
False. -
output_path(Optional[str], default:False) –Optional path to export the config YAML to. If provided, the file is written to this path.
-
theme(str, default:None) –The theme to use for syntax highlighting. Defaults to auto-detection based on terminal background.
Source code in fusion_bench/utils/rich_utils.py
setup_colorlogging(force=False, level=logging.INFO, **kwargs)
¶
Sets up color logging for the application.
Source code in fusion_bench/utils/rich_utils.py
fusion_bench.utils.pylogger
¶
RankZeroLogger
¶
Bases: Logger
A logger that logs only on rank zero and works just like logging.Logger
Source code in fusion_bench/utils/pylogger.py
RankedLogger
¶
Bases: LoggerAdapter
A multi-GPU-friendly python command line logger.
Source code in fusion_bench/utils/pylogger.py
__init__(name=__name__, rank_zero_only=False, extra=None)
¶
Initializes a multi-GPU-friendly python command line logger that logs on all processes with their rank prefixed in the log message.
:param name: The name of the logger. Default is __name__.
:param rank_zero_only: Whether to force all logs to only occur on the rank zero process. Default is False.
:param extra: (Optional) A dict-like object which provides contextual information. See logging.LoggerAdapter.
Source code in fusion_bench/utils/pylogger.py
log(level, msg, rank=None, *args, **kwargs)
¶
Delegate a log call to the underlying logger, after prefixing its message with the rank
of the process it's being logged from. If 'rank' is provided, then the log will only
occur on that rank/process.
:param level: The level to log at. Look at logging.__init__.py for more information.
:param msg: The message to log.
:param rank: The rank to log at.
:param args: Additional args to pass to the underlying logging function.
:param kwargs: Any additional keyword args to pass to the underlying logging function.
Source code in fusion_bench/utils/pylogger.py
get_rankzero_logger(name=None)
¶
Return a logger with the specified name, creating it if necessary.
If no name is specified, return the root logger.