mmcv
mmcv copied to clipboard
Wandb save `.py` config file ealier
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)
Another option: pass the config dict to wandb.config, and let wandb update dict configs automatically (ref). Two ways to do so:
- 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
- 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()})
Thanks for your feedback~ I think it is a reasonable requirement. We may invite @hhaAndroid to have a look.
Hi, I think this format may be more proper.
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