We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Bug feedback.
Thanks for your codes. 
In [mmcv/runner/base_runner](https://github.com/open-mmlab/mmcv/blob/master/mmcv/runner/base_runner.py#L385), 
`    def register_logger_hooks(self, log_config):
        log_interval = log_config['interval']
        for info in log_config['hooks']:
            logger_hook = mmcv.build_from_cfg(
                info, HOOKS, default_args=dict(interval=log_interval))
            self.register_hook(logger_hook, priority='VERY_LOW')
`
.
Only the argument 'interval' in log_config is fed into logger_hook. However, the argument 'by_epoch' is ignored, always true, so that if iter_based_runner is used, the logger will work unexpectedly. 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mmcv/runner/iter_based_runner.py`
Content:
```
1 # Copyright (c) Open-MMLab. All rights reserved.
2 import os.path as osp
3 import time
4 
5 import torch
6 from torch.optim import Optimizer
7 
8 import mmcv
9 from .base_runner import BaseRunner
10 from .checkpoint import save_checkpoint
11 from .hooks import IterTimerHook
12 from .utils import get_host_info
13 
14 
15 class IterLoader:
16 
17     def __init__(self, dataloader):
18         self._dataloader = dataloader
19         self.iter_loader = iter(self._dataloader)
20         self._epoch = 0
21 
22     @property
23     def epoch(self):
24         return self._epoch
25 
26     def __next__(self):
27         try:
28             data = next(self.iter_loader)
29         except StopIteration:
30             self._epoch += 1
31             if hasattr(self._dataloader.sampler, 'set_epoch'):
32                 self._dataloader.sampler.set_epoch(self._epoch)
33             self.iter_loader = iter(self._dataloader)
34             data = next(self.iter_loader)
35 
36         return data
37 
38     def __len__(self):
39         return len(self._dataloader)
40 
41 
42 class IterBasedRunner(BaseRunner):
43     """Iteration-based Runner.
44 
45     This runner train models iteration by iteration.
46     """
47 
48     def train(self, data_loader, **kwargs):
49         self.model.train()
50         self.mode = 'train'
51         self.data_loader = data_loader
52         self._epoch = data_loader.epoch
53         self.call_hook('before_train_iter')
54         data_batch = next(data_loader)
55         outputs = self.model.train_step(data_batch, self.optimizer, **kwargs)
56         if not isinstance(outputs, dict):
57             raise TypeError('model.train_step() must return a dict')
58         if 'log_vars' in outputs:
59             self.log_buffer.update(outputs['log_vars'], outputs['num_samples'])
60         self.outputs = outputs
61         self.call_hook('after_train_iter')
62         self._inner_iter += 1
63         self._iter += 1
64 
65     def val(self, data_loader, **kwargs):
66         self.model.eval()
67         self.mode = 'val'
68         self.data_loader = data_loader
69         self.call_hook('before_val_iter')
70         data_batch = next(data_loader)
71         outputs = self.model.val_step(data_batch, **kwargs)
72         if not isinstance(outputs, dict):
73             raise TypeError('model.val_step() must return a dict')
74         if 'log_vars' in outputs:
75             self.log_buffer.update(outputs['log_vars'], outputs['num_samples'])
76         self.outputs = outputs
77         self.call_hook('after_val_iter')
78         self._inner_iter += 1
79 
80     def run(self, data_loaders, workflow, max_iters, **kwargs):
81         """Start running.
82 
83         Args:
84             data_loaders (list[:obj:`DataLoader`]): Dataloaders for training
85                 and validation.
86             workflow (list[tuple]): A list of (phase, iters) to specify the
87                 running order and iterations. E.g, [('train', 10000),
88                 ('val', 1000)] means running 10000 iterations for training and
89                 1000 iterations for validation, iteratively.
90             max_iters (int): Total training iterations.
91         """
92         assert isinstance(data_loaders, list)
93         assert mmcv.is_list_of(workflow, tuple)
94         assert len(data_loaders) == len(workflow)
95 
96         self._max_iters = max_iters
97         work_dir = self.work_dir if self.work_dir is not None else 'NONE'
98         self.logger.info('Start running, host: %s, work_dir: %s',
99                          get_host_info(), work_dir)
100         self.logger.info('workflow: %s, max: %d iters', workflow, max_iters)
101         self.call_hook('before_run')
102 
103         iter_loaders = [IterLoader(x) for x in data_loaders]
104 
105         self.call_hook('before_epoch')
106 
107         while self.iter < max_iters:
108             for i, flow in enumerate(workflow):
109                 self._inner_iter = 0
110                 mode, iters = flow
111                 if not isinstance(mode, str) or not hasattr(self, mode):
112                     raise ValueError(
113                         'runner has no method named "{}" to run a workflow'.
114                         format(mode))
115                 iter_runner = getattr(self, mode)
116                 for _ in range(iters):
117                     if mode == 'train' and self.iter >= max_iters:
118                         break
119                     iter_runner(iter_loaders[i], **kwargs)
120 
121         time.sleep(1)  # wait for some hooks like loggers to finish
122         self.call_hook('after_epoch')
123         self.call_hook('after_run')
124 
125     def resume(self,
126                checkpoint,
127                resume_optimizer=True,
128                map_location='default'):
129         """Resume model from checkpoint.
130 
131         Args:
132             checkpoint (str): Checkpoint to resume from.
133             resume_optimizer (bool, optional): Whether resume the optimizer(s)
134                 if the checkpoint file includes optimizer(s). Default to True.
135             map_location (str, optional): Same as :func:`torch.load`.
136                 Default to 'default'.
137         """
138         if map_location == 'default':
139             device_id = torch.cuda.current_device()
140             checkpoint = self.load_checkpoint(
141                 checkpoint,
142                 map_location=lambda storage, loc: storage.cuda(device_id))
143         else:
144             checkpoint = self.load_checkpoint(
145                 checkpoint, map_location=map_location)
146 
147         self._epoch = checkpoint['meta']['epoch']
148         self._iter = checkpoint['meta']['iter']
149         self._inner_iter = checkpoint['meta']['iter']
150         if 'optimizer' in checkpoint and resume_optimizer:
151             if isinstance(self.optimizer, Optimizer):
152                 self.optimizer.load_state_dict(checkpoint['optimizer'])
153             elif isinstance(self.optimizer, dict):
154                 for k in self.optimizer.keys():
155                     self.optimizer[k].load_state_dict(
156                         checkpoint['optimizer'][k])
157 
158         self.logger.info(f'resumed from epoch: {self.epoch}, iter {self.iter}')
159 
160     def save_checkpoint(self,
161                         out_dir,
162                         filename_tmpl='iter_{}.pth',
163                         meta=None,
164                         save_optimizer=True,
165                         create_symlink=True):
166         """Save checkpoint to file.
167 
168         Args:
169             out_dir (str): Directory to save checkpoint files.
170             filename_tmpl (str, optional): Checkpoint file template.
171                 Defaults to 'iter_{}.pth'.
172             meta (dict, optional): Metadata to be saved in checkpoint.
173                 Defaults to None.
174             save_optimizer (bool, optional): Whether save optimizer.
175                 Defaults to True.
176             create_symlink (bool, optional): Whether create symlink to the
177                 latest checkpoint file. Defaults to True.
178         """
179         if meta is None:
180             meta = dict(iter=self.iter + 1, epoch=self.epoch + 1)
181         elif isinstance(meta, dict):
182             meta.update(iter=self.iter + 1, epoch=self.epoch + 1)
183         else:
184             raise TypeError(
185                 f'meta should be a dict or None, but got {type(meta)}')
186         if self.meta is not None:
187             meta.update(self.meta)
188 
189         filename = filename_tmpl.format(self.iter + 1)
190         filepath = osp.join(out_dir, filename)
191         optimizer = self.optimizer if save_optimizer else None
192         save_checkpoint(self.model, filepath, optimizer=optimizer, meta=meta)
193         # in some environments, `os.symlink` is not supported, you may need to
194         # set `create_symlink` to False
195         if create_symlink:
196             mmcv.symlink(filename, osp.join(out_dir, 'latest.pth'))
197 
198     def register_training_hooks(self,
199                                 lr_config,
200                                 optimizer_config=None,
201                                 checkpoint_config=None,
202                                 log_config=None,
203                                 momentum_config=None):
204         """Register default hooks for iter-based training.
205 
206         Default hooks include:
207 
208         - LrUpdaterHook
209         - MomentumUpdaterHook
210         - OptimizerStepperHook
211         - CheckpointSaverHook
212         - IterTimerHook
213         - LoggerHook(s)
214         """
215         if checkpoint_config is not None:
216             checkpoint_config.setdefault('by_epoch', False)
217         if lr_config is not None:
218             lr_config.setdefault('by_epoch', False)
219         self.register_lr_hook(lr_config)
220         self.register_momentum_hook(momentum_config)
221         self.register_optimizer_hook(optimizer_config)
222         self.register_checkpoint_hook(checkpoint_config)
223         self.register_hook(IterTimerHook())
224         if log_config is not None:
225             log_config.setdefault('by_epoch', False)
226         self.register_logger_hooks(log_config)
227
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mmcv/runner/iter_based_runner.py b/mmcv/runner/iter_based_runner.py
--- a/mmcv/runner/iter_based_runner.py
+++ b/mmcv/runner/iter_based_runner.py
@@ -222,5 +222,6 @@
         self.register_checkpoint_hook(checkpoint_config)
         self.register_hook(IterTimerHook())
         if log_config is not None:
-            log_config.setdefault('by_epoch', False)
+            for info in log_config['hooks']:
+                info.setdefault('by_epoch', False)
         self.register_logger_hooks(log_config)

{"golden_diff": "diff --git a/mmcv/runner/iter_based_runner.py b/mmcv/runner/iter_based_runner.py\n--- a/mmcv/runner/iter_based_runner.py\n+++ b/mmcv/runner/iter_based_runner.py\n@@ -222,5 +222,6 @@\n         self.register_checkpoint_hook(checkpoint_config)\n         self.register_hook(IterTimerHook())\n         if log_config is not None:\n-            log_config.setdefault('by_epoch', False)\n+            for info in log_config['hooks']:\n+                info.setdefault('by_epoch', False)\n         self.register_logger_hooks(log_config)\n", "issue": "Bug feedback.\nThanks for your codes. \r\nIn [mmcv/runner/base_runner](https://github.com/open-mmlab/mmcv/blob/master/mmcv/runner/base_runner.py#L385), \r\n`    def register_logger_hooks(self, log_config):\r\n        log_interval = log_config['interval']\r\n        for info in log_config['hooks']:\r\n            logger_hook = mmcv.build_from_cfg(\r\n                info, HOOKS, default_args=dict(interval=log_interval))\r\n            self.register_hook(logger_hook, priority='VERY_LOW')\r\n`\r\n.\r\nOnly the argument 'interval' in log_config is fed into logger_hook. However, the argument 'by_epoch' is ignored, always true, so that if iter_based_runner is used, the logger will work unexpectedly. \n", "before_files": [{"content": "# Copyright (c) Open-MMLab. All rights reserved.\nimport os.path as osp\nimport time\n\nimport torch\nfrom torch.optim import Optimizer\n\nimport mmcv\nfrom .base_runner import BaseRunner\nfrom .checkpoint import save_checkpoint\nfrom .hooks import IterTimerHook\nfrom .utils import get_host_info\n\n\nclass IterLoader:\n\n    def __init__(self, dataloader):\n        self._dataloader = dataloader\n        self.iter_loader = iter(self._dataloader)\n        self._epoch = 0\n\n    @property\n    def epoch(self):\n        return self._epoch\n\n    def __next__(self):\n        try:\n            data = next(self.iter_loader)\n        except StopIteration:\n            self._epoch += 1\n            if hasattr(self._dataloader.sampler, 'set_epoch'):\n                self._dataloader.sampler.set_epoch(self._epoch)\n            self.iter_loader = iter(self._dataloader)\n            data = next(self.iter_loader)\n\n        return data\n\n    def __len__(self):\n        return len(self._dataloader)\n\n\nclass IterBasedRunner(BaseRunner):\n    \"\"\"Iteration-based Runner.\n\n    This runner train models iteration by iteration.\n    \"\"\"\n\n    def train(self, data_loader, **kwargs):\n        self.model.train()\n        self.mode = 'train'\n        self.data_loader = data_loader\n        self._epoch = data_loader.epoch\n        self.call_hook('before_train_iter')\n        data_batch = next(data_loader)\n        outputs = self.model.train_step(data_batch, self.optimizer, **kwargs)\n        if not isinstance(outputs, dict):\n            raise TypeError('model.train_step() must return a dict')\n        if 'log_vars' in outputs:\n            self.log_buffer.update(outputs['log_vars'], outputs['num_samples'])\n        self.outputs = outputs\n        self.call_hook('after_train_iter')\n        self._inner_iter += 1\n        self._iter += 1\n\n    def val(self, data_loader, **kwargs):\n        self.model.eval()\n        self.mode = 'val'\n        self.data_loader = data_loader\n        self.call_hook('before_val_iter')\n        data_batch = next(data_loader)\n        outputs = self.model.val_step(data_batch, **kwargs)\n        if not isinstance(outputs, dict):\n            raise TypeError('model.val_step() must return a dict')\n        if 'log_vars' in outputs:\n            self.log_buffer.update(outputs['log_vars'], outputs['num_samples'])\n        self.outputs = outputs\n        self.call_hook('after_val_iter')\n        self._inner_iter += 1\n\n    def run(self, data_loaders, workflow, max_iters, **kwargs):\n        \"\"\"Start running.\n\n        Args:\n            data_loaders (list[:obj:`DataLoader`]): Dataloaders for training\n                and validation.\n            workflow (list[tuple]): A list of (phase, iters) to specify the\n                running order and iterations. E.g, [('train', 10000),\n                ('val', 1000)] means running 10000 iterations for training and\n                1000 iterations for validation, iteratively.\n            max_iters (int): Total training iterations.\n        \"\"\"\n        assert isinstance(data_loaders, list)\n        assert mmcv.is_list_of(workflow, tuple)\n        assert len(data_loaders) == len(workflow)\n\n        self._max_iters = max_iters\n        work_dir = self.work_dir if self.work_dir is not None else 'NONE'\n        self.logger.info('Start running, host: %s, work_dir: %s',\n                         get_host_info(), work_dir)\n        self.logger.info('workflow: %s, max: %d iters', workflow, max_iters)\n        self.call_hook('before_run')\n\n        iter_loaders = [IterLoader(x) for x in data_loaders]\n\n        self.call_hook('before_epoch')\n\n        while self.iter < max_iters:\n            for i, flow in enumerate(workflow):\n                self._inner_iter = 0\n                mode, iters = flow\n                if not isinstance(mode, str) or not hasattr(self, mode):\n                    raise ValueError(\n                        'runner has no method named \"{}\" to run a workflow'.\n                        format(mode))\n                iter_runner = getattr(self, mode)\n                for _ in range(iters):\n                    if mode == 'train' and self.iter >= max_iters:\n                        break\n                    iter_runner(iter_loaders[i], **kwargs)\n\n        time.sleep(1)  # wait for some hooks like loggers to finish\n        self.call_hook('after_epoch')\n        self.call_hook('after_run')\n\n    def resume(self,\n               checkpoint,\n               resume_optimizer=True,\n               map_location='default'):\n        \"\"\"Resume model from checkpoint.\n\n        Args:\n            checkpoint (str): Checkpoint to resume from.\n            resume_optimizer (bool, optional): Whether resume the optimizer(s)\n                if the checkpoint file includes optimizer(s). Default to True.\n            map_location (str, optional): Same as :func:`torch.load`.\n                Default to 'default'.\n        \"\"\"\n        if map_location == 'default':\n            device_id = torch.cuda.current_device()\n            checkpoint = self.load_checkpoint(\n                checkpoint,\n                map_location=lambda storage, loc: storage.cuda(device_id))\n        else:\n            checkpoint = self.load_checkpoint(\n                checkpoint, map_location=map_location)\n\n        self._epoch = checkpoint['meta']['epoch']\n        self._iter = checkpoint['meta']['iter']\n        self._inner_iter = checkpoint['meta']['iter']\n        if 'optimizer' in checkpoint and resume_optimizer:\n            if isinstance(self.optimizer, Optimizer):\n                self.optimizer.load_state_dict(checkpoint['optimizer'])\n            elif isinstance(self.optimizer, dict):\n                for k in self.optimizer.keys():\n                    self.optimizer[k].load_state_dict(\n                        checkpoint['optimizer'][k])\n\n        self.logger.info(f'resumed from epoch: {self.epoch}, iter {self.iter}')\n\n    def save_checkpoint(self,\n                        out_dir,\n                        filename_tmpl='iter_{}.pth',\n                        meta=None,\n                        save_optimizer=True,\n                        create_symlink=True):\n        \"\"\"Save checkpoint to file.\n\n        Args:\n            out_dir (str): Directory to save checkpoint files.\n            filename_tmpl (str, optional): Checkpoint file template.\n                Defaults to 'iter_{}.pth'.\n            meta (dict, optional): Metadata to be saved in checkpoint.\n                Defaults to None.\n            save_optimizer (bool, optional): Whether save optimizer.\n                Defaults to True.\n            create_symlink (bool, optional): Whether create symlink to the\n                latest checkpoint file. Defaults to True.\n        \"\"\"\n        if meta is None:\n            meta = dict(iter=self.iter + 1, epoch=self.epoch + 1)\n        elif isinstance(meta, dict):\n            meta.update(iter=self.iter + 1, epoch=self.epoch + 1)\n        else:\n            raise TypeError(\n                f'meta should be a dict or None, but got {type(meta)}')\n        if self.meta is not None:\n            meta.update(self.meta)\n\n        filename = filename_tmpl.format(self.iter + 1)\n        filepath = osp.join(out_dir, filename)\n        optimizer = self.optimizer if save_optimizer else None\n        save_checkpoint(self.model, filepath, optimizer=optimizer, meta=meta)\n        # in some environments, `os.symlink` is not supported, you may need to\n        # set `create_symlink` to False\n        if create_symlink:\n            mmcv.symlink(filename, osp.join(out_dir, 'latest.pth'))\n\n    def register_training_hooks(self,\n                                lr_config,\n                                optimizer_config=None,\n                                checkpoint_config=None,\n                                log_config=None,\n                                momentum_config=None):\n        \"\"\"Register default hooks for iter-based training.\n\n        Default hooks include:\n\n        - LrUpdaterHook\n        - MomentumUpdaterHook\n        - OptimizerStepperHook\n        - CheckpointSaverHook\n        - IterTimerHook\n        - LoggerHook(s)\n        \"\"\"\n        if checkpoint_config is not None:\n            checkpoint_config.setdefault('by_epoch', False)\n        if lr_config is not None:\n            lr_config.setdefault('by_epoch', False)\n        self.register_lr_hook(lr_config)\n        self.register_momentum_hook(momentum_config)\n        self.register_optimizer_hook(optimizer_config)\n        self.register_checkpoint_hook(checkpoint_config)\n        self.register_hook(IterTimerHook())\n        if log_config is not None:\n            log_config.setdefault('by_epoch', False)\n        self.register_logger_hooks(log_config)\n", "path": "mmcv/runner/iter_based_runner.py"}], "after_files": [{"content": "# Copyright (c) Open-MMLab. All rights reserved.\nimport os.path as osp\nimport time\n\nimport torch\nfrom torch.optim import Optimizer\n\nimport mmcv\nfrom .base_runner import BaseRunner\nfrom .checkpoint import save_checkpoint\nfrom .hooks import IterTimerHook\nfrom .utils import get_host_info\n\n\nclass IterLoader:\n\n    def __init__(self, dataloader):\n        self._dataloader = dataloader\n        self.iter_loader = iter(self._dataloader)\n        self._epoch = 0\n\n    @property\n    def epoch(self):\n        return self._epoch\n\n    def __next__(self):\n        try:\n            data = next(self.iter_loader)\n        except StopIteration:\n            self._epoch += 1\n            if hasattr(self._dataloader.sampler, 'set_epoch'):\n                self._dataloader.sampler.set_epoch(self._epoch)\n            self.iter_loader = iter(self._dataloader)\n            data = next(self.iter_loader)\n\n        return data\n\n    def __len__(self):\n        return len(self._dataloader)\n\n\nclass IterBasedRunner(BaseRunner):\n    \"\"\"Iteration-based Runner.\n\n    This runner train models iteration by iteration.\n    \"\"\"\n\n    def train(self, data_loader, **kwargs):\n        self.model.train()\n        self.mode = 'train'\n        self.data_loader = data_loader\n        self._epoch = data_loader.epoch\n        self.call_hook('before_train_iter')\n        data_batch = next(data_loader)\n        outputs = self.model.train_step(data_batch, self.optimizer, **kwargs)\n        if not isinstance(outputs, dict):\n            raise TypeError('model.train_step() must return a dict')\n        if 'log_vars' in outputs:\n            self.log_buffer.update(outputs['log_vars'], outputs['num_samples'])\n        self.outputs = outputs\n        self.call_hook('after_train_iter')\n        self._inner_iter += 1\n        self._iter += 1\n\n    def val(self, data_loader, **kwargs):\n        self.model.eval()\n        self.mode = 'val'\n        self.data_loader = data_loader\n        self.call_hook('before_val_iter')\n        data_batch = next(data_loader)\n        outputs = self.model.val_step(data_batch, **kwargs)\n        if not isinstance(outputs, dict):\n            raise TypeError('model.val_step() must return a dict')\n        if 'log_vars' in outputs:\n            self.log_buffer.update(outputs['log_vars'], outputs['num_samples'])\n        self.outputs = outputs\n        self.call_hook('after_val_iter')\n        self._inner_iter += 1\n\n    def run(self, data_loaders, workflow, max_iters, **kwargs):\n        \"\"\"Start running.\n\n        Args:\n            data_loaders (list[:obj:`DataLoader`]): Dataloaders for training\n                and validation.\n            workflow (list[tuple]): A list of (phase, iters) to specify the\n                running order and iterations. E.g, [('train', 10000),\n                ('val', 1000)] means running 10000 iterations for training and\n                1000 iterations for validation, iteratively.\n            max_iters (int): Total training iterations.\n        \"\"\"\n        assert isinstance(data_loaders, list)\n        assert mmcv.is_list_of(workflow, tuple)\n        assert len(data_loaders) == len(workflow)\n\n        self._max_iters = max_iters\n        work_dir = self.work_dir if self.work_dir is not None else 'NONE'\n        self.logger.info('Start running, host: %s, work_dir: %s',\n                         get_host_info(), work_dir)\n        self.logger.info('workflow: %s, max: %d iters', workflow, max_iters)\n        self.call_hook('before_run')\n\n        iter_loaders = [IterLoader(x) for x in data_loaders]\n\n        self.call_hook('before_epoch')\n\n        while self.iter < max_iters:\n            for i, flow in enumerate(workflow):\n                self._inner_iter = 0\n                mode, iters = flow\n                if not isinstance(mode, str) or not hasattr(self, mode):\n                    raise ValueError(\n                        'runner has no method named \"{}\" to run a workflow'.\n                        format(mode))\n                iter_runner = getattr(self, mode)\n                for _ in range(iters):\n                    if mode == 'train' and self.iter >= max_iters:\n                        break\n                    iter_runner(iter_loaders[i], **kwargs)\n\n        time.sleep(1)  # wait for some hooks like loggers to finish\n        self.call_hook('after_epoch')\n        self.call_hook('after_run')\n\n    def resume(self,\n               checkpoint,\n               resume_optimizer=True,\n               map_location='default'):\n        \"\"\"Resume model from checkpoint.\n\n        Args:\n            checkpoint (str): Checkpoint to resume from.\n            resume_optimizer (bool, optional): Whether resume the optimizer(s)\n                if the checkpoint file includes optimizer(s). Default to True.\n            map_location (str, optional): Same as :func:`torch.load`.\n                Default to 'default'.\n        \"\"\"\n        if map_location == 'default':\n            device_id = torch.cuda.current_device()\n            checkpoint = self.load_checkpoint(\n                checkpoint,\n                map_location=lambda storage, loc: storage.cuda(device_id))\n        else:\n            checkpoint = self.load_checkpoint(\n                checkpoint, map_location=map_location)\n\n        self._epoch = checkpoint['meta']['epoch']\n        self._iter = checkpoint['meta']['iter']\n        self._inner_iter = checkpoint['meta']['iter']\n        if 'optimizer' in checkpoint and resume_optimizer:\n            if isinstance(self.optimizer, Optimizer):\n                self.optimizer.load_state_dict(checkpoint['optimizer'])\n            elif isinstance(self.optimizer, dict):\n                for k in self.optimizer.keys():\n                    self.optimizer[k].load_state_dict(\n                        checkpoint['optimizer'][k])\n\n        self.logger.info(f'resumed from epoch: {self.epoch}, iter {self.iter}')\n\n    def save_checkpoint(self,\n                        out_dir,\n                        filename_tmpl='iter_{}.pth',\n                        meta=None,\n                        save_optimizer=True,\n                        create_symlink=True):\n        \"\"\"Save checkpoint to file.\n\n        Args:\n            out_dir (str): Directory to save checkpoint files.\n            filename_tmpl (str, optional): Checkpoint file template.\n                Defaults to 'iter_{}.pth'.\n            meta (dict, optional): Metadata to be saved in checkpoint.\n                Defaults to None.\n            save_optimizer (bool, optional): Whether save optimizer.\n                Defaults to True.\n            create_symlink (bool, optional): Whether create symlink to the\n                latest checkpoint file. Defaults to True.\n        \"\"\"\n        if meta is None:\n            meta = dict(iter=self.iter + 1, epoch=self.epoch + 1)\n        elif isinstance(meta, dict):\n            meta.update(iter=self.iter + 1, epoch=self.epoch + 1)\n        else:\n            raise TypeError(\n                f'meta should be a dict or None, but got {type(meta)}')\n        if self.meta is not None:\n            meta.update(self.meta)\n\n        filename = filename_tmpl.format(self.iter + 1)\n        filepath = osp.join(out_dir, filename)\n        optimizer = self.optimizer if save_optimizer else None\n        save_checkpoint(self.model, filepath, optimizer=optimizer, meta=meta)\n        # in some environments, `os.symlink` is not supported, you may need to\n        # set `create_symlink` to False\n        if create_symlink:\n            mmcv.symlink(filename, osp.join(out_dir, 'latest.pth'))\n\n    def register_training_hooks(self,\n                                lr_config,\n                                optimizer_config=None,\n                                checkpoint_config=None,\n                                log_config=None,\n                                momentum_config=None):\n        \"\"\"Register default hooks for iter-based training.\n\n        Default hooks include:\n\n        - LrUpdaterHook\n        - MomentumUpdaterHook\n        - OptimizerStepperHook\n        - CheckpointSaverHook\n        - IterTimerHook\n        - LoggerHook(s)\n        \"\"\"\n        if checkpoint_config is not None:\n            checkpoint_config.setdefault('by_epoch', False)\n        if lr_config is not None:\n            lr_config.setdefault('by_epoch', False)\n        self.register_lr_hook(lr_config)\n        self.register_momentum_hook(momentum_config)\n        self.register_optimizer_hook(optimizer_config)\n        self.register_checkpoint_hook(checkpoint_config)\n        self.register_hook(IterTimerHook())\n        if log_config is not None:\n            for info in log_config['hooks']:\n                info.setdefault('by_epoch', False)\n        self.register_logger_hooks(log_config)\n", "path": "mmcv/runner/iter_based_runner.py"}]}