Professional PyTorch library for 120+ metaheuristic optimization algorithms (Swarm, Evolutionary, Physics, Hybrid).
Project description
SwarmTorch 🐝🔥
The ultimate metaheuristic library for PyTorch
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.
Installation • Key Features • Benchmarks • Usage • Citation
🚀 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.
📈 Research & Benchmarking Results
We conducted a massive-scale rigorous evaluation of 118 algorithms to benchmark their performance across various deep learning tasks.
1. Model Training (Weight Optimization)
SwarmTorch enables the training of neural networks without gradients. Several metaheuristics exhibit convergence stability comparable to standard gradient-based methods.
Figure 1: Convergence history comparing Swarm Optimizers (PSO, HHO, etc.) against Adam and SGD.
Figure 2: The Top 25 most effective weight optimizers ranked by final loss.
2. High-Density Distribution Analysis
We analyzed the reliability of each category. Swarm and Hybrid categories demonstrated the highest stability and lowest variance across multiple trials.
Figure 3: Statistical distribution of final loss across categories. Lower loss indicates superior optimization.
3. Hyperparameter Optimization (HPO) Benchmarks
Our metaheuristic searchers are designed to replace Random Search with more intelligent exploration strategies. 94.9% of our algorithms outperformed Random Search.
Figure 4: Success rate of metaheuristic searchers vs. the Random Search baseline.
4. The "Generalist" Frontier
We identified "Generalist" algorithms that excel at both weight optimization and hyperparameter tuning.
Figure 5: Scatter plot mapping Training Efficiency vs. HPO Accuracy. Elite generalists occupy the top-right quadrant.
📦 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
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.1.3.tar.gz.
File metadata
- Download URL: swarmtorch-0.1.3.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b58b1e89425b285a11e4d0d55cdd9691c92748e466b15e8ef646dfbb360b17aa
|
|
| MD5 |
40504d859b0f231dbeb73371fa71f1a6
|
|
| BLAKE2b-256 |
be38984eb0e2804eb0260d620169c40559c04ea0ea2e8350b0acd59f2716a15a
|
File details
Details for the file swarmtorch-0.1.3-py3-none-any.whl.
File metadata
- Download URL: swarmtorch-0.1.3-py3-none-any.whl
- Upload date:
- Size: 3.6 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 |
9e4ae49d004ed434577b5fde1be0a155ece83fb0d1bda09222571f09fbac9c92
|
|
| MD5 |
0449e02080aedbc7eb78b5fa49865685
|
|
| BLAKE2b-256 |
2aabe51770dd554d9d271aea4af6ac19ef2ad402a645cc2796ef03607867b5d0
|