Download src/training/utils/logging.py from ThomasTheMaker/pico-decoder-tiny-experiments: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/ThomasTheMaker/pico-decoder-tiny-experiments/resolve/a1f100c9548202e80bd367f574ba4045706ee2ba/src/training/utils/logging.py
- Command line
-
hf download hf://ThomasTheMaker/pico-decoder-tiny-experiments@a1f100c9548202e80bd367f574ba4045706ee2ba/src/training/utils/logging.py
-
curl -L -o logging.py https://huggingface.co/ThomasTheMaker/pico-decoder-tiny-experiments/resolve/a1f100c9548202e80bd367f574ba4045706ee2ba/src/training/utils/logging.py
1.31 kB
| """ | |
| Miscellaneous logging utilities. | |
| """ | |
| from io import StringIO | |
| import yaml | |
| from lightning.fabric.utilities.rank_zero import rank_zero_only | |
| from rich.console import Console | |
| from rich.panel import Panel | |
| def pretty_print_yaml_config(logger, config: dict) -> None: | |
| """ | |
| Pretty print config with rich formatting. Assumes that the config is already saved as a | |
| dictionary - this can be done by calling `asdict` on the dataclass or loading in the config | |
| from a yaml file. | |
| NOTE: this function is only called on rank 0. | |
| Args: | |
| logger: Logger object to log the formatted output to. | |
| config: Dictionary containing the config to pretty print. | |
| """ | |
| # Create string buffer | |
| output = StringIO() | |
| console = Console(file=output, force_terminal=False) | |
| # Convert to YAML string first | |
| yaml_str = yaml.dump( | |
| config, default_flow_style=False, sort_keys=False, Dumper=yaml.SafeDumper | |
| ) | |
| # Create formatted panel | |
| panel = Panel( | |
| yaml_str, | |
| border_style="blue", | |
| padding=(0, 1), # Reduced padding | |
| expand=False, # Don't expand to terminal width | |
| ) | |
| # Print to buffer | |
| console.print(panel) | |
| # Log the formatted output | |
| for line in output.getvalue().splitlines(): | |
| logger.info(line) | |