PyTorch using LR-Scheduler with param groups of different LR's
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Using different learning rates for different parameter groups is standard in PyTorch, especially for transfer learning and models with separate backbones and heads. Learning-rate schedulers work with those groups, but you need to understand whether the scheduler applies the same multiplier to every group or whether you must define separate behavior yourself.
Define Parameter Groups Explicitly
The optimizer is where group-specific base learning rates are declared.
Here the head learns ten times faster than the backbone, which is a common fine-tuning setup.
Standard Schedulers Scale All Groups from Their Own Base Rates
Most built-in schedulers do not erase the fact that the groups started at different rates. They apply a schedule to each group while preserving the relative difference.
In a training loop:
Both groups decay on the same schedule, but the backbone remains lower than the head.
Use LambdaLR for Different Group Schedules
If the groups need different schedules rather than just different starting rates, use LambdaLR with one lambda function per parameter group.
This example keeps the backbone steady longer while decaying the head earlier and more aggressively. That pattern is useful when the task head converges quickly but the pretrained backbone needs smaller, more stable updates.
Log Effective Learning Rates During Training
Do not trust your mental model alone. Print the effective learning rates and confirm they follow the intended schedule.
This is a simple check, but it catches many configuration mistakes before they affect model quality.
Save Scheduler State with the Optimizer
If you pause and resume training, save the scheduler state along with the model and optimizer. Otherwise resumed training can continue with the wrong rates.
When loading, restore all three components so the schedule continues from the correct point.
Know When Step Timing Matters
One common source of confusion is when to call scheduler.step(). For many epoch-based schedulers, the typical pattern is to call it after optimizer.step(). Some schedulers are intended for batch-level updates instead, so always check the specific scheduler contract you are using.
The important part is consistency. If you designed the schedule per epoch, step it per epoch. If the scheduler is tied to batches, step it per batch.
Common Pitfalls
A common mistake is expecting a standard scheduler to produce different decay shapes for different groups automatically. Most of them apply the same rule to every group unless you configure separate behavior.
Another problem is forgetting to inspect the actual learning rates after a checkpoint restore. If the scheduler state was not restored, the optimizer may continue at the wrong stage of the schedule.
Developers also sometimes call scheduler.step() in the wrong place or at the wrong frequency, which shifts the schedule even though the code still runs.
Summary
- Use optimizer parameter groups to assign different base learning rates.
- Standard schedulers usually scale each group while preserving relative differences.
- Use
LambdaLRwhen groups need genuinely different schedule shapes. - Log learning rates during training to verify that the schedule matches your intent.
- Save and restore scheduler state together with model and optimizer state.
Related reading
- PyTorch What's the difference between state_dict and parameters?
- Quantize a Keras neural network model
- Question about Backpropagation Algorithm with Artificial Neural Networks -- Order of updating
- Rank error in tf.nn.dynamic_rnn
- Pytorch ValueError optimizer got an empty parameter list
- Random Choice with Pytorch?
- RBM implementation with tensorflow
- Read big train/validation/test datasets in tensorflow
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.