x-evolution
Implementation of various evolutionary algorithms, starting with evolutionary strategies
Install
$ pip install x-evolution
Usage
import torch
from x_evolution import EvoStrategy
# model
from torch import nn
model = torch.nn.Sequential(
nn.Linear(8, 16),
nn.ReLU(),
nn.Linear(16, 4)
)
# evolution wrapper
evo_strat = EvoStrategy(
model,
environment = lambda model: torch.randint(0, 100, ()), # environment is just a function that takes in the individual model (with unique noise) and outputs a scalar (the fitness) the measure you are selecting for
noise_population_size = 30, # increase this for better gradient estimates
noise_scale = 1e-2, # the scale of the perturbation noise, also the initial noise scale (sigma) if `learned_noise_scale` = True
num_generations = 100, # number of generations / training steps
learning_rate = 1e-3, # scale on update derived by fitness and perturb noises
params_to_optimize = None # defaults to all parameters, but can be [str {param name}] or [Parameter]
)
# do evolution with your desired fitness function for so many generations
evo_strat()
# model will be saved under checkpoints/ folder
# can also specify checkpoint_every at init and select the one with your favored fitness score for continued policy gradient learning etc
Distributed
Using the CLI from 🤗
$ uv run accelerate config
Then
$ uv run accelerate launch train.py
Or with torchrun (which can do multiple CPU processes for testing)
$ uv run torchrun --nproc_per_node=<N> train.py --cpu True
For a quick demo on LunarLander with 8 processes
$ uv run torchrun --nproc_per_node=8 train_lunar.py --cpu True --noise_population_size 100 --fitness_to_weighted_factor centered_rank
Sim-to-Real Bipedal Locomotion (Microduck)
You can train a walking gait for the Microduck biped robot from scratch using EvoStrategy and torchrun.
With a population size of 128 distributed across 8 CPU processes, a forward walking gait emerges around 150 generations (~3-4 minutes):
$ uv run torchrun --nproc_per_node=8 train_microduck.py
To render evaluation videos or resume from the saved best checkpoint:
# render periodic evaluation videos to videos/
$ uv run torchrun --nproc_per_node=8 train_microduck.py --eval_video True --eval_every 50
# resume training from best checkpoint
$ uv run torchrun --nproc_per_node=8 train_microduck.py --resume True
Special thanks to Pollen Robotics 🤗 for their open sourcing of such a polished sim2real env!
Citations
@article{Qiu2025EvolutionSA,
title = {Evolution Strategies at Scale: LLM Fine-Tuning Beyond Reinforcement Learning},
author = {Xin Qiu and Yulu Gan and Conor F. Hayes and Qiyao Liang and Elliot Meyerson and Babak Hodjat and Risto Miikkulainen},
journal = {ArXiv},
year = {2025},
volume = {abs/2509.24372},
url = {https://api.semanticscholar.org/CorpusID:281674745}
}
@misc{sarkar2025evolutionstrategieshyperscale,
title = {Evolution Strategies at the Hyperscale},
author = {Bidipta Sarkar and Mattie Fellows and Juan Agustin Duque and Alistair Letcher and Antonio León Villares and Anya Sims and Dylan Cope and Jarek Liesen and Lukas Seier and Theo Wolf and Uljad Berdica and Alexander David Goldie and Aaron Courville and Karin Sevegnani and Shimon Whiteson and Jakob Nicolaus Foerster},
year = {2025},
eprint = {2511.16652},
archivePrefix = {arXiv},
primaryClass = {cs.LG},
url = {https://arxiv.org/abs/2511.16652},
}
@misc{fortunato2019noisynetworksexploration,
title = {Noisy Networks for Exploration},
author = {Meire Fortunato and Mohammad Gheshlaghi Azar and Bilal Piot and Jacob Menick and Ian Osband and Alex Graves and Vlad Mnih and Remi Munos and Demis Hassabis and Olivier Pietquin and Charles Blundell and Shane Legg},
year = {2019},
eprint = {1706.10295},
archivePrefix = {arXiv},
primaryClass = {cs.LG},
url = {https://arxiv.org/abs/1706.10295},
}
@article{ha2017visual,
title = "A Visual Guide to Evolution Strategies",
author = "Ha, David",
journal = "blog.otoro.net",
year = "2017",
url = "https://blog.otoro.net/2017/10/29/visual-evolution-strategies/"
}
@misc{dahal2026backprop,
title = {Dust: Pretraining Transformers Without Backpropagation},
author = {Dahal, Samip and Mandal, Bishwas and G{\"u}lbahar, Serdar and Vegesna, Akshay},
year = {2026},
url = {https://qlabs.sh/research/dust}
}
Nothing makes sense except in the light of evolution - Theodosius Dobzhansky
Metadata
Release files for x-evolution 0.1.35
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| x_evolution-0.1.35.tar.gz | 15.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| x_evolution-0.1.35-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.1 kB
Release files / x_evolution-0.1.35.tar.gz
| Download URL | x_evolution-0.1.35.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2c021ca26478954c74ed4da1443a7f4e461340167e62e2d4618d98789071d9fc
|
|
BLAKE2b-256 checksum How to use checksums |
c8c4d3cdbcd8467c1eba3f2df91d4cbe998744681580964fc87ba627335fe53e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Release files / x_evolution-0.1.35-py3-none-any.whl
| Download URL | x_evolution-0.1.35-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
19132c865d5a8fd0b2bd633827451effd00f02bd41f9f5acd315144653343508
|
|
BLAKE2b-256 checksum How to use checksums |
a507fda128ac85a6bea098c2b4245f607ba8ab6aa17a2e465240373a56051a4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|