Why ml_logger¶
People use different tools for logging experimental results - Tensorboard, Wandb etc to name a few. Working with different collaborators, I will have to switch my logging tool with each new project. So I made this simple tool that provides a common interface to logging results to different loggers.
Installation¶
pip install "mllogger[all]"
If you want to use only the filesystem logger, use
pip install "mllogger"
Install from source
git clone git@github.com:shagunsodhani/ml-logger.gitcd ml-loggerpip install ".[all]"
Alternatively,
pip install "git+https://git@github.com/shagunsodhani/ml-logger.git@master#egg=ml_logger[all]"
If you want to use only the filesystem logger, use pip install . or
pip install "git+https://git@github.com/shagunsodhani/ml-logger.git@master#egg=ml_logger".
Use¶
Make a
logbook_config:from ml_logger import logbook as ml_logbook logbook_config = ml_logbook.make_config( logger_dir = <path to write logs>, wandb_config = <wandb config or None>, tensorboard_config = <tensorboard config or None>, mlflow_config = <mlflow config or None>)
The API for
make_configcan be accessed here.Make a
LogBookinstance:logbook = ml_logbook.LogBook(config = logbook_config)
Use the
logbookinstance:log = { "epoch": 1, "loss": 0.1, "accuracy": 0.2 } logbook.write_metric(log)
The API for
write_metriccan be accessed here.
Note¶
If you are writing to wandb, the
logmust have a key calledstep. If yourlogalready captures thestepbut as a different key (sayepoch), you can pass thewandb_key_mapargument (set as{epoch: step}). For more details, refer the documentation here.If you are writing to mlflow, the
logmust have a key calledstep. If yourlogalready captures thestepbut as a different key (sayepoch), you can pass themlflow_key_mapargument (set as{epoch: step}). For more details, refer the documentation here.If you are writing to tensorboard, the
logmust have a key calledmain_tagortagwhich acts as the data Identifier and another key calledglobal_step. These keys are described here. If yourlogalready captures these values but as different key (saymodeformain_tagandepochforglobal_step), you can pass thetensorboard_key_mapargument (set as{mode: main_tag, epoch: global_step}). For more details, refer the documentation here.
Dev Setup¶
pip install -e ".[dev]"Install pre-commit hooks
pre-commit installThe code is linted using:
blackflake8mypyisort
Tests can be run locally using
nox