itwinai.loggersο
Abstraction layer for loggers.
- class itwinai.loggers.LogMixin[source]ο
Bases:
object- abstract log(item: Any | List[Any], identifier: str | List[str], kind: str = 'metric', step: int | None = None, batch_idx: int | None = None, **kwargs) None[source]ο
Log
itemwithidentifiername ofkindtype atsteptime step.- Parameters:
item (Union[Any, List[Any]]) β element to be logged (e.g., metric).
identifier (Union[str, List[str]]) β unique identifier for the element to log(e.g., name of a metric).
kind (str, optional) β type of the item to be logged. Must be one among the list of self.supported_types. Defaults to βmetricβ.
step (Optional[int], optional) β logging step. Defaults to None.
batch_idx (Optional[int], optional) β DataLoader batch counter (i.e., batch idx), if available. Defaults to None.
- class itwinai.loggers.Logger(savedir: str = 'mllogs', log_freq: int | Literal['epoch', 'batch'] = 'epoch')[source]ο
Bases:
LogMixinBase class for logger
- Parameters:
savedir (str, optional) β filesystem location where logs are stored. Defaults to βmllogsβ.
log_freq (Union[int, Literal['epoch', 'batch']], optional) β
how often should the logger fulfill calls to the log() method:
When set to βepochβ, the logger logs only if
batch_idxis not passed to thelogmethod.When an integer is given, the logger logs if
batch_idxis a multiple oflog_freq.When set to
'batch', the logger logs always.
Defaults to βepochβ.
- supported_types: List[str]ο
Supported logging βkindβs.
- savedir: str = Noneο
Location on filesystem where to store data.
- property log_freq: int | Literal['epoch', 'batch']ο
Get
log_feq, namely how often should the logger fulfill or ignore calls to the log() method.
- start_logging()[source]ο
Start logging context.
Example:
>>> with my_logger.start_logging(): >>> my_logger.log(123, 'value', kind='metric', step=0)
- abstract save_hyperparameters(params: Dict[str, Any]) None[source]ο
Save hyperparameters.
- Parameters:
params (Dict[str, Any]) β hyperparameters dictionary.
- serialize(obj: Any, identifier: str) str[source]ο
Serializes object to disk and returns its path.
- Parameters:
obj (Any) β item to save.
identifier (str) β identifier of the item to log (expected to be a path under
self.savedir).
- Returns:
local path of the serialized object to be logged.
- Return type:
str
- should_log(batch_idx: int | None = None) bool[source]ο
Determines whether the logger should fulfill or ignore calls to the log() method, depending on the
log_freqproperty:When
log_freqis set to βepochβ, the logger logs only ifbatch_idxis not passed to thelogmethod.When
log_freqis an integer is given, the logger logs ifbatch_idxis a multiple oflog_freq.When
log_freqis set to'batch', the logger logs always.
- Parameters:
batch_idx (Optional[int]) β the dataloader batch idx, if available. Defaults to None.
- Returns:
True if the logger should log, False otherwise.
- Return type:
bool
- class itwinai.loggers.ConsoleLogger(savedir: str = 'mllogs', log_freq: int | Literal['epoch', 'batch'] = 'epoch')[source]ο
Bases:
LoggerSimplified logger.
- Parameters:
savedir (str, optional) β where to store artifacts. Defaults to βmllogsβ.
log_freq (Union[int, Literal['epoch', 'batch']], optional) β determines whether the logger should fulfill or ignore calls to the log() method. See
Logger.should_logmethod for more details. Defaults to βepochβ.
- save_hyperparameters(params: Dict[str, Any]) None[source]ο
Save hyperparameters. Do nothing.
- Parameters:
params (Dict[str, Any]) β hyperparameters dictionary.
- log(item: Any | List[Any], identifier: str | List[str], kind: str = 'metric', step: int | None = None, batch_idx: int | None = None, **kwargs) None[source]ο
Print metrics to stdout and save artifacts to the filesystem.
- Parameters:
item (Union[Any, List[Any]]) β element to be logged (e.g., metric).
identifier (Union[str, List[str]]) β unique identifier for the element to log(e.g., name of a metric).
kind (str, optional) β type of the item to be logged. Must be one among the list of
self.supported_types. Defaults to βmetricβ.step (Optional[int], optional) β logging step. Defaults to None.
batch_idx (Optional[int], optional) β DataLoader batch counter (i.e., batch idx), if available. Defaults to None.
kwargs β keyword arguments to pass to the logger.
- class itwinai.loggers.MLFlowLogger(savedir: str = 'mllogs', experiment_name: str = 'default_experiment', tracking_uri: str | None = None, run_description: str | None = None, log_freq: int | Literal['epoch', 'batch'] = 'epoch')[source]ο
Bases:
LoggerAbstraction around MLFlow logger.
- Parameters:
savedir (str, optional) β path on local filesystem where logs are stored. Defaults to βmllogsβ.
experiment_name (str, optional) β experiment name. Defaults to
itwinai.loggers.BASE_EXP_NAME.tracking_uri (Optional[str], optional) β MLFLow tracking URI. Overrides
savedirif given. Defaults to None.run_description (Optional[str], optional) β run description. Defaults to None.
log_freq (Union[int, Literal['epoch', 'batch']], optional) β determines whether the logger should fulfill or ignore calls to the log() method. See
Logger.should_logmethod for more details. Defaults to βepochβ.
- active_run: mlflow.ActiveRunο
Current MLFLow experimentβs run.
- save_hyperparameters(params: Dict[str, Any]) None[source]ο
Save hyperparameters as MLFlow parameters.
- Parameters:
params (Dict[str, Any]) β hyperparameters dictionary.
- log(item: Any | List[Any], identifier: str | List[str], kind: str = 'metric', step: int | None = None, batch_idx: int | None = None, **kwargs) None[source]ο
Log with MLFlow.
- Parameters:
item (Union[Any, List[Any]]) β element to be logged (e.g., metric).
identifier (Union[str, List[str]]) β unique identifier for the element to log(e.g., name of a metric).
kind (str, optional) β type of the item to be logged. Must be one among the list of
self.supported_types. Defaults to βmetricβ.step (Optional[int], optional) β logging step. Defaults to None.
batch_idx (Optional[int], optional) β DataLoader batch counter (i.e., batch idx), if available. Defaults to None.
kwargs β keyword arguments to pass to the logger.
- class itwinai.loggers.WandBLogger(savedir: str = 'mllogs', project_name: str = 'default_experiment', log_freq: int | Literal['epoch', 'batch'] = 'epoch')[source]ο
Bases:
LoggerAbstraction around WandB logger.
- Parameters:
savedir (str, optional) β location on local filesystem where logs are stored. Defaults to βmllogsβ.
project_name (str, optional) β experiment name. Defaults to
itwinai.loggers.BASE_EXP_NAME.log_freq (Union[int, Literal['epoch', 'batch']], optional) β determines whether the logger should fulfill or ignore calls to the log() method. See
Logger.should_logmethod for more details. Defaults to βepochβ.
- save_hyperparameters(params: Dict[str, Any]) None[source]ο
Save hyperparameters.
- Parameters:
params (Dict[str, Any]) β hyperparameters dictionary.
- log(item: Any | List[Any], identifier: str | List[str], kind: str = 'metric', step: int | None = None, batch_idx: int | None = None, **kwargs) None[source]ο
Log with WandB. Wrapper of https://docs.wandb.ai/ref/python/log
- Parameters:
item (Union[Any, List[Any]]) β element to be logged (e.g., metric).
identifier (Union[str, List[str]]) β unique identifier for the element to log(e.g., name of a metric).
kind (str, optional) β type of the item to be logged. Must be one among the list of
self.supported_types. Defaults to βmetricβ.step (Optional[int], optional) β ignored by
WandBLogger.batch_idx (Optional[int], optional) β DataLoader batch counter (i.e., batch idx), if available. Defaults to None.
kwargs β keyword arguments to pass to the logger.
- class itwinai.loggers.TensorBoardLogger(savedir: str = 'mllogs', log_freq: int | Literal['epoch', 'batch'] = 'epoch', framework: Literal['tensorflow', 'pytorch'] = 'pytorch')[source]ο
Bases:
LoggerAbstraction around TensorBoard logger, both for PyTorch and TensorFlow.
- Parameters:
savedir (str, optional) β location on local filesystem where logs are stored. Defaults to βmllogsβ.
log_freq (Union[int, Literal['epoch', 'batch']], optional) β determines whether the logger should fulfill or ignore calls to the log() method. See
Logger.should_logmethod for more details. Defaults to βepochβ.framework (Literal['tensorflow', 'pytorch'], optional) β whether to log PyTorch or TensorFlow ML data. Defaults to βpytorchβ.
- Raises:
ValueError β when
frameworkis not recognized.
- save_hyperparameters(params: Dict[str, Any]) None[source]ο
Save hyperparameters.
- Parameters:
params (Dict[str, Any]) β hyperparameters dictionary.
- log(item: Any | List[Any], identifier: str | List[str], kind: str = 'metric', step: int | None = None, batch_idx: int | None = None, **kwargs) None[source]ο
Log with Tensorboard.
- Parameters:
item (Union[Any, List[Any]]) β element to be logged (e.g., metric).
identifier (Union[str, List[str]]) β unique identifier for the element to log(e.g., name of a metric).
kind (str, optional) β type of the item to be logged. Must be one among the list of
self.supported_types. Defaults to βmetricβ.step (Optional[int], optional) β logging step. Defaults to None.
batch_idx (Optional[int], optional) β DataLoader batch counter (i.e., batch idx), if available. Defaults to None.
kwargs β keyword arguments to pass to the logger.
- class itwinai.loggers.LoggersCollection(loggers: List[Logger])[source]ο
Bases:
LoggerWrapper of a set of loggers, allowing to use them simultaneously.
- Parameters:
loggers (List[Logger]) β list of itwinai loggers.
- should_log(batch_idx: int | None = None) bool[source]ο
Transparent method which delegates the Logger.should_log` to individual loggers. Always returns True.
- Parameters:
batch_idx (int, optional) β dataloader batch index.
None. (Defaults to) β
- Returns:
always True.
- Return type:
bool
- log(item: Any | List[Any], identifier: str | List[str], kind: str = 'metric', step: int | None = None, batch_idx: int | None = None, **kwargs) None[source]ο
Log on all loggers.
- Parameters:
item (Union[Any, List[Any]]) β element to be logged (e.g., metric).
identifier (Union[str, List[str]]) β unique identifier for the element to log(e.g., name of a metric).
kind (str, optional) β type of the item to be logged. Must be one among the list of
self.supported_types. Defaults to βmetricβ.step (Optional[int], optional) β logging step. Defaults to None.
batch_idx (Optional[int], optional) β DataLoader batch counter (i.e., batch idx), if available. Defaults to None.
kwargs β keyword arguments to pass to the logger.
- class itwinai.loggers.EpochTimeTracker(series_name: str, csv_file: str)[source]ο
Bases:
objectProfiler for epoch execution time used to support scaling tests. It uses CSV files to store, for each epoch, the
nameof the experiment, the number of computenodesused, theepoch_id, and the executiontimein seconds.- Parameters:
series_name (str) β name of the experiment/job.
csv_file (str) β path to CSV file to store experiments times.