You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MMCV 1.x version uses LrUpdaterHook and MomentumUpdaterHook to adjust the learning rate and momentum.
However, the design of LrUpdaterHook has been difficult to meet more abundant customization requirements due to the development of the training strategies. Hence, MMEngine proposes parameter schedulers (ParamScheduler).
The interface of the parameter scheduler is consistent with PyTroch's learning rate scheduler (LRScheduler). In addition, the parameter scheduler provides stronger functions. For details, please refer to Parameter Scheduler User Guide.
Learning rate scheduler (LrUpdater) migration
MMEngine uses LRScheduler instead of LrUpdaterHook. The field in the config file is changed from the original lr_config to param_scheduler.
The learning rate config in MMCV corresponds to the parameter scheduler config in MMEngine as follows:
Learning rate warm-up migration
The learning rate warm-up can be achieved through the combination of schedulers by specifying the effective range begin and end. There are 3 learning rate warm-up methods in MMCV, namely 'constant', 'linear', 'exp'. The corresponding config in MMEngine should be modified as follows:
The learning rate strategy combined by multiple phases like FlatCosineAnnealing originally needs to be achieved by rewriting a Hook. But in MMEngine, it can be achieved with combining two parameter scheduler configs:
MMCV uses momentum_config field and MomentumUpdateHook to adjust momentum. The momentum in MMEngine is also controlled by the parameter scheduler. Users can simply change the LR of the learning rate scheduler to Momentum to use the same strategy to adjust the momentum. The momentum scheduler shares the same param_scheduler field in the config with the learning rate scheduler:
param_scheduler= [
# config of learning rate schedulersdict(...),
# config of momentum schedulersdict(type='CosineAnnealingMomentum',
eta_min=0.1,
T_max=num_epochs,
begin=0,
end=num_epochs,
by_epoch=True)
]
Migrate parameter update frequency related config
If you want to update the parameter rate based on iteration while using the epoch-based training loop and setting the effective range (begin, end) or period (T_max) and other variables according to epoch in MMCV, you need to set by_epoch to False.
However, in MMEngine, the by_epoch in the config still needs to be set to True. Instead, you need to add convert_to_iter_based=True in the config to build a parameter scheduler which updates by iteration, see Parameter Scheduler Tutorial for more details.
Take the migration of CosineAnnealing as an example:
param_scheduler= [
dict(
type='CosineAnnealingLR',
eta_min=0.5,
T_max=num_epochs,
by_epoch=True, # Notice, by_epoch need to be set to Trueconvert_to_iter_based=True# convert to an iter-based scheduler
)
]