Skip to main content

Professional PyTorch library for 120+ metaheuristic optimization algorithms (Swarm, Evolutionary, Physics, Hybrid).

Project description

SwarmTorch 🐝🔥

The ultimate metaheuristic library for PyTorch

CI PyPI version Downloads License: MIT Python 3.10+


SwarmTorch is a high-performance, academic-grade library that brings 120+ metaheuristic algorithms to the PyTorch ecosystem. It enables gradient-free neural network training and state-of-the-art hyperparameter optimization (HPO) with a single, unified API.

InstallationKey FeaturesBenchmarks & ResearchUsageCitation


🚀 Key Features

  • 120+ Algorithms: Categorized into Swarm Intelligence, Evolutionary, Physics-based, Human-based, Bio-inspired, and Hybrids.
  • Gradient-Free Training: Optimize weights for non-differentiable or complex loss landscapes directly as a PyTorch Optimizer.
  • Deep HPO Integration: Replace Random/Grid search with intelligent, nature-inspired exploration.
  • Research Ready: Includes full benchmarking suites, raw experimental data, and publication-quality visualizations.
  • Highly Optimized: Leverages PyTorch's tensor operations for swarm-level parallelism.

📈 Benchmarks & Research

We conducted a massive-scale evaluation of 118 algorithms. Our research shows that 94.9% of SwarmTorch searchers outperform the standard Random Search baseline in HPO tasks.

Detailed performance analysis, convergence plots, and category reliability studies are available in the dedicated benchmarks document:

👉 View Full Research & Benchmarks Report (with Visualizations)


📦 Installation

Using pip:

pip install swarmtorch

Using uv (Recommended):

uv add swarmtorch

💻 Usage

Model Weight Optimization

import torch.nn as nn
from swarmtorch.swarm.model_training import PSO

model = nn.Sequential(nn.Linear(10, 64), nn.ReLU(), nn.Linear(64, 1))
optimizer = PSO(model.parameters(), swarm_size=30)

def closure():
    optimizer.zero_grad()
    loss = criterion(model(inputs), targets)
    return loss

optimizer.step(closure)

Hyperparameter Tuning

from swarmtorch.swarm.hyperparameter_tuning import PSOSearch

searcher = PSOSearch(
    model_fn=build_model,
    param_space={'lr': (0.001, 0.1), 'hidden_dim': [32, 64]},
    train_fn=train_fn,
    iterations=50
)
best_params = searcher.search()

🤝 Acknowledgments & References

This library was developed with reference to the pyMetaheuristic library. We are grateful for their contributions to the metaheuristic optimization community.

📝 Citation

@software{swarmtorch2026,
  author = {Halleluyah Darasimi Oludele},
  title = {SwarmTorch: A PyTorch Library for 120+ Metaheuristic Optimization Algorithms},
  year = {2026},
  url = {https://github.com/hallelx2/swarmtorch}
}

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

swarmtorch-0.1.6.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

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

swarmtorch-0.1.6-py3-none-any.whl (50.1 kB view details)

Uploaded Python 3

File details

Details for the file swarmtorch-0.1.6.tar.gz.

File metadata

  • Download URL: swarmtorch-0.1.6.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for swarmtorch-0.1.6.tar.gz
Algorithm Hash digest
SHA256 0127585dc093fffa8a4fa099921bddeccda49ad93cedc84e31d2fa24a0338daf
MD5 cfeecb3c44eb0916c0573a1a1ed983f7
BLAKE2b-256 df1d06ffa970a6354ff8225dbd023c51976a50ae2feb87c4b69bbeded1d577d4

See more details on using hashes here.

File details

Details for the file swarmtorch-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: swarmtorch-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 50.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for swarmtorch-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 82c16b94cc54c5a1f05af9443ab3388167fa58adedc32de163e20f0e2c729147
MD5 004cd4bd3d023ea39a8c4a89c279caf1
BLAKE2b-256 e940d9af6d355ef5b7d3428e3bbe01bff86c49403728343fc8d770edf99d5e4e

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