Professional PyTorch library for 120+ metaheuristic optimization algorithms (Swarm, Evolutionary, Physics, Hybrid).
Project description
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.
- 60 model-training optimizers for gradient-free weight optimization
- 60 hyperparameter-tuning searchers for intelligent HPO
Installation • Key Features • Benchmarks & Research • Usage • Citation
🚀 Key Features
- 120 Algorithms (60 + 60): 60 model-training optimizers + 60 HPO searchers across 6 categories: 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 120 algorithms (60 training + 60 HPO). Our research shows that 65.5% of SwarmTorch searchers outperform the standard Random Search baseline in HPO tasks, with top performers achieving near-perfect validation accuracy.
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
With benchmark dependencies:
pip install swarmtorch[benchmarks]
💻 Usage
Model Weight Optimization
import torch.nn as nn
from swarmtorch 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 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()
Why SwarmTorch?
Traditional deep learning relies on gradient-based optimization (Adam, SGD, etc.). SwarmTorch complements these with:
| Scenario | Use Gradient (Adam/SGD) | Use SwarmTorch |
|---|---|---|
| Standard classification | ✅ Best choice | Overkill |
| Non-differentiable loss | ❌ Can't use | ✅ Perfect fit |
| Discrete optimization | ❌ Can't use | ✅ Perfect fit |
| Multi-modal landscapes | Gets stuck | Explores well |
| Hyperparameter tuning | Manual search | Automated |
🤝 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swarmtorch-0.2.1.tar.gz.
File metadata
- Download URL: swarmtorch-0.2.1.tar.gz
- Upload date:
- Size: 29.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5ef77bfdf570899a9a718e16f644f47f63ee756023850e1cb89392de8644d59
|
|
| MD5 |
3b66d7dccd6e50e3ea67086f5615d7fb
|
|
| BLAKE2b-256 |
826b42e185143a90262e32cbdac762a35009a8c291ae54dcf171f4e8d14d4e98
|
File details
Details for the file swarmtorch-0.2.1-py3-none-any.whl.
File metadata
- Download URL: swarmtorch-0.2.1-py3-none-any.whl
- Upload date:
- Size: 47.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2d2ce04ff5afd21f51430b92207b0d90f08855cdeafeddbe27a39ade254a271
|
|
| MD5 |
1a472d4e8ee5b8b85d25801aa97404e9
|
|
| BLAKE2b-256 |
6c776c9c893adcf71f3c94b2762daba63cb6492a2d4791674e717fc155a07a3c
|