Advice for Optimizer and CycleLR with Transformer training

pumplerod: <p>I’m seeking advice for a learning rate scheduler while training a Transformer based model.  It is my understanding that it is quite possible for the training process to take a very long time ( perhaps &gt; 10k itterations).  With such a lengthy training period it becomes difficult to know whether I’m stuck in an intractable situation and should give up, or continue processing.  As such, I’ve found that using a simple “reduce on plateau” type learning rate will often shrink to a point that hardly seems useful.  So there is some logic, in my thinking, to use a cyclical learning rate when training on something which may last for tens or hundreds of thousands of iterations.  Am I correct in that assumption?  What is the standard practice for these extremely long training sessions?  Are Transformers better suited for one method over another?</p>
<p>This is my current optimizer/scheduler setup…</p>
<pre><code class="lang-auto">learn_rate = 4e-3
optimizer = torch.optim.Adam( model.parameters(), lr=learn_rate)
main_scheduler = torch.optim.lr_scheduler.CyclicLR(optimizer, base_lr=1e-6, max_lr=4e-3, step_size_up=20, step_size_down=100, cycle_momentum=False)
</code></pre>
<p>So my understanding is that it will start with the small <code>lr=1e-6</code> and over 20 iterations increase to <code>lr=4e-3</code> then cycle back to <code>lr=1e-6</code> over the next 100 iterations, and begin again ad-infinitum.</p>
<p>Something I didn’t expect was to see such a jagged response in the loss curves.  Rather than showing a slow, rapid, slow, rapid, etc… rate of learning, it actually appears as though there is a reversal of learning during the first cycle followed by an increased learning during the second cycle.  For example, here is a training curve for cross entropy loss on the training class…<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/9/e9a0f2d312492af294895d31c91d08421f9d9d80.png" data-download-href="https://discuss.pytorch.org/uploads/default/e9a0f2d312492af294895d31c91d08421f9d9d80" title="train_class_loss"><img src="https://discuss.pytorch.org/uploads/default/original/3X/e/9/e9a0f2d312492af294895d31c91d08421f9d9d80.png" alt="train_class_loss" data-base62-sha1="xkM52lJEPlUCIDb0T338QQVZM2s" width="690" height="196" data-dominant-color="333738"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">train_class_loss</span><span class="informations">799×227 6.44 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
Each of the training loss curves share this characteristic.</p>
<p>Have I, perhaps, made a mistake in my implementation of the scheduler?<br>
Should I not be using the Adam optimizer with the CycleLR scheduler?<br>
Is there a rule of thumb for how long I should let the transformer train before assuming failure?</p>
<p>The training is done in batches of 1000, with approximately 5000 batches in each epoch.  So I expect it might be reasonable to take a very long time to learn the data.  But is there guidance for what I should actually expect?  Do I really let this run for months and still not be sure if it needs more time?</p>
<p>I don’t have the resources of a Google or OpenAI, but is there information on just how long these LLMs took to train?  Their batch size, number of batches in an epoch?  How many epochs of training?  the optimizer and style of learning rate schedules used?  That would all be very interesting information for someone trying to work with their own large dataset.  My small test datasets work well, but I’m just not sure what to expect when I scale up.</p>