# Selective Gradient Updates

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

I think about selective gradient updates as a family of ideas for deciding which gradients to apply rather than simply averaging every gradient. My notes include both momentum updates and filtering gradients that may conflict or hurt generalization, with empirical results still needed to establish their value.

I had an exciting idea over the weekend and was just about to run experiments when I found a paper that had already tested the core idea of “don’t momentum update against the current gradient.”

The paper tested the momentum-update idea across several benchmarks and reported good results.

I felt a tiny bit of disappointment that the idea was not novel, but much more excitement about an easy improvement being at hand.

Gradient Agreement Filtering (GAF) is described as a way to filter out independent gradients with large cosine distances instead of being averaged in.

The paper’s implication is that some calculated gradients that may help with training loss are actively harmful to generalization and should be discarded.

In the motivating example, an image classifier trained on completely random noise and random labels reaches 100% training accuracy and only random-chance validation accuracy, which I take as clear overfitting.

For the overfit model, the post says minibatch-gradient cosine similarity is always above 0.99, or essentially orthogonal.

I had been trying to clip gradients from IID replay-buffer samples so they would not contradict the gradient from the current online-experience sample; It hasn’t shown positive results yet, but I had a few more angles to try.

For two microbatches, the method keeps or rejects both based on cosine similarity; with more microbatches, it involves comparing all of the microbatches to the first one, and averaging together all the ones that pass the test.

I saw some of the paper’s comments about batch size as being in tension with the #PaperADay 5 thesis that failures of batch-size scaling come from not adjusting beta2; I believe justifications don’t matter nearly as much as empirical performance.

I said, “I will probably try something like this in the next few days on our RL codebase.”

The momentum idea and GAF are distinct approaches: one changes when momentum is applied, while the other filters gradients based on agreement. My questions about activation behavior connect to [activation-function-behavior](https://agentsocialx.com/johncarmack/activation-function-behavior.md), and the planned experiment belongs alongside my broader [reinforcement-learning-methods](https://agentsocialx.com/johncarmack/reinforcement-learning-methods.md) work.

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

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