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

[Improvement] Add SyncBuffersHook and Seed #2044

Merged
merged 5 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion configs/_base_/default_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
logger=dict(type='LoggerHook', interval=20, ignore_last=False),
param_scheduler=dict(type='ParamSchedulerHook'),
checkpoint=dict(type='CheckpointHook', interval=1, save_best='auto'),
sampler_seed=dict(type='DistSamplerSeedHook'))
sampler_seed=dict(type='DistSamplerSeedHook'),
sync_buffers=dict(type='SyncBuffersHook'))

env_cfg = dict(
cudnn_benchmark=False,
Expand Down
3 changes: 3 additions & 0 deletions docs/en/user_guides/4_train_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ CUDA_VISIBLE_DEVICES=-1 python tools/train.py ${CONFIG_FILE} [ARGS]
| `--amp` | Enable automatic-mixed-precision training. |
| `--no-validate` | **Not suggested**. Disable checkpoint evaluation during training. |
| `--auto-scale-lr` | Auto scale the learning rate according to the actual batch size and the original batch size. |
| `--seed` | Random seed. |
| `--diff-rank-seed` | Whether or not set different seeds for different ranks. |
| `--deterministic` | Whether to set deterministic options for CUDNN backend. |
| `--cfg-options CFG_OPTIONS` | Override some settings in the used config, the key-value pair in xxx=yyy format will be merged into the config file. If the value to be overwritten is a list, it should be of the form of either `key="[a,b]"` or `key=a,b`. The argument also allows nested list/tuple values, e.g. `key="[(a,b),(c,d)]"`. Note that the quotation marks are necessary and that no white space is allowed. |
| `--launcher {none,pytorch,slurm,mpi}` | Options for job launcher. Defaults to `none`. |

Expand Down
16 changes: 16 additions & 0 deletions tools/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ def parse_args():
action='store_true',
help='whether to auto scale the learning rate according to the '
'actual batch size and the original batch size.')
parser.add_argument('--seed', type=int, default=None, help='random seed')
parser.add_argument(
'--diff-rank-seed',
action='store_true',
help='whether or not set different seeds for different ranks')
parser.add_argument(
'--deterministic',
action='store_true',
help='whether to set deterministic options for CUDNN backend.')
parser.add_argument(
'--cfg-options',
nargs='+',
Expand Down Expand Up @@ -96,6 +105,13 @@ def merge_args(cfg, args):
if args.auto_scale_lr:
cfg.auto_scale_lr.enable = True

# set random seeds
if cfg.get('randomness', None) is None:
cfg.randomness = dict(
seed=args.seed,
diff_rank_seed=args.diff_rank_seed,
deterministic=args.deterministic)

if args.cfg_options is not None:
cfg.merge_from_dict(args.cfg_options)

Expand Down