mmcv icon indicating copy to clipboard operation
mmcv copied to clipboard

Wandb save `.py` config file ealier

Open doem97 opened this issue 2 years ago • 3 comments

I suggest to upload .py artifacts earlier.

Motivation The WandbLoggerHook saves .py config only after training. However, people always stop earlier, in which case the config file is unavailable.

Related resources https://github.com/open-mmlab/mmcv/blob/ea173c9f07f0abf6873d2b7d786fb6411843cf00/mmcv/runner/hooks/logger/wandb.py#L100

Additional context I suggest to add such changes to WandbLoggerHook.before_run():

class WandbLoggerHook():
    def before_run(self, runner):
        ...
        if self.log_artifact:
            wandb_artifact = self.wandb.Artifact(name="artifacts", type="model")
            if ".py" in self.out_suffix:
                for filename in scandir(runner.work_dir, ".py", True):
                    local_filepath = osp.join(runner.work_dir, filename)
                    wandb_artifact.add_file(local_filepath)
            self.wandb.log_artifact(wandb_artifact)

doem97 avatar Jul 18 '22 13:07 doem97

Another option: pass the config dict to wandb.config, and let wandb update dict configs automatically (ref). Two ways to do so:

  1. pass cfg to WandbLoggerHook.before_run() (reference: #1773 )
# in runner/hooks/logger/wandb.py
class WandbLoggerHook():
    def before_run(self, runner):
        self.wandb.config = runner.cfg
  1. save cfg in tools/train.py (reference: open-mmlab/mmsegmentation#1750)
# in tools/train.py
for hook in cfg.log_config.hooks:
    if hook['type'] == 'MMSegWandbHook':
        hook['init_kwargs'].update({'config': cfg._cfg_dict.to_dict()})

doem97 avatar Jul 18 '22 13:07 doem97

Thanks for your feedback~ I think it is a reasonable requirement. We may invite @hhaAndroid to have a look.

HAOCHENYE avatar Jul 19 '22 03:07 HAOCHENYE

Hi, I think this format may be more proper. image It could be better to only modify the code of WandbLoggerHook. We can refer to the implementation of mmdet: https://github.com/open-mmlab/mmdetection/blob/master/mmdet/core/hook/wandblogger_hook.py#L134

HAOCHENYE avatar Jul 19 '22 03:07 HAOCHENYE