Skip to content

Enable customizable logging backends and logger subclassing#208

Open
MarkusPorti wants to merge 2 commits into
leggedrobotics:mainfrom
MarkusPorti:custom_logger
Open

Enable customizable logging backends and logger subclassing#208
MarkusPorti wants to merge 2 commits into
leggedrobotics:mainfrom
MarkusPorti:custom_logger

Conversation

@MarkusPorti
Copy link
Copy Markdown

Implements changes proposed / discussed in #207

Summary

  • Introduces LogWriter, an ABC that defines the interface for logging backends.
  • Logger now accepts an optional writer: LogWriter constructor argument for injecting a custom backend (e.g. MLflow, a database) without touching the config.
  • OnPolicyRunner.__init__ adds Logger as possible type for log_dir parameter. Pass a path string for default behavior, or a pre-built Logger (or subclass) instance for full customization.
  • OnPolicyRunner.__init__ gets a new parameter writer. Pass a custom LogWriter to choose where the default logs are stored.
  • WandbSummaryWriter and NeptuneSummaryWriter now explicitly inherit from LogWriter, replacing ad-hoc logger_type string guards with isinstance checks throughout Logger.
  • LogWriter and Logger are exported from rsl_rl.utils.

Extension patterns

Custom backend (where data goes) — subclass LogWriter:

from rsl_rl.utils import LogWriter, Logger

class MLflowWriter(LogWriter):
    def add_scalar(self, tag, scalar_value, global_step):
        mlflow.log_metric(tag.replace("/", "."), scalar_value, step=global_step)
    def stop(self):
        mlflow.end_run()

runner = OnPolicyRunner(env, cfg, writer=MLflowWriter())

Custom metrics (what gets logged) — subclass Logger:

from rsl_rl.utils import Logger

class MyLogger(Logger):
    def log(self, it, start_it, total_it, ...):
        super().log(it, start_it, total_it, ...)
        self.writer.add_scalar("Custom/my_metric", compute_x(), it)

runner = OnPolicyRunner(env, cfg, log_dir=MyLogger(log_dir="/path", cfg=cfg, ...))

Backward compatibility

All existing usage (cfg["logger"] = "tensorboard"/"wandb"/"neptune", passing log_dir as a string) is unchanged.

- Inject own Logging implementation
- Inject own LogWriter implementation
@ClemensSchwarke
Copy link
Copy Markdown
Collaborator

Hi @MarkusPorti, thanks a lot for the PR! After reviewing it, I decided to go for a slightly different implementation in #211. I would really appreciate a quick review if you find the time :)

Cheers, Clemens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants