Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix add_config func is not called bug #613

Merged
merged 10 commits into from Oct 24, 2022
2 changes: 2 additions & 0 deletions mmengine/runner/runner.py
Expand Up @@ -389,6 +389,8 @@ def __init__(
self.message_hub = self.build_message_hub()
# visualizer used for writing log or visualizing all kinds of data
self.visualizer = self.build_visualizer(visualizer)
if self.cfg:
self.visualizer.add_config(self.cfg)

self._load_from = load_from
self._resume = resume
Expand Down
17 changes: 11 additions & 6 deletions mmengine/visualization/vis_backend.py
Expand Up @@ -354,17 +354,25 @@ class WandbVisBackend(BaseVisBackend):
updates the current metrics dict with the row argument
and metrics won't be saved until `wandb.log` is called
with `commit=True`. Default to True.
log_code_name: (str, optional) The name of code artifact.
zhouzaida marked this conversation as resolved.
Show resolved Hide resolved
By default, the artifact will be named
source-$PROJECT_ID-$ENTRYPOINT_RELPATH. See
`wandb docs <https://docs.wandb.ai/ref/python/run#log_code>`_
for details. Defaults to None.
New in version 0.3.0.
"""

def __init__(self,
save_dir: str,
init_kwargs: Optional[dict] = None,
define_metric_cfg: Optional[dict] = None,
commit: Optional[bool] = True):
commit: Optional[bool] = True,
log_code_name: Optional[str] = None):
super().__init__(save_dir)
self._init_kwargs = init_kwargs
self._define_metric_cfg = define_metric_cfg
self._commit = commit
self._log_code_name = log_code_name

def _init_env(self):
"""Setup env for wandb."""
Expand Down Expand Up @@ -404,11 +412,8 @@ def add_config(self, config: Config, **kwargs) -> None:
Args:
config (Config): The Config object
"""
cfg_path = os.path.join(self._wandb.run.dir, 'config.py')
config.dump(cfg_path)
# Files under run.dir are automatically uploaded,
# so no need to manually call save.
# self._wandb.save(cfg_path)
self._wandb.config.update(dict(config))
self._wandb.run.log_code(name=self._log_code_name)

@force_init_env
def add_image(self,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_visualizer/test_vis_backend.py
Expand Up @@ -206,7 +206,7 @@ def test_experiment(self):

def test_add_config(self):
cfg = Config(dict(a=1, b=dict(b1=[0, 1])))
wandb_vis_backend = WandbVisBackend('temp_dir')
wandb_vis_backend = WandbVisBackend('temp_dir', log_code_name='code')
_wandb = wandb_vis_backend.experiment
_wandb.run.dir = 'temp_dir'
wandb_vis_backend.add_config(cfg)
Expand Down