prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Add a README file to explain the settings in the config files
  A good example can be found [here](https://github.com/open-mmlab/mmaction2/blob/master/docs/config.md)
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `tools/train.py`
  Content:
  ```
  1 import argparse
  2 import copy
  3 import os
  4 import os.path as osp
  5 import time
  6 
  7 import mmcv
  8 import torch
  9 from mmcv import Config, DictAction
  10 from mmcv.runner import init_dist, set_random_seed
  11 from mmcv.utils import get_git_hash
  12 
  13 from mmpose import __version__
  14 from mmpose.apis import train_model
  15 from mmpose.datasets import build_dataset
  16 from mmpose.models import build_posenet
  17 from mmpose.utils import collect_env, get_root_logger
  18 
  19 
  20 def parse_args():
  21     parser = argparse.ArgumentParser(description='Train a pose model')
  22     parser.add_argument('config', help='train config file path')
  23     parser.add_argument('--work-dir', help='the dir to save logs and models')
  24     parser.add_argument(
  25         '--resume-from', help='the checkpoint file to resume from')
  26     parser.add_argument(
  27         '--no-validate',
  28         action='store_true',
  29         help='whether not to evaluate the checkpoint during training')
  30     group_gpus = parser.add_mutually_exclusive_group()
  31     group_gpus.add_argument(
  32         '--gpus',
  33         type=int,
  34         help='number of gpus to use '
  35         '(only applicable to non-distributed training)')
  36     group_gpus.add_argument(
  37         '--gpu-ids',
  38         type=int,
  39         nargs='+',
  40         help='ids of gpus to use '
  41         '(only applicable to non-distributed training)')
  42     parser.add_argument('--seed', type=int, default=None, help='random seed')
  43     parser.add_argument(
  44         '--deterministic',
  45         action='store_true',
  46         help='whether to set deterministic options for CUDNN backend.')
  47     parser.add_argument(
  48         '--options', nargs='+', action=DictAction, help='arguments in dict')
  49     parser.add_argument(
  50         '--launcher',
  51         choices=['none', 'pytorch', 'slurm', 'mpi'],
  52         default='none',
  53         help='job launcher')
  54     parser.add_argument('--local_rank', type=int, default=0)
  55     parser.add_argument(
  56         '--autoscale-lr',
  57         action='store_true',
  58         help='automatically scale lr with the number of gpus')
  59     args = parser.parse_args()
  60     if 'LOCAL_RANK' not in os.environ:
  61         os.environ['LOCAL_RANK'] = str(args.local_rank)
  62 
  63     return args
  64 
  65 
  66 def main():
  67     args = parse_args()
  68     cfg = Config.fromfile(args.config)
  69     if args.options is not None:
  70         cfg.merge_from_dict(args.options)
  71     # set cudnn_benchmark
  72     if cfg.get('cudnn_benchmark', False):
  73         torch.backends.cudnn.benchmark = True
  74     # work_dir is determined in this priority: CLI > segment in file > filename
  75     if args.work_dir is not None:
  76         # update configs according to CLI args if args.work_dir is not None
  77         cfg.work_dir = args.work_dir
  78     elif cfg.get('work_dir', None) is None:
  79         # use config filename as default work_dir if cfg.work_dir is None
  80         cfg.work_dir = osp.join('./work_dirs',
  81                                 osp.splitext(osp.basename(args.config))[0])
  82     if args.resume_from is not None:
  83         cfg.resume_from = args.resume_from
  84     if args.gpu_ids is not None:
  85         cfg.gpu_ids = args.gpu_ids
  86     else:
  87         cfg.gpu_ids = range(1) if args.gpus is None else range(args.gpus)
  88 
  89     if args.autoscale_lr:
  90         # apply the linear scaling rule (https://arxiv.org/abs/1706.02677)
  91         cfg.optimizer['lr'] = cfg.optimizer['lr'] * len(cfg.gpu_ids) / 8
  92 
  93     # init distributed env first, since logger depends on the dist info.
  94     if args.launcher == 'none':
  95         distributed = False
  96     else:
  97         distributed = True
  98         init_dist(args.launcher, **cfg.dist_params)
  99 
  100     # create work_dir
  101     mmcv.mkdir_or_exist(osp.abspath(cfg.work_dir))
  102     # init the logger before other steps
  103     timestamp = time.strftime('%Y%m%d_%H%M%S', time.localtime())
  104     log_file = osp.join(cfg.work_dir, f'{timestamp}.log')
  105     logger = get_root_logger(log_file=log_file, log_level=cfg.log_level)
  106 
  107     # init the meta dict to record some important information such as
  108     # environment info and seed, which will be logged
  109     meta = dict()
  110     # log env info
  111     env_info_dict = collect_env()
  112     env_info = '\n'.join([(f'{k}: {v}') for k, v in env_info_dict.items()])
  113     dash_line = '-' * 60 + '\n'
  114     logger.info('Environment info:\n' + dash_line + env_info + '\n' +
  115                 dash_line)
  116     meta['env_info'] = env_info
  117 
  118     # log some basic info
  119     logger.info(f'Distributed training: {distributed}')
  120     logger.info(f'Config:\n{cfg.pretty_text}')
  121 
  122     # set random seeds
  123     if args.seed is not None:
  124         logger.info(f'Set random seed to {args.seed}, '
  125                     f'deterministic: {args.deterministic}')
  126         set_random_seed(args.seed, deterministic=args.deterministic)
  127     cfg.seed = args.seed
  128     meta['seed'] = args.seed
  129 
  130     model = build_posenet(cfg.model)
  131     datasets = [build_dataset(cfg.data.train)]
  132 
  133     if len(cfg.workflow) == 2:
  134         val_dataset = copy.deepcopy(cfg.data.val)
  135         val_dataset.pipeline = cfg.data.train.pipeline
  136         datasets.append(build_dataset(val_dataset))
  137 
  138     if cfg.checkpoint_config is not None:
  139         # save mmpose version, config file content
  140         # checkpoints as meta data
  141         cfg.checkpoint_config.meta = dict(
  142             mmpose_version=__version__ + get_git_hash(digits=7),
  143             config=cfg.pretty_text,
  144         )
  145     train_model(
  146         model,
  147         datasets,
  148         cfg,
  149         distributed=distributed,
  150         validate=(not args.no_validate),
  151         timestamp=timestamp,
  152         meta=meta)
  153 
  154 
  155 if __name__ == '__main__':
  156     main()
  157
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/tools/train.py b/tools/train.py
  --- a/tools/train.py
  +++ b/tools/train.py
  @@ -45,7 +45,13 @@
           action='store_true',
           help='whether to set deterministic options for CUDNN backend.')
       parser.add_argument(
  -        '--options', nargs='+', action=DictAction, help='arguments in dict')
  +        '--cfg-options',
  +        nargs='+',
  +        action=DictAction,
  +        default={},
  +        help='override some settings in the used config, the key-value pair '
  +        'in xxx=yyy format will be merged into config file. For example, '
  +        "'--cfg-options model.backbone.depth=18 model.backbone.with_cp=True'")
       parser.add_argument(
           '--launcher',
           choices=['none', 'pytorch', 'slurm', 'mpi'],
  @@ -65,12 +71,16 @@
   
   def main():
       args = parse_args()
  +
       cfg = Config.fromfile(args.config)
  -    if args.options is not None:
  -        cfg.merge_from_dict(args.options)
  +
  +    if args.cfg_options is not None:
  +        cfg.merge_from_dict(args.cfg_options)
  +
       # set cudnn_benchmark
       if cfg.get('cudnn_benchmark', False):
           torch.backends.cudnn.benchmark = True
  +
       # work_dir is determined in this priority: CLI > segment in file > filename
       if args.work_dir is not None:
           # update configs according to CLI args if args.work_dir is not None
  
verification_info: {"golden_diff": "diff --git a/tools/train.py b/tools/train.py\n--- a/tools/train.py\n+++ b/tools/train.py\n@@ -45,7 +45,13 @@\n         action='store_true',\n         help='whether to set deterministic options for CUDNN backend.')\n     parser.add_argument(\n-        '--options', nargs='+', action=DictAction, help='arguments in dict')\n+        '--cfg-options',\n+        nargs='+',\n+        action=DictAction,\n+        default={},\n+        help='override some settings in the used config, the key-value pair '\n+        'in xxx=yyy format will be merged into config file. For example, '\n+        \"'--cfg-options model.backbone.depth=18 model.backbone.with_cp=True'\")\n     parser.add_argument(\n         '--launcher',\n         choices=['none', 'pytorch', 'slurm', 'mpi'],\n@@ -65,12 +71,16 @@\n \n def main():\n     args = parse_args()\n+\n     cfg = Config.fromfile(args.config)\n-    if args.options is not None:\n-        cfg.merge_from_dict(args.options)\n+\n+    if args.cfg_options is not None:\n+        cfg.merge_from_dict(args.cfg_options)\n+\n     # set cudnn_benchmark\n     if cfg.get('cudnn_benchmark', False):\n         torch.backends.cudnn.benchmark = True\n+\n     # work_dir is determined in this priority: CLI > segment in file > filename\n     if args.work_dir is not None:\n         # update configs according to CLI args if args.work_dir is not None\n", "issue": "Add a README file to explain the settings in the config files\nA good example can be found [here](https://github.com/open-mmlab/mmaction2/blob/master/docs/config.md)\n", "before_files": [{"content": "import argparse\nimport copy\nimport os\nimport os.path as osp\nimport time\n\nimport mmcv\nimport torch\nfrom mmcv import Config, DictAction\nfrom mmcv.runner import init_dist, set_random_seed\nfrom mmcv.utils import get_git_hash\n\nfrom mmpose import __version__\nfrom mmpose.apis import train_model\nfrom mmpose.datasets import build_dataset\nfrom mmpose.models import build_posenet\nfrom mmpose.utils import collect_env, get_root_logger\n\n\ndef parse_args():\n    parser = argparse.ArgumentParser(description='Train a pose model')\n    parser.add_argument('config', help='train config file path')\n    parser.add_argument('--work-dir', help='the dir to save logs and models')\n    parser.add_argument(\n        '--resume-from', help='the checkpoint file to resume from')\n    parser.add_argument(\n        '--no-validate',\n        action='store_true',\n        help='whether not to evaluate the checkpoint during training')\n    group_gpus = parser.add_mutually_exclusive_group()\n    group_gpus.add_argument(\n        '--gpus',\n        type=int,\n        help='number of gpus to use '\n        '(only applicable to non-distributed training)')\n    group_gpus.add_argument(\n        '--gpu-ids',\n        type=int,\n        nargs='+',\n        help='ids of gpus to use '\n        '(only applicable to non-distributed training)')\n    parser.add_argument('--seed', type=int, default=None, help='random seed')\n    parser.add_argument(\n        '--deterministic',\n        action='store_true',\n        help='whether to set deterministic options for CUDNN backend.')\n    parser.add_argument(\n        '--options', nargs='+', action=DictAction, help='arguments in dict')\n    parser.add_argument(\n        '--launcher',\n        choices=['none', 'pytorch', 'slurm', 'mpi'],\n        default='none',\n        help='job launcher')\n    parser.add_argument('--local_rank', type=int, default=0)\n    parser.add_argument(\n        '--autoscale-lr',\n        action='store_true',\n        help='automatically scale lr with the number of gpus')\n    args = parser.parse_args()\n    if 'LOCAL_RANK' not in os.environ:\n        os.environ['LOCAL_RANK'] = str(args.local_rank)\n\n    return args\n\n\ndef main():\n    args = parse_args()\n    cfg = Config.fromfile(args.config)\n    if args.options is not None:\n        cfg.merge_from_dict(args.options)\n    # set cudnn_benchmark\n    if cfg.get('cudnn_benchmark', False):\n        torch.backends.cudnn.benchmark = True\n    # work_dir is determined in this priority: CLI > segment in file > filename\n    if args.work_dir is not None:\n        # update configs according to CLI args if args.work_dir is not None\n        cfg.work_dir = args.work_dir\n    elif cfg.get('work_dir', None) is None:\n        # use config filename as default work_dir if cfg.work_dir is None\n        cfg.work_dir = osp.join('./work_dirs',\n                                osp.splitext(osp.basename(args.config))[0])\n    if args.resume_from is not None:\n        cfg.resume_from = args.resume_from\n    if args.gpu_ids is not None:\n        cfg.gpu_ids = args.gpu_ids\n    else:\n        cfg.gpu_ids = range(1) if args.gpus is None else range(args.gpus)\n\n    if args.autoscale_lr:\n        # apply the linear scaling rule (https://arxiv.org/abs/1706.02677)\n        cfg.optimizer['lr'] = cfg.optimizer['lr'] * len(cfg.gpu_ids) / 8\n\n    # init distributed env first, since logger depends on the dist info.\n    if args.launcher == 'none':\n        distributed = False\n    else:\n        distributed = True\n        init_dist(args.launcher, **cfg.dist_params)\n\n    # create work_dir\n    mmcv.mkdir_or_exist(osp.abspath(cfg.work_dir))\n    # init the logger before other steps\n    timestamp = time.strftime('%Y%m%d_%H%M%S', time.localtime())\n    log_file = osp.join(cfg.work_dir, f'{timestamp}.log')\n    logger = get_root_logger(log_file=log_file, log_level=cfg.log_level)\n\n    # init the meta dict to record some important information such as\n    # environment info and seed, which will be logged\n    meta = dict()\n    # log env info\n    env_info_dict = collect_env()\n    env_info = '\\n'.join([(f'{k}: {v}') for k, v in env_info_dict.items()])\n    dash_line = '-' * 60 + '\\n'\n    logger.info('Environment info:\\n' + dash_line + env_info + '\\n' +\n                dash_line)\n    meta['env_info'] = env_info\n\n    # log some basic info\n    logger.info(f'Distributed training: {distributed}')\n    logger.info(f'Config:\\n{cfg.pretty_text}')\n\n    # set random seeds\n    if args.seed is not None:\n        logger.info(f'Set random seed to {args.seed}, '\n                    f'deterministic: {args.deterministic}')\n        set_random_seed(args.seed, deterministic=args.deterministic)\n    cfg.seed = args.seed\n    meta['seed'] = args.seed\n\n    model = build_posenet(cfg.model)\n    datasets = [build_dataset(cfg.data.train)]\n\n    if len(cfg.workflow) == 2:\n        val_dataset = copy.deepcopy(cfg.data.val)\n        val_dataset.pipeline = cfg.data.train.pipeline\n        datasets.append(build_dataset(val_dataset))\n\n    if cfg.checkpoint_config is not None:\n        # save mmpose version, config file content\n        # checkpoints as meta data\n        cfg.checkpoint_config.meta = dict(\n            mmpose_version=__version__ + get_git_hash(digits=7),\n            config=cfg.pretty_text,\n        )\n    train_model(\n        model,\n        datasets,\n        cfg,\n        distributed=distributed,\n        validate=(not args.no_validate),\n        timestamp=timestamp,\n        meta=meta)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "tools/train.py"}], "after_files": [{"content": "import argparse\nimport copy\nimport os\nimport os.path as osp\nimport time\n\nimport mmcv\nimport torch\nfrom mmcv import Config, DictAction\nfrom mmcv.runner import init_dist, set_random_seed\nfrom mmcv.utils import get_git_hash\n\nfrom mmpose import __version__\nfrom mmpose.apis import train_model\nfrom mmpose.datasets import build_dataset\nfrom mmpose.models import build_posenet\nfrom mmpose.utils import collect_env, get_root_logger\n\n\ndef parse_args():\n    parser = argparse.ArgumentParser(description='Train a pose model')\n    parser.add_argument('config', help='train config file path')\n    parser.add_argument('--work-dir', help='the dir to save logs and models')\n    parser.add_argument(\n        '--resume-from', help='the checkpoint file to resume from')\n    parser.add_argument(\n        '--no-validate',\n        action='store_true',\n        help='whether not to evaluate the checkpoint during training')\n    group_gpus = parser.add_mutually_exclusive_group()\n    group_gpus.add_argument(\n        '--gpus',\n        type=int,\n        help='number of gpus to use '\n        '(only applicable to non-distributed training)')\n    group_gpus.add_argument(\n        '--gpu-ids',\n        type=int,\n        nargs='+',\n        help='ids of gpus to use '\n        '(only applicable to non-distributed training)')\n    parser.add_argument('--seed', type=int, default=None, help='random seed')\n    parser.add_argument(\n        '--deterministic',\n        action='store_true',\n        help='whether to set deterministic options for CUDNN backend.')\n    parser.add_argument(\n        '--cfg-options',\n        nargs='+',\n        action=DictAction,\n        default={},\n        help='override some settings in the used config, the key-value pair '\n        'in xxx=yyy format will be merged into config file. For example, '\n        \"'--cfg-options model.backbone.depth=18 model.backbone.with_cp=True'\")\n    parser.add_argument(\n        '--launcher',\n        choices=['none', 'pytorch', 'slurm', 'mpi'],\n        default='none',\n        help='job launcher')\n    parser.add_argument('--local_rank', type=int, default=0)\n    parser.add_argument(\n        '--autoscale-lr',\n        action='store_true',\n        help='automatically scale lr with the number of gpus')\n    args = parser.parse_args()\n    if 'LOCAL_RANK' not in os.environ:\n        os.environ['LOCAL_RANK'] = str(args.local_rank)\n\n    return args\n\n\ndef main():\n    args = parse_args()\n\n    cfg = Config.fromfile(args.config)\n\n    if args.cfg_options is not None:\n        cfg.merge_from_dict(args.cfg_options)\n\n    # set cudnn_benchmark\n    if cfg.get('cudnn_benchmark', False):\n        torch.backends.cudnn.benchmark = True\n\n    # work_dir is determined in this priority: CLI > segment in file > filename\n    if args.work_dir is not None:\n        # update configs according to CLI args if args.work_dir is not None\n        cfg.work_dir = args.work_dir\n    elif cfg.get('work_dir', None) is None:\n        # use config filename as default work_dir if cfg.work_dir is None\n        cfg.work_dir = osp.join('./work_dirs',\n                                osp.splitext(osp.basename(args.config))[0])\n    if args.resume_from is not None:\n        cfg.resume_from = args.resume_from\n    if args.gpu_ids is not None:\n        cfg.gpu_ids = args.gpu_ids\n    else:\n        cfg.gpu_ids = range(1) if args.gpus is None else range(args.gpus)\n\n    if args.autoscale_lr:\n        # apply the linear scaling rule (https://arxiv.org/abs/1706.02677)\n        cfg.optimizer['lr'] = cfg.optimizer['lr'] * len(cfg.gpu_ids) / 8\n\n    # init distributed env first, since logger depends on the dist info.\n    if args.launcher == 'none':\n        distributed = False\n    else:\n        distributed = True\n        init_dist(args.launcher, **cfg.dist_params)\n\n    # create work_dir\n    mmcv.mkdir_or_exist(osp.abspath(cfg.work_dir))\n    # init the logger before other steps\n    timestamp = time.strftime('%Y%m%d_%H%M%S', time.localtime())\n    log_file = osp.join(cfg.work_dir, f'{timestamp}.log')\n    logger = get_root_logger(log_file=log_file, log_level=cfg.log_level)\n\n    # init the meta dict to record some important information such as\n    # environment info and seed, which will be logged\n    meta = dict()\n    # log env info\n    env_info_dict = collect_env()\n    env_info = '\\n'.join([(f'{k}: {v}') for k, v in env_info_dict.items()])\n    dash_line = '-' * 60 + '\\n'\n    logger.info('Environment info:\\n' + dash_line + env_info + '\\n' +\n                dash_line)\n    meta['env_info'] = env_info\n\n    # log some basic info\n    logger.info(f'Distributed training: {distributed}')\n    logger.info(f'Config:\\n{cfg.pretty_text}')\n\n    # set random seeds\n    if args.seed is not None:\n        logger.info(f'Set random seed to {args.seed}, '\n                    f'deterministic: {args.deterministic}')\n        set_random_seed(args.seed, deterministic=args.deterministic)\n    cfg.seed = args.seed\n    meta['seed'] = args.seed\n\n    model = build_posenet(cfg.model)\n    datasets = [build_dataset(cfg.data.train)]\n\n    if len(cfg.workflow) == 2:\n        val_dataset = copy.deepcopy(cfg.data.val)\n        val_dataset.pipeline = cfg.data.train.pipeline\n        datasets.append(build_dataset(val_dataset))\n\n    if cfg.checkpoint_config is not None:\n        # save mmpose version, config file content\n        # checkpoints as meta data\n        cfg.checkpoint_config.meta = dict(\n            mmpose_version=__version__ + get_git_hash(digits=7),\n            config=cfg.pretty_text,\n        )\n    train_model(\n        model,\n        datasets,\n        cfg,\n        distributed=distributed,\n        validate=(not args.no_validate),\n        timestamp=timestamp,\n        meta=meta)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "tools/train.py"}]}