vwxyzjn / cleanrl

High-quality single file implementation of Deep Reinforcement Learning algorithms with research-friendly features (PPO, DQN, C51, DDPG, TD3, SAC, PPG)
http://docs.cleanrl.dev
Other
5.53k stars 631 forks source link

Adopt or not to adopt tensorboard native hyperparameters recording #184

Open vwxyzjn opened 2 years ago

vwxyzjn commented 2 years ago

Problem Description

The current way of adding hyperparameters is to do it via markdown text:

writer = SummaryWriter(f"runs/{run_name}")
writer.add_text(
    "hyperparameters",
    "|param|value|\n|-|-|\n%s" % ("\n".join([f"|{key}|{value}|" for key, value in vars(args).items()])),
)

It is however to use the tensorboard native hyperparameters plugin, which unfortunately also has ugly code... see https://github.com/pytorch/pytorch/issues/37738#issuecomment-1124497827

writer = SummaryWriter(f"runs/{run_name}")
from torch.utils.tensorboard.summary import hparams
exp, ssi, sei = hparams(vars(args), metric_dict={"charts/episodic_return": 0})   
writer.file_writer.add_summary(exp)                 
writer.file_writer.add_summary(ssi)                 
writer.file_writer.add_summary(sei)  

produces the following demo, which I guess is pretty cool

https://user-images.githubusercontent.com/5555347/167988018-50c94e3f-14bc-4af9-bebb-24e95d9cd2fb.mov

Checklist

CC @araffin and @Miffyli and who might be interested in this hidden feature.

araffin commented 2 years ago

You may have a look at https://github.com/DLR-RM/stable-baselines3/issues/428#issuecomment-1124815614 too