Skip to main content

TorchNEAT

TorchNEAT is a PyTorch-based neuroevolution library. It evolves the parameters of NeatModule models through initialization, mutation, speciation and reproduction, on the CPU (numba) or on an NVIDIA GPU (numba.cuda / cupy). RL trainers (NEAT, PPO) are included; environment design and fitness evaluation remain the caller's job.

TorchNEAT grew out of an earlier private project of the same author. This repository is a clean restructure; the old history is not carried over.

Install

Python 3.11 or newer. Install PyTorch first, from the wheel index that matches what you want, then TorchNEAT:

# CPU only (any OS; on Linux this avoids the multi-GB CUDA wheels)
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install torchneat

# NVIDIA GPU: use your driver's CUDA version from `nvidia-smi` (cu132 = CUDA 13.2), required on Windows
pip install torch --index-url https://download.pytorch.org/whl/cu132
pip install "torchneat[gpu]"

pip install "torchneat[logging]"      # + runlytics logging for the RL trainers

pip install torchneat alone takes whatever PyTorch PyPI serves: the CUDA build on Linux, the CPU build on Windows and macOS. [gpu] adds the numba/cupy/CUDA libraries pinned to the CUDA version of your NVIDIA driver, but never changes your PyTorch build. torchneat-install detects the system and sets up PyTorch and the CUDA libraries for you (--cpu to force CPU). See Installation and Troubleshooting.

Quick start

import torch
import torchneat as neat
from torchneat import nn


class Policy(neat.nn.Model):
    def __init__(self, inputs=4, hidden=16, outputs=2):
        super().__init__()
        self.net = nn.Sequential(
            nn.Linear(inputs, hidden), nn.Tanh(),     # NEAT-evolvable layer + wrapped PyTorch activation
            nn.Linear(hidden, outputs),
        )

    def forward(self, state, keys=None):
        return self.net(state, keys=keys)


config = neat.Config(file_name="demo", directory="demo")
population = neat.Population(100, Policy(), config)

Everything you normally take from torch.nn (activations, dropout, flatten, containers, ...) is re-exported from torchneat.nn. Parameters that evolve use NeatParameter / NeatModule; everything else is plain PyTorch.

Package layout

Package Contents
torchneat.core Genome, Specie/Species, Stagnation, Reproduction, Population
torchneat.backends device-independent init/reproduce/speciate orchestration, cpu/ and gpu/ kernels, seeding
torchneat.nn NeatParameter, NeatModule, Model; layers, attention/transformer blocks, activations, PyTorch re-exports; legacy/
torchneat.rl NEAT and PPO trainers, rollout buffers, logger
torchneat.config Config and its sections
torchneat.optim hyper-parameter schedulers
torchneat.reporting reporters and loggers
torchneat.utils storage, console colours, timing, helpers

Devices

CPU is the default. Choose the NEAT backend with torchneat.set_device("cuda") or the TORCHNEAT_DEVICE environment variable; torchneat.cuda_is_available() tells whether the GPU backend is usable. set_device does not move your model: create the NeatParameters / NeatModules on the same device (device="cuda") so the backend can use the weights in place. The numba CUDA occupancy warnings are hidden; set TORCHNEAT_PERF_WARNINGS=1 or use with torchneat.perf_warnings(): to show them.

Saving and loading

population.save(filename="experiment", directory="neat_save")
population.load(filename="experiment", directory="neat_save")
state = population.state_dict()

Checkpoints use pickle; only load files you trust.

Documentation

Development

pip install -e ".[dev]"
pytest -m "not gpu"     # CPU tests
pytest -m gpu           # GPU tests (skipped when no CUDA device is usable)

See CONTRIBUTING.md, CHANGELOG.md and TODO.md.

Metadata

Release files for torchneat 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torchneat 0.2.2
File Size Uploaded Provenance Actions
torchneat-0.2.2.tar.gz 188.6 kB With provenance Details for torchneat-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for torchneat 0.2.2
File Interpreter ABI Platform Actions
torchneat-0.2.2-py3-none-any.whl Python 3 none any Details for torchneat-0.2.2-py3-none-any.whl

Total release size: 412.8 kB

Release files / torchneat-0.2.2.tar.gz

Download URL torchneat-0.2.2.tar.gz
Size 188.6 kB
Tags Source
SHA-256 checksum
How to use checksums
39124ab9fdf1a9473f4e08d587acee4e2eb7c3eceb3f4c60c213f6c538bfb854
BLAKE2b-256 checksum
How to use checksums
3e782cae32848f15c5ce9cfcc08359d899090804759840265c3cd78a4bf0ed7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / torchneat-0.2.2-py3-none-any.whl

Download URL torchneat-0.2.2-py3-none-any.whl
Size 224.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ebd16d7e0483525e5647d150f1e8db7ad62351b588dcdd6e3e6e0ec81cc2fd3
BLAKE2b-256 checksum
How to use checksums
7b50ad4735ea1e2768d1c5856dae923d4ad4f0dbfa686d34b0c4fff92a54e192
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for torchneat 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for torchneat-0.2.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page