r/deeplearning • u/ModularMind8 • Oct 02 '26
Gradient descent vs evolution on three loss landscapes
I've been getting a bit more into evolutionary algorithms again, so I was testing some loss landscapes where evolution beats vanilla gradient descent (while also trying to make some cool visuals).
Round 1, rugged hillside: gradient descent gets stuck in a dip, and evolution reaches the bottom after 750 evaluations.
Round 2, smooth slope: gradient descent wins, 108 steps against 570 evaluations.
Round 3, flat plateau: the slope is zero, so gradient descent never moves, and evolution reaches the bottom after 840 evaluations.
Edit:
"evolution" here means truncation selection (keep best 30 of 120) plus Gaussian mutation, no crossover.
9
u/WiredFan Oct 02 '26
How expensive is it to calculate the gradient vs just the value/loss at a point?
5
u/ModularMind8 Oct 02 '26
I believe with backprop a gradient costs roughly 2-3 loss evaluations regardless of parameter count (the standard reverse-mode autodiff rule of thumb, one forward plus one similarly priced backward pass), so it stays cheap even at scale
7
u/AtMaxSpeed Oct 03 '26
It would be great to also visualize how modern GD algorithms work on various landscapes. Evolution and SGD are very intuitive/easy to imagine so the visualization just shows what we expect, but modern GD algos are harder to imagine so there would be a lot of value in visualizing those.
3
u/ModularMind8 Oct 03 '26
Agreed! Adam, momentum and SGD on these same landscapes is next on my list :)
4
u/superlus Oct 02 '26
What do you want to tell with this comparison..? The convergence seems highly dependent on hyperparameter/loss choices for both GD and the EA.
3
u/ModularMind8 Oct 02 '26
Honestly, no deeper message: evolutionary algorithms are cool and sometimes beat GD, and yes, these results depend on hyperparameters
2
u/0bi_nx Oct 02 '26
Its a cool visualization. Do you think evolution is applicable to deep learning? You planning to test against stochastic gradient descent, ADAM or Muon?
2
u/ModularMind8 Oct 02 '26
Thanks :)
I definitely think so! Take a look at "Evolution Strategies at the Hyperscale" as an example, and yes, an Adam/SGD comparison is a fun next one.3
u/drcopus Oct 02 '26
As an author on that paper I'm pleasantly happy to see it mentioned here! :)
2
u/ModularMind8 Oct 02 '26
Wow, it's an honor :) Beautifully written paper
2
u/drcopus Oct 02 '26
The first 3 authors deserve most of the credit! I'm happy to have made a contribution but I wasn't a main author haha
2
u/ModularMind8 Oct 02 '26
I'm sure you're just being modest!
Since you're the expert, curious if you've read the Sakana AI book (Neuroevolution: Harnessing Creativity in AI Agent Design) that just came out. And if so, what are your thoughts? :)
2
u/AllergicToBullshit24 Oct 02 '26
Think it would be very interesting to blend techniques similar to cosine schedule for learning rate perhaps using evolution on a schedule or whenever gradient descent may be getting stuck in a local min pocket.
1
u/ModularMind8 Oct 02 '26
Love that idea! Population based training does something close, I think, where running gradient descent with periodic evolutionary exploit-and-explore steps
2
u/AllergicToBullshit24 Oct 02 '26
I need to try this intuitively seems like it could unlock better performance out of smaller parameter counts.
1
u/ModularMind8 Oct 02 '26
Would love to see what you find!
1
u/AllergicToBullshit24 Oct 02 '26
If only I had an NVL72 B300 rack or two to play with the research queue on my limited hardware is already backed up worse than LA rush hour.
Not jealous of the frontier labs capacity at all. /s
2
2
2
16
u/LiorZim Oct 02 '26
You don't use plain GD in deep neural networks optimization. GD works only in convex optimization, for non-convex optimization we use the stochastic variant with an optimization strategy like ADAM that gives the process something akin to velocity and acceleration, helping it to "climb" rugged landscapes like the one you showed here :-)
8
u/DoubleOtter2 Oct 03 '26 edited Oct 04 '26
As someone who studied and used many optimization algorithms, including genetic algorithms like SAEM, gradient descent always felt too simple. But as other commenters point out, real high-dimension landscapes relevant to deep learning are not like this. By construction, the abundance of possibly redundant parameters with smooth non linearities creates a locally smooth landscape.
Also, very importantly, deep learning losses are differentiable in closed form. This has an insanely huge impact. Without this, estimating a gradient takes at least N (or frequently 2N or more) evaluations with N the number of parameters!
The video that made it click for me is this one from welch labs. All the key ingredient are in there. I recommend it.
2
u/Equal_Passenger9791 Oct 03 '26
You probably want to prune that YouTube link a bit to not reveal your name to those who click it just FYI
1
4
u/WobblyBlackHole Oct 03 '26
A kind of half way method I read once was to have n gradient decent with different learning rates, and then take the top k and copy them into n with different learning rates
1
u/WiredFan Oct 02 '26
How’s the performance?
1
u/ModularMind8 Oct 02 '26
For this set of landscapes, on the smooth slope gradient descent is ~5x cheaper (108 vs 570 evaluations). Evolution wins where gradients mislead or vanish
1
u/macumazana Oct 02 '26
What if the next minima is not nearby the current local one er even the next one isnt smaller but the farthest one is?
1
u/ModularMind8 Oct 02 '26
Good question! I haven't tried that landscape yet. I'll add it to the next experiment
1
u/Envoy-Insc Oct 02 '26
While applicable in small scale settings, Local minimums like those in first don’t tend to exist in high dim high param spaces in my impression
1
u/ModularMind8 Oct 02 '26
Definitely some landscapes favor GD, though papers like "Evolution Strategies at the Hyperscale" show evolution can work well
1
u/Envoy-Insc Oct 02 '26
I really liked the idea of that paper, but paper actually don’t scale to llm scale if we look at the experiments
1
u/PK_thundr Oct 02 '26
Afaik there are three things that help gradient descent work in practice so well.
Momentum terms
Stochasticity usually ensures that you wont be in a flat region of the loss landscape once you pull the next batch
There was a Bengio paper a while ago that argued most local minima might actually be within some epsilon loss of each other
1
u/ModularMind8 Oct 02 '26
Great points. This video uses plain gradient descent, so adding momentum and minibatch noise (or changing to adam) is a fair next comparison
1
u/msw3age Oct 02 '26
Very nice visualization. Would be cool to see the evolutionary algorithms vs SGD. To some extent it seems like the visualization is mostly showing the benefits of stochasticity during training.
1
u/ModularMind8 Oct 02 '26
Thanks! That's a fair read, and SGD with noise is on the list for the next comparison
1
u/alrojo Oct 02 '26
Random search degrades as a function feature space. Look up Curse of Dimensionality
1
u/ModularMind8 Oct 02 '26
Agreed! The search here is deliberately simple, and more sophisticated evolutionary methods like CMA-ES cope better as dimensions grow
1
u/hardcoke Oct 03 '26
Interesting...what if crossover is introduced?
2
u/ModularMind8 Oct 03 '26
Haven't tried it yet, though with only 2 parameters in this experiment crossover just swaps x and y between parents, so I'd expect a small effect
1
u/IcyGlia Oct 03 '26
Does the whole dataset fit into one mini batch? I would expect random batch to batch variations to sometimes kick you out of the local minimum. As the loss landscape doesn’t change, I assume the error landscape is the whole dataset since it doesn’t change? Adding noise to the data could be interesting to see if that rescues gradient descent.
1
u/ModularMind8 Oct 03 '26
No dataset here, each landscape is a fixed 2D function, so it's full-batch GD, and noise is next on my list
1
u/UnderstandingOwn2913 Oct 09 '26
how did you make this visualization?
2
u/ModularMind8 Oct 09 '26
I made it with a Python script that builds the landscapes in NumPy, renders the frames in PyVista, and joins them with ffmpeg.
2
u/trenmost Oct 03 '26
I think when you get to thousands of dimensions, SGD (especially with ADAM) would be more efficient
1
u/pnachtwey Oct 02 '26
The test is rigged! I have spent a lot of time on optimizing routines. No one technique is going to be best for all terrains. GD is simple but no where closed to optimal. SGD is better when there are many dimensions. Sometimes optimizing only one dimension at a time works well but it is slow. Nelder-Mead works well when it is hard to find the gradient accurately and there aren't many dimensions.. N-M can be a memory hog. Levenberg-Marquardt is the fastest. In python, use lmfit or scipys.optimize least_squares. BFGS works well too. So it is best to make the search flexible.
I would like to have the data used so I could try other techniques.
I uses minimization for fitting models to data for auto tuning programs. The method I used most often is Levenberg-Marquardt.
1
1
u/AsliReddington Oct 02 '26
But can you actually run with updated loss landscape as well since every backward pass causes the landscape to update as well over time
1
u/TheRealStepBot Oct 02 '26
In my experience it’s very hard to beat Adamw on practical problems that have decently well behaved loss landscapes especially on speed of convergence either wall clock or number of operations performed.
1
u/PlusIndication8386 Oct 03 '26
Evolution looks great until you try GD with random restarts for this type of problem
1
u/concrete_aircraft Oct 04 '26
nobody uses just gradient descent all the libraries in python they introduce noise using perturbations and other parameters to reach the most optimal solution. And also evolutionary algorithms are computationally expensive over gradient descent
1
u/LelouchZer12 Oct 08 '26
Now gradient descent with momentum ? adam ?
Plus the more dimension you add, the more chance you can "decrease" in at least one direction and hence not end up being stuck. This is the blessing of dimensionality.
68
Oct 02 '26
[removed] — view removed comment
20
u/ModularMind8 Oct 02 '26
Really appreciate that! It's a simple mutation-plus-selection loop: 120 points start near the same spot, each generation I keep the 30 with the lowest loss and replace the other 90 with copies of those survivors plus Gaussian noise. The noise starts wide and shrinks about 2.5% per generation, so it explores first and settles later, and it never uses a gradient, only loss values
11
32
u/ForceBru Oct 02 '26
Yeah, "evolution" is a whole family of algorithms
31
u/ModularMind8 Oct 02 '26
True, I'll clarify this in the post. This one is a simple one: truncation selection plus Gaussian mutation, no crossover
2
Oct 02 '26
[removed] — view removed comment
2
2
u/AtMaxSpeed Oct 03 '26
It's fun to incorporate biological techniques into algorithms, but afaik what you describe is basically what RMSprop (and hence Adam) already do - they increase the step size when the gradient is small (aka, it cranks up exploration when in a plateau).
22
u/MentionJealous9306 Oct 02 '26
What is the dimensionality of this problem?