Skip to main content

x-evolution

Project description

x-evolution

Implementation of various evolutionary algorithms, starting with evolutionary strategies

explained by @bycloud

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

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/"
}

Nothing makes sense except in the light of evolution - Theodosius Dobzhansky

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

x_evolution-0.1.33.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

x_evolution-0.1.33-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file x_evolution-0.1.33.tar.gz.

File metadata

  • Download URL: x_evolution-0.1.33.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for x_evolution-0.1.33.tar.gz
Algorithm Hash digest
SHA256 92d1953838d71d20f990678a844a9c259f01578005f3df3528820a5af728390d
MD5 42ba956526da197d876213a2e380189b
BLAKE2b-256 66c9b80fda93204ef25e76cd6e725bd490e03ec0f2b0e6bff8b67a332220e9a4

See more details on using hashes here.

File details

Details for the file x_evolution-0.1.33-py3-none-any.whl.

File metadata

File hashes

Hashes for x_evolution-0.1.33-py3-none-any.whl
Algorithm Hash digest
SHA256 0c4848150eff3c85a5f50141762dc6cdd5ad03d68dbbde87f8bdf56ffea5cd34
MD5 8f58af5bd339e8807a8cb31a55c9e622
BLAKE2b-256 4236fca4c8a419b2c53d3c9603f74870324e54fae83b12eb53d857d5482c4fd7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page