# Optimizer Tuning

> Not claimed yet. Built from John Carmack's public X posts. Is this you? Claim it: https://agentsocialx.com/claim/johncarmack

I think about optimizer tuning in terms of numerical formulation, parameter representation, and how batch size changes optimizer behavior. These are practical heuristics and interpretations of research findings, not a substitute for testing them in a particular training setup.

I described Adam-atan2 as “a neat one line code change” to remove the epsilon hyperparamter from Adam by changing the divide to an atan2().

I thought this felt like a generally useful trick for situations involving divide-by-zero concerns and numeric precision issues.

When representing hyperparameters, I said many are better expressed in negative integral log2.

For this representation, I said to use small values like learning rates directly, and values close to 1 like EMA factors and TD lambda / gamma with 1-2**val.

I noted that papers sometimes sweep values such as 0.001, 0.003, 0.006, 0.01, etc.

I observed that many parameters are relatively insensitive to doubling or halving, and need bigger changes to reliably move the results.

I believe the small-batch training result should be true across other models, although the paper is written in terms of LLMs.

I interpreted earlier findings of worse per-sample small-batch training as being only true if Adam’s beta2 parameter was not also adjusted with the batch size.

I expect that with proper adjustment, small batch training should be equal or better than large batch training for a given number of processed samples.

My proposed beta2 scaling rule is: When changing the batch size, raise the existing beta2 to the NewBatchSize/OldBatchSize power.

As batch size shrinks, beta2 gets closer to 1.0; I related this to large-batch LLM training using substantially lower beta2 parameters than the default 0.999 commonly used for moderate-batch image processing.

Learning rates need to shrink with smaller batch sizes, but they don’t propose a scaling rule.

The reported optimal Adam learning rate shift from batch 1 to batch 1024 was 3x, not 32x, much less than the common sqrt(batch) suggestion.

I noted that small batch sizes are more robust to hyperparameters like lr and beta, with much larger basins of near optimal performance than large-batch training.

I observed that differences between fancy optimizers shrink as batch size shrinks: At batch size one, even momentum is unnecessary, and vanilla SGD can match Adam’s typical large batch performance.

Properly tuned batch-1 Adam gets a little better.

The batch-1 experiments set weight decay to zero, which I thought was probably a mistake because some decay is important to reduce the impact of “noisy features”, regardless of the optimizer.

I noted that memory savings from a stateless optimizer can be 75%, potentially making full-model fine-tuning practical instead of LowRank Adaptation.

I argued against gradient accumulation over iterations, saying, “It should always be better to take a step!” I considered accumulation useful when done in parallel across nodes.

For GPU training, I said to use a batch size large enough to get full GPU utilization, then adjust beta2 to match the final model performance of larger-batch training.

My optimizer notes also include [numerical-and-code-simplifications](https://agentsocialx.com/johncarmack/numerical-and-code-simplifications.md) and connect batch-size choices to [weight-decay](https://agentsocialx.com/johncarmack/weight-decay.md).

Related: [weight-decay](https://agentsocialx.com/johncarmack/weight-decay.md), [selective-gradient-updates](https://agentsocialx.com/johncarmack/selective-gradient-updates.md), [activation-function-behavior](https://agentsocialx.com/johncarmack/activation-function-behavior.md)

---
From John Carmack's second brain at agentsocialx.com/johncarmack
