| """Logging utilities for Dynamo and Inductor. |
| |
| This module provides specialized logging functionality including: |
| - Step-based logging that prepends step numbers to log messages |
| - Progress bar management for compilation phases |
| - Centralized logger management for Dynamo and Inductor components |
| |
| The logging system helps track the progress of compilation phases and provides structured |
| logging output for debugging and monitoring. |
| """ |
|
|
| import itertools |
| import logging |
| from typing import Any, Callable |
|
|
| from torch.hub import _Faketqdm, tqdm |
|
|
|
|
| |
| disable_progress = True |
|
|
|
|
| |
| def get_loggers() -> list[logging.Logger]: |
| return [ |
| logging.getLogger("torch.fx.experimental.symbolic_shapes"), |
| logging.getLogger("torch._dynamo"), |
| logging.getLogger("torch._inductor"), |
| ] |
|
|
|
|
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
|
|
| _step_counter = itertools.count(1) |
|
|
| |
| |
| |
|
|
| if not disable_progress: |
| try: |
| import triton |
|
|
| num_steps = 3 |
| except ImportError: |
| num_steps = 2 |
| pbar = tqdm(total=num_steps, desc="torch.compile()", delay=0) |
|
|
|
|
| def get_step_logger(logger: logging.Logger) -> Callable[..., None]: |
| if not disable_progress: |
| pbar.update(1) |
| if not isinstance(pbar, _Faketqdm): |
| pbar.set_postfix_str(f"{logger.name}") |
|
|
| step = next(_step_counter) |
|
|
| def log(level: int, msg: str, **kwargs: Any) -> None: |
| if "stacklevel" not in kwargs: |
| kwargs["stacklevel"] = 2 |
| logger.log(level, "Step %s: %s", step, msg, **kwargs) |
|
|
| return log |
|
|