0
0
PyTorchml~12 mins

StepLR and MultiStepLR in PyTorch - Model Pipeline Trace

Choose your learning style9 modes available
Model Pipeline - StepLR and MultiStepLR

This pipeline shows how learning rate schedulers StepLR and MultiStepLR adjust the learning rate during training to help the model learn better and faster.

Data Flow - 5 Stages
1Data Loading
1000 rows x 10 featuresLoad dataset with 10 features per sample1000 rows x 10 features
[[0.5, 1.2, ..., 0.3], [0.1, 0.4, ..., 0.7], ...]
2Model Initialization
1000 rows x 10 featuresInitialize a simple neural network with 10 input nodes and 2 output nodesModel ready for training
Neural network with layers: Input(10) -> Hidden(5) -> Output(2)
3Optimizer Setup
Model parametersSet optimizer with initial learning rate 0.1Optimizer ready
SGD optimizer with lr=0.1
4Learning Rate Scheduler Setup
Optimizer with lr=0.1Apply StepLR or MultiStepLR scheduler to adjust learning rate during trainingScheduler ready to update learning rate
StepLR with step_size=5, gamma=0.5 or MultiStepLR with milestones=[3,7], gamma=0.1
5Training Loop
Training data and modelTrain model for 10 epochs, update learning rate each epoch using schedulerTrained model with updated learning rates
Epoch 1 lr=0.1, Epoch 5 lr=0.05 (StepLR), Epoch 3 lr=0.01 (MultiStepLR)
Training Trace - Epoch by Epoch
Loss
1.0 |*
0.9  | *
0.8  |  *
0.7  |   *
0.6  |    *
0.5  |     *
0.4  |      *
0.3  |       *
     +----------------
      1 2 3 4 5 6 7 8 9 10 Epochs
EpochLoss ↓Accuracy ↑Observation
10.850.60Initial training with learning rate 0.1
20.700.68Loss decreased, accuracy improved
30.600.72Learning rate unchanged for StepLR, decreased for MultiStepLR
40.550.75Model continues to improve
50.500.78StepLR reduces learning rate by gamma=0.5 here
60.450.80Lower learning rate helps fine-tune weights
70.420.82MultiStepLR reduces learning rate at this milestone
80.400.83Training stabilizes with smaller learning rate
90.380.84Model converges further
100.360.85Final epoch with lowest learning rate
Prediction Trace - 3 Layers
Layer 1: Input Layer
Layer 2: Hidden Layer (ReLU)
Layer 3: Output Layer (Softmax)
Model Quiz - 3 Questions
Test your understanding
What does the StepLR scheduler do during training?
AReduces learning rate by a factor after fixed number of epochs
BIncreases learning rate gradually every epoch
CKeeps learning rate constant throughout training
DRandomly changes learning rate each epoch
Key Insight
Learning rate schedulers like StepLR and MultiStepLR help the model train better by reducing the learning rate at strategic points, allowing faster learning early on and finer adjustments later to improve accuracy and reduce loss.