CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

How do I see that autoAdjust for learning rates is working?

Open ant0nsc opened this issue 10 years ago • 4 comments

I'm training image classifiers, and would like to use the auto-adjust feature for learning rates. From the CNTK book (sec 6.1.2) I got the following:

SGD=[
    epochSize=500000
    minibatchSize=128
    learningRatesPerMB=0.01*20:0.003*12:0.001*28:0.0003
    momentumPerMB=0.9
    maxEpochs=50
    gradUpdateType=None
    L2RegWeight=0.0005
    dropoutRate=0*5:0.5 
    <snip>
    ]
AutoAdjust=[
    autoAdjustLR="adjustAfterEpoch"
    reduceLearnRateIfImproveLessThan=0
    loadBestModel=true
    increaseLearnRateIfImproveMoreThan=1000000000
    learnRateDecreaseFactor=0.5
    learnRateIncreaseFactor=1.382
]

What should I be looking for in the log files as an indication that learning rate adjustment is happening? I see learning rates go down, exactly at the epochs I've specified in learningRatesperMB, but no other adjustment. Subset of the relevant log lines below.

[ 1 of 50]: TrainLoss = 0.33056159;  EvalErr = 0.145852; AvgLearningRatePerSample = 7.8124998e-005;
[ 2 of 50]: TrainLoss = 0.26867797;  EvalErr = 0.113708; AvgLearningRatePerSample = 7.8124998e-005;
[ 3 of 50]: TrainLoss = 0.24968333;  EvalErr = 0.103788; AvgLearningRatePerSample = 7.8124998e-005;
[ 4 of 50]: TrainLoss = 0.23899481;  EvalErr = 0.09858; AvgLearningRatePerSample = 7.8124998e-005; 
[ 5 of 50]: TrainLoss = 0.23045319;  EvalErr = 0.09432; AvgLearningRatePerSample = 7.8124998e-005; 
[ 6 of 50]: TrainLoss = 0.25406902;  EvalErr = 0.102806; AvgLearningRatePerSample = 7.8124998e-005;
[ 7 of 50]: TrainLoss = 0.23786711;  EvalErr = 0.095234; AvgLearningRatePerSample = 7.8124998e-005;
[ 8 of 50]: TrainLoss = 0.23296247;  EvalErr = 0.093562; AvgLearningRatePerSample = 7.8124998e-005;
[ 9 of 50]: TrainLoss = 0.22796863;  EvalErr = 0.090888; AvgLearningRatePerSample = 7.8124998e-005;
[10 of 50]: TrainLoss = 0.22359934;  EvalErr = 0.088766; AvgLearningRatePerSample = 7.8124998e-005;
[11 of 50]: TrainLoss = 0.22039156;  EvalErr = 0.087726; AvgLearningRatePerSample = 7.8124998e-005;
[12 of 50]: TrainLoss = 0.21881606;  EvalErr = 0.086496; AvgLearningRatePerSample = 7.8124998e-005;
[13 of 50]: TrainLoss = 0.21563614;  EvalErr = 0.085334; AvgLearningRatePerSample = 7.8124998e-005;
[14 of 50]: TrainLoss = 0.21374359;  EvalErr = 0.084376; AvgLearningRatePerSample = 7.8124998e-005;
[15 of 50]: TrainLoss = 0.21124869;  EvalErr = 0.083186; AvgLearningRatePerSample = 7.8124998e-005;
[16 of 50]: TrainLoss = 0.21076133;  EvalErr = 0.08343; AvgLearningRatePerSample = 7.8124998e-005; 
[17 of 50]: TrainLoss = 0.20787881;  EvalErr = 0.081774; AvgLearningRatePerSample = 7.8124998e-005;
[18 of 50]: TrainLoss = 0.20695247;  EvalErr = 0.081646; AvgLearningRatePerSample = 7.8124998e-005;
[19 of 50]: TrainLoss = 0.20494711;  EvalErr = 0.080588; AvgLearningRatePerSample = 7.8124998e-005;
[20 of 50]: TrainLoss = 0.20349531;  EvalErr = 0.079934; AvgLearningRatePerSample = 7.8124998e-005;
[21 of 50]: TrainLoss = 0.19138364;  EvalErr = 0.074836; AvgLearningRatePerSample = 2.34375e-005; E
[22 of 50]: TrainLoss = 0.19284798;  EvalErr = 0.075126; AvgLearningRatePerSample = 2.34375e-005; E
[23 of 50]: TrainLoss = 0.19002519;  EvalErr = 0.073802; AvgLearningRatePerSample = 2.34375e-005; E
[24 of 50]: TrainLoss = 0.18921558;  EvalErr = 0.073458; AvgLearningRatePerSample = 2.34375e-005; E
[25 of 50]: TrainLoss = 0.18737066;  EvalErr = 0.072686; AvgLearningRatePerSample = 2.34375e-005; E
[26 of 50]: TrainLoss = 0.18833814;  EvalErr = 0.073074; AvgLearningRatePerSample = 2.34375e-005; E
[27 of 50]: TrainLoss = 0.18619861;  EvalErr = 0.071984; AvgLearningRatePerSample = 2.34375e-005; E
[28 of 50]: TrainLoss = 0.18622889;  EvalErr = 0.072276; AvgLearningRatePerSample = 2.34375e-005; E
[29 of 50]: TrainLoss = 0.18611808;  EvalErr = 0.072282; AvgLearningRatePerSample = 2.34375e-005; E
[30 of 50]: TrainLoss = 0.18412914;  EvalErr = 0.071428; AvgLearningRatePerSample = 2.34375e-005; E
[31 of 50]: TrainLoss = 0.18434625;  EvalErr = 0.071708; AvgLearningRatePerSample = 2.34375e-005; E
[32 of 50]: TrainLoss = 0.18387931;  EvalErr = 0.07084; AvgLearningRatePerSample = 2.34375e-005; Ep
[33 of 50]: TrainLoss = 0.17778558;  EvalErr = 0.068328; AvgLearningRatePerSample = 7.8125004e-006;
[34 of 50]: TrainLoss = 0.17775016;  EvalErr = 0.068368; AvgLearningRatePerSample = 7.8125004e-006;
[35 of 50]: TrainLoss = 0.17824245;  EvalErr = 0.068332; AvgLearningRatePerSample = 7.8125004e-006;
[36 of 50]: TrainLoss = 0.17521142;  EvalErr = 0.067454; AvgLearningRatePerSample = 7.8125004e-006;
[37 of 50]: TrainLoss = 0.17499666;  EvalErr = 0.06722; AvgLearningRatePerSample = 7.8125004e-006; 
[38 of 50]: TrainLoss = 0.17683337;  EvalErr = 0.06803; AvgLearningRatePerSample = 7.8125004e-006; 
[39 of 50]: TrainLoss = 0.17521395;  EvalErr = 0.06703; AvgLearningRatePerSample = 7.8125004e-006; 
[40 of 50]: TrainLoss = 0.17547275;  EvalErr = 0.067278; AvgLearningRatePerSample = 7.8125004e-006;
[41 of 50]: TrainLoss = 0.17494184;  EvalErr = 0.06696; AvgLearningRatePerSample = 7.8125004e-006; 
[42 of 50]: TrainLoss = 0.17389006;  EvalErr = 0.066912; AvgLearningRatePerSample = 7.8125004e-006;
[43 of 50]: TrainLoss = 0.17457794;  EvalErr = 0.066972; AvgLearningRatePerSample = 7.8125004e-006;
[44 of 50]: TrainLoss = 0.17400442;  EvalErr = 0.066824; AvgLearningRatePerSample = 7.8125004e-006;
[45 of 50]: TrainLoss = 0.17352048;  EvalErr = 0.06626; AvgLearningRatePerSample = 7.8125004e-006; 
[46 of 50]: TrainLoss = 0.17265323;  EvalErr = 0.066498; AvgLearningRatePerSample = 7.8125004e-006;
[47 of 50]: TrainLoss = 0.172443;    EvalErr = 0.066432; AvgLearningRatePerSample = 7.8125004e-006; 
[48 of 50]: TrainLoss = 0.17197359;  EvalErr = 0.06561; AvgLearningRatePerSample = 7.8125004e-006;
[49 of 50]: TrainLoss = 0.17162655;  EvalErr = 0.065922; AvgLearningRatePerSample = 7.8125004e-006
[50 of 50]: TrainLoss = 0.17232008;  EvalErr = 0.066144; AvgLearningRatePerSample = 7.8125004e-006

ant0nsc avatar May 20 '16 13:05 ant0nsc

In response to the question of @frankseide: Yes, there is a cvReader specified:

cvReader=[
    readerType=ImageReader
    file=$DataDir$/myMappingFile.tsv
    randomize=Auto
    features=[
        width=224
        height=224
        channels=3
        cropType=Center
    ]
    labels=[
        labelDim=2
    ]
]    

Log lines including those from cvReader show that EvalErr on the validation set gets worse in epochs 18 and 19, but no change in learning rates. Similarly, TrainLoss gets worse in epoch 28, but I see no change in learning rate.

Also, can somebody clarify the sentence in the CNTK book in sec. 6.1.2, "performance on the held-out set" - is performance referring to the EvalErr or the TrainLoss ?

Log lines follow.

Epoch[10 [Training] TrainLoss = 0.22359934; TotalSamplesSeen = 5000000; AvgLearningRate = 7.8124998e-005;
Epoch[10 [Validation] TrainLoss = 0.20818494; EvalErr = 0.08293
Epoch[11 [Training] TrainLoss = 0.22039156; TotalSamplesSeen = 5500000; AvgLearningRate = 7.8124998e-005;
Epoch[11 [Validation] TrainLoss = 0.20654171; EvalErr = 0.08228
Epoch[12 [Training] TrainLoss = 0.21881606; TotalSamplesSeen = 6000000; AvgLearningRate = 7.8124998e-005;
Epoch[12 [Validation] TrainLoss = 0.2031351; EvalErr = 0.07983
Epoch[13 [Training] TrainLoss = 0.21563614; TotalSamplesSeen = 6500000; AvgLearningRate = 7.8124998e-005;
Epoch[13 [Validation] TrainLoss = 0.20235395; EvalErr = 0.07956
Epoch[14 [Training] TrainLoss = 0.21374359; TotalSamplesSeen = 7000000; AvgLearningRate = 7.8124998e-005;
Epoch[14 [Validation] TrainLoss = 0.20140273; EvalErr = 0.07954
Epoch[15 [Training] TrainLoss = 0.21124869; TotalSamplesSeen = 7500000; AvgLearningRate = 7.8124998e-005;
Epoch[15 [Validation] TrainLoss = 0.1979728; EvalErr = 0.07782
Epoch[16 [Training] TrainLoss = 0.21076133; TotalSamplesSeen = 8000000; AvgLearningRate = 7.8124998e-005;
Epoch[16 [Validation] TrainLoss = 0.19875933; EvalErr = 0.07724
Epoch[17 [Training] TrainLoss = 0.20787881; TotalSamplesSeen = 8500000; AvgLearningRate = 7.8124998e-005;
Epoch[17 [Validation] TrainLoss = 0.19627193; EvalErr = 0.07709
Epoch[18 [Training] TrainLoss = 0.20695247; TotalSamplesSeen = 9000000; AvgLearningRate = 7.8124998e-005;
Epoch[18 [Validation] TrainLoss = 0.19811846; EvalErr = 0.07786
Epoch[19 [Training] TrainLoss = 0.20494711; TotalSamplesSeen = 9500000; AvgLearningRate = 7.8124998e-005;
Epoch[19 [Validation] TrainLoss = 0.20673306; EvalErr = 0.08138
Epoch[20 [Training] TrainLoss = 0.20349531; TotalSamplesSeen = 10000000; AvgLearningRate = 7.8124998e-005;
Epoch[20 [Validation] TrainLoss = 0.19253801; EvalErr = 0.07541
Epoch[21 [Training] TrainLoss = 0.19138364; TotalSamplesSeen = 10500000; AvgLearningRate = 2.34375e-005;
Epoch[21 [Validation] TrainLoss = 0.18669268; EvalErr = 0.07342
Epoch[22 [Training] TrainLoss = 0.19284798; TotalSamplesSeen = 11000000; AvgLearningRate = 2.34375e-005;
Epoch[22 [Validation] TrainLoss = 0.18623109; EvalErr = 0.07392
Epoch[23 [Training] TrainLoss = 0.19002519; TotalSamplesSeen = 11500000; AvgLearningRate = 2.34375e-005;
Epoch[23 [Validation] TrainLoss = 0.18480431; EvalErr = 0.07178
Epoch[24 [Training] TrainLoss = 0.18921558; TotalSamplesSeen = 12000000; AvgLearningRate = 2.34375e-005;
Epoch[24 [Validation] TrainLoss = 0.18787638; EvalErr = 0.07313
Epoch[25 [Training] TrainLoss = 0.18737066; TotalSamplesSeen = 12500000; AvgLearningRate = 2.34375e-005;
Epoch[25 [Validation] TrainLoss = 0.18378688; EvalErr = 0.07099
Epoch[26 [Training] TrainLoss = 0.18833814; TotalSamplesSeen = 13000000; AvgLearningRate = 2.34375e-005;
Epoch[26 [Validation] TrainLoss = 0.18344182; EvalErr = 0.07248
Epoch[27 [Training] TrainLoss = 0.18619861; TotalSamplesSeen = 13500000; AvgLearningRate = 2.34375e-005;
Epoch[27 [Validation] TrainLoss = 0.18474305; EvalErr = 0.07028
Epoch[28 [Training] TrainLoss = 0.18622889; TotalSamplesSeen = 14000000; AvgLearningRate = 2.34375e-005;
Epoch[28 [Validation] TrainLoss = 0.18324048; EvalErr = 0.07058
Epoch[29 [Training] TrainLoss = 0.18611808; TotalSamplesSeen = 14500000; AvgLearningRate = 2.34375e-005;
Epoch[29 [Validation] TrainLoss = 0.18245653; EvalErr = 0.07105
Epoch[30 [Training] TrainLoss = 0.18412914; TotalSamplesSeen = 15000000; AvgLearningRate = 2.34375e-005;
Epoch[30 [Validation] TrainLoss = 0.18365912; EvalErr = 0.07115

ant0nsc avatar May 23 '16 10:05 ant0nsc

I tried to test the Autoadjust function with the following code, but I also couldn’t see any changes in the learning rate except those in the LearningRatePerMB parameter.

AutoAdjust=[ autoAdjustLR="adjustAfterEpoch" reduceLearnRateIfImproveLessThan=0.1 loadBestModel=true increaseLearnRateIfImproveMoreThan=0.1 learnRateDecreaseFactor=0.5 learnRateIncreaseFactor=1.2 learnRateAdjustInterval = 1 ]

SteFromGer avatar May 23 '16 13:05 SteFromGer

Looking at the code, the AutoAdjust-condition for cutting the LR is

(prevCriterion - avgCriterion <= m_reduceLearnRateIfImproveLessThan * prevCriterion)

where avgCriterion is the training objective (on the CV data of course) unless you specify useEvalCriterionControlLR=true which would make it use the first evaluation criterion instead.

In the sequence-to-sequence example, I see the expected behaviour. I include below the settings and the log for one of the runs of the seq-2-seq example (I am not 100% sure whether this is the precise config in the git repo). You can see how every time the CV loss does not improve (enough), the error rate is cut.

It is not what I see in your log though, and your settings are very similar to mine, so I am not quite sure why this would not work.

BTW, your version seems old. You may consider upgrading to 1.5. However, I don't think that there have been changes to AutoAdjust.

    # settings for Auto Adjust Learning Rate
    AutoAdjust = [
        autoAdjustLR = "adjustAfterEpoch"
        reduceLearnRateIfImproveLessThan = 0.001
        continueReduce = false
        increaseLearnRateIfImproveMoreThan = 1000000000
        learnRateDecreaseFactor = 0.5
        learnRateIncreaseFactor = 1.382
        numMiniBatch4LRSearch = 100
        numPrevLearnRates = 5
        numBestSearchEpoch = 1
    ]

Log:

% grep -e Finished -e "Sample reduced" G2P_train.log
Finished Epoch[ 1 of 50]: [Training] ce = 1.20555300 * 799289; errs = 35.507% * 799289; totalSamplesSeen = 799289; learningRatePerSample = 0.0070000002; epochTime=8168.92s
Finished Epoch[ 1 of 50]: [Validate] ce = 0.40261506 * 40079; errs = 13.144% * 40079
Finished Epoch[ 2 of 50]: [Training] ce = 0.28647572 * 799289; errs = 9.567% * 799289; totalSamplesSeen = 1598578; learningRatePerSample = 0.0070000002; epochTime=7762.6s
Finished Epoch[ 2 of 50]: [Validate] ce = 0.27184968 * 40079; errs = 8.947% * 40079
Finished Epoch[ 3 of 50]: [Training] ce = 0.17945836 * 799289; errs = 6.188% * 799289; totalSamplesSeen = 2397867; learningRatePerSample = 0.0035000001; epochTime=5351.52s
Finished Epoch[ 3 of 50]: [Validate] ce = 0.21666807 * 40079; errs = 7.176% * 40079
Finished Epoch[ 4 of 50]: [Training] ce = 0.15370188 * 799289; errs = 5.227% * 799289; totalSamplesSeen = 3197156; learningRatePerSample = 0.0035000001; epochTime=4742.62s
Finished Epoch[ 4 of 50]: [Validate] ce = 0.26149251 * 40079; errs = 7.563% * 40079
learnRatePerSample reduced to 0.0017500001
Finished Epoch[ 5 of 50]: [Training] ce = 0.10780444 * 799289; errs = 3.676% * 799289; totalSamplesSeen = 3996445; learningRatePerSample = 0.0017500001; epochTime=4750.91s
Finished Epoch[ 5 of 50]: [Validate] ce = 0.26104782 * 40079; errs = 6.921% * 40079
Finished Epoch[ 6 of 50]: [Training] ce = 0.08686798 * 799289; errs = 2.906% * 799289; totalSamplesSeen = 4795734; learningRatePerSample = 0.0017500001; epochTime=4723.55s
Finished Epoch[ 6 of 50]: [Validate] ce = 0.26951229 * 40079; errs = 7.158% * 40079
learnRatePerSample reduced to 0.00087500003
Finished Epoch[ 7 of 50]: [Training] ce = 0.06175954 * 799289; errs = 2.087% * 799289; totalSamplesSeen = 5595023; learningRatePerSample = 0.00087500003; epochTime=4709.09s
Finished Epoch[ 7 of 50]: [Validate] ce = 0.29914652 * 40079; errs = 6.926% * 40079
learnRatePerSample reduced to 0.00043750001
Finished Epoch[ 8 of 50]: [Training] ce = 0.04764013 * 799289; errs = 1.592% * 799289; totalSamplesSeen = 6394312; learningRatePerSample = 0.00043750001; epochTime=4715.97s
Finished Epoch[ 8 of 50]: [Validate] ce = 0.31409274 * 40079; errs = 6.951% * 40079
learnRatePerSample reduced to 0.00021875001
Finished Epoch[ 9 of 50]: [Training] ce = 0.04041496 * 799289; errs = 1.390% * 799289; totalSamplesSeen = 7193601; learningRatePerSample = 0.00021875001; epochTime=4738.65s
Finished Epoch[ 9 of 50]: [Validate] ce = 0.34033528 * 40079; errs = 6.986% * 40079
learnRatePerSample reduced to 0.000109375
Finished Epoch[10 of 50]: [Training] ce = 0.03455538 * 799289; errs = 1.258% * 799289; totalSamplesSeen = 7992890; learningRatePerSample = 0.000109375; epochTime=5013.36s
Finished Epoch[10 of 50]: [Validate] ce = 0.34865011 * 40079; errs = 6.984% * 40079
learnRatePerSample reduced to 5.4687502e-005
Finished Epoch[11 of 50]: [Training] ce = 0.03406198 * 799289; errs = 1.200% * 799289; totalSamplesSeen = 8792179; learningRatePerSample = 5.4687502e-005; epochTime=5159.92s
Finished Epoch[11 of 50]: [Validate] ce = 0.35735342 * 40079; errs = 7.044% * 40079
learnRatePerSample reduced to 2.7343751e-005
Finished Epoch[12 of 50]: [Training] ce = 0.02900090 * 799289; errs = 1.118% * 799289; totalSamplesSeen = 9591468; learningRatePerSample = 2.7343751e-005; epochTime=5091.35s
Finished Epoch[12 of 50]: [Validate] ce = 0.36414414 * 40079; errs = 7.041% * 40079
learnRatePerSample reduced to 1.3671875e-005
Finished Epoch[13 of 50]: [Training] ce = 0.03112283 * 799289; errs = 1.117% * 799289; totalSamplesSeen = 10390757; learningRatePerSample = 1.3671875e-005; epochTime=5100.17s
Finished Epoch[13 of 50]: [Validate] ce = 0.36537774 * 40079; errs = 7.046% * 40079
learnRatePerSample reduced to 6.8359377e-006
Finished Epoch[14 of 50]: [Training] ce = 0.03166310 * 799289; errs = 1.103% * 799289; totalSamplesSeen = 11190046; learningRatePerSample = 6.8359377e-006; epochTime=4819.36s
Finished Epoch[14 of 50]: [Validate] ce = 0.36613970 * 40079; errs = 7.051% * 40079
learnRatePerSample reduced to 3.4179689e-006
Finished Epoch[15 of 50]: [Training] ce = 0.02988654 * 799289; errs = 1.077% * 799289; totalSamplesSeen = 11989335; learningRatePerSample = 3.4179689e-006; epochTime=4502.97s
Finished Epoch[15 of 50]: [Validate] ce = 0.36657301 * 40079; errs = 7.051% * 40079
learnRatePerSample reduced to 1.7089844e-006

frankseide avatar Jun 15 '16 16:06 frankseide

Closing as answered. Feel free to re-open or a file a new issue if necessary. Thanks!

mahilleb-msft avatar Jul 14 '17 12:07 mahilleb-msft