ablator.modules.loggers package#
Submodules#
ablator.modules.loggers.file module#
- class ablator.modules.loggers.file.FileLogger(path: str | Path | None = None, verbose: bool = True, prefix: str | None = None)[source]#
Bases:
objectA logger that writes messages to a file and prints them to the console.
- Parameters:
- pathstr | Path | None
Path to the log file, by default
None.- verbosebool
Whether to print messages to the console, by default
True.- prefixstr | None
A prefix to add to each logged message, by default
None.
- Attributes:
- WARNINGstr
ANSI escape code for the warning text color.
- FAILstr
ANSI escape code for the error text color.
- ENDCstr
ANSI escape code for resetting the text color.
- ENDC: str = '\x1b[0m'#
- FAIL: str = '\x1b[91m'#
- WARNING: str = '\x1b[93m'#
- error(msg: str) str[source]#
Log an error message.
- Parameters:
- msgstr
The message to log.
- Returns:
- str
the formated string message
- info(msg: str, verbose: bool = False) str[source]#
Log an info message.
- Parameters:
- msgstr
The message to log.
- verbosebool
Whether to print messages to the console, by default
False.
- Returns:
- str
the formated string message
- set_path(path: str | Path)[source]#
Set the path to the log file.
- Parameters:
- pathstr | Path
The path to the log file.
- class ablator.modules.loggers.file.RemoteFileLogger(path: str | Path | None = None, verbose: bool = True, prefix: str | None = None)[source]#
Bases:
FileLogger- set_path(path: str | Path)[source]#
Set the path to the log file.
- Parameters:
- pathstr | Path
The path to the log file.
ablator.modules.loggers.main module#
- class ablator.modules.loggers.main.SummaryLogger(run_config: RunConfig, experiment_dir: str | Path | None = None, resume: bool = False, keep_n_checkpoints: int | None = None, verbose: bool = True)[source]#
Bases:
objectA logger for training and evaluation summary.
- Parameters:
- run_configRunConfig
The run configuration.
- experiment_dirstr | None | Path
Path to the trial directory, by default
None.- resumebool
Whether to resume from an existing model directory, by default
False.- keep_n_checkpointsint | None
Number of checkpoints to keep, by default
None.- verbosebool
Whether to print messages to the console, by default
True.
- Raises:
- FileExistsError
If resume is set to
Falsebut the experiment directory already exists.
- Attributes:
- SUMMARY_DIR_NAMEstr
Name of the summary directory.
- RESULTS_JSON_NAMEstr
Name of the results JSON file.
- LOG_FILE_NAMEstr
Name of the log file.
- CONFIG_FILE_NAMEstr
Name of the configuration file.
- METADATA_JSONstr
Name of the metadata JSON file.
- CHKPT_DIR_NAMESlist[str]
List of checkpoint directory names.
- CHKPT_DIR_VALUESlist[str]
List of checkpoint directory values.
- CHKPT_DIRSdict[str, Path]
Dictionary containing checkpoint directories.
- keep_n_checkpointsint
Number of checkpoints to keep.
- log_iterationint
Current log iteration.
- checkpoint_iterationdict[str, dict[str, int]]
checkpoint_iterationis a dictionary that keeps track of the checkpoint iterations for each directory. It is used in thecheckpoint()method to determine the appropriate iteration number for the saved checkpoint.- log_file_pathPath | None
Path to the log file.
- dashboardLoggerBase | None
Dashboard logger.
- experiment_dirPath | None
the trial directory.
- result_json_pathPath | None
Path to the results JSON file.
- BACKUP_CONFIG_FILE_NAME: str = 'config_backup_{i}.yaml'#
- CHKPT_DIRS: dict[str, pathlib.Path]#
- CHKPT_DIR_NAMES: list[str] = ['best', 'recent']#
- CHKPT_DIR_VALUES: list[str] = ['best_checkpoints', 'checkpoints']#
- CONFIG_FILE_NAME: str = 'config.yaml'#
- LOG_FILE_NAME: str = 'train.log'#
- METADATA_JSON: str = 'metadata.json'#
- RESULTS_JSON_NAME: str = 'results.json'#
- SUMMARY_DIR_NAME: str = 'dashboard'#
- checkpoint(save_dict: object, file_name: str, itr: int | None = None, is_best: bool = False)[source]#
Save a checkpoint and update the checkpoint iteration
Saves the model checkpoint in the appropriate directory based on the
is_bestparameter. Ifis_best==True, the checkpoint is saved in the"best"directory, indicating the best performing model so far. Otherwise, the checkpoint is saved in the"recent"directory, representing the most recent checkpoint.The file path for the checkpoint is constructed using the selected directory name (
"best"or"recent"), and the file name with the format"{file_name}_{itr:010}.pt", whereitris the iteration number.The
checkpoint_iterationdictionary is updated with the current iteration number for each directory. Ifitris not provided, the iteration number is increased by 1 each time a checkpoint is saved. Otherwise, the iteration number is set to the provideditr.- Parameters:
- save_dictobject
The object to save.
- file_namestr
The file name.
- itrint | None
The iteration. If not provided, the current iteration is incremented by 1, by default
None.- is_bestbool
Whether this is the best checkpoint, by default
False.
- clean_checkpoints(keep_n_checkpoints: int)[source]#
Clean up checkpoints and keep only the specified number of checkpoints.
- Parameters:
- keep_n_checkpointsint
Number of checkpoints to keep.
- error(*args: Any, **kwargs: Any)[source]#
Log an error message to files and to console using the logger. Here you can use positional or keyword arguments. Possible parameters are shown in the Parameters section.
- Parameters:
- msgstr
The message to log.
- info(*args: Any, **kwargs: Any)[source]#
Log an info to files and to console message using the logger. Here you can use positional or keyword arguments. Possible parameters are shown in the Parameters section.
- Parameters:
- msgstr
The message to log,
- verbosebool
Whether to print messages to the console, by default
False.
- update(metrics: Metrics | dict, itr: int | None = None)[source]#
Update the dashboard with the given metrics. write some metrics to json files and update the current metadata (
log_iteration)- Parameters:
- metricsUnion[Metrics, dict]
The metrics to update.
- itrOptional[int]
The iteration, by default
None.
- Raises:
- AssertionError
If the iteration is not greater than the current iteration.
Notes
Attribute
log_iterationis increased by 1 every timeupdate()is called while training models.
- warn(*args: Any, **kwargs: Any)[source]#
Log a warning message to files and to console using the logger. Here you can use positional or keyword arguments. Possible parameters are shown in the Parameters section.
- Parameters:
- msgstr
The message to log,
- verbosebool
Whether to print messages to the console, by default
True.
ablator.modules.loggers.tensor module#
- class ablator.modules.loggers.tensor.TensorboardLogger(summary_dir: str | Path)[source]#
Bases:
LoggerBaseA logger class for Tensorboard visualization.
- Parameters:
- summary_dirUnion[str, Path]
The directory to store the Tensorboard summary files.
- Attributes:
- summary_dirUnion[str, Path]
The directory to store the Tensorboard summary files.
- backend_loggerSummaryWriter
The PyTorch Tensorboard SummaryWriter object used to log data.
- add_image(k: str, v: ndarray, itr: int, dataformats: str | None = 'CHW')[source]#
Add an image to the TensorBoard dashboard.
- Parameters:
- kstr
The tag associated with the image.
- vnp.ndarray
The image data.
- itrint
The iteration number.
- dataformatsty.Optional[str]
The format of the image data, by default
"CHW".
- add_scalar(k: str, v: float | int, itr: int)[source]#
Add a scalar to the TensorBoard dashboard.
- Parameters:
- kstr
The tag associated with the scalar.
- vfloat | int
The scalar value.
- itrint
The iteration number.
- add_scalars(k: str, v: dict[str, float | int], itr: int)[source]#
Add multiple scalars to the TensorBoard dashboard.
- Parameters:
- kstr
The main tag associated with the scalars.
- vdict[str, float | int]
A dictionary of scalar tags and values.
- itrint
The iteration number.
- add_table(k: str, v: DataFrame, itr: int)[source]#
Add a table to the TensorBoard dashboard.
- Parameters:
- kstr
The tag associated with the table.
- vpd.DataFrame
The table data.
- itrint
The iteration number.
- add_text(k: str, v: str, itr: int)[source]#
Add a text to the TensorBoard dashboard.
- Parameters:
- kstr
The tag associated with the text.
- vstr
The text data.
- itrint
The iteration number.
- write_config(config: ConfigBase)[source]#
Write the configuration to the TensorBoard dashboard.
- Parameters:
- configConfigBase
The configuration object.
Module contents#
- class ablator.modules.loggers.LoggerBase[source]#
Bases:
ABC- abstract write_config(config: ConfigBase)[source]#
- class ablator.modules.loggers.LoggerConfig(*args: Any, debug: bool = False, **kwargs: Any)[source]#
Bases:
ConfigBase- config_class#
alias of
LoggerConfig