Professional PyTorch library for 120+ metaheuristic optimization algorithms (Swarm, Evolutionary, Physics, Hybrid).
Project description
SwarmTorch ๐๐ฅ
A PyTorch Library for Metaheuristic Optimization in Deep Learning
๐ About
SwarmTorch is a comprehensive PyTorch library that brings 120 metaheuristic optimization algorithms to the deep learning ecosystem. It provides a unified API for:
- 60 model-training optimizers โ gradient-free weight optimization for neural networks
- 60 hyperparameter searchers โ intelligent hyperparameter optimization (HPO)
Published on arXiv: arXiv:2503.XXXXX
๐ Key Features
- 120 Algorithms Across 6 Families: Swarm Intelligence, Evolutionary, Physics-based, Human-based, Bio-inspired, and Hybrid methods
- Native PyTorch Integration: Drop-in replacement for
torch.optim.Optimizer - GPU-Accelerated: Full tensor parallelism using PyTorch's CUDA support
- Research-Grade Benchmarks: Comprehensive evaluation across 60 training algorithms and 60 HPO searchers with reproducible results
๐ Key Research Findings
Our empirical evaluation on standard benchmarks demonstrates:
- 63.3% of SwarmTorch's hyperparameter searchers outperform Random Search baseline
- Metaheuristics achieve significantly lower loss on multimodal (non-convex) test functions where gradient-based methods fail
- Up to 17.4ร GPU speedup for models with >50K parameters
See our paper for detailed results.
๐ฆ Installation
pip install swarmtorch
With development dependencies:
pip install -e ".[dev]"
๐ป Usage Examples
Model Weight Optimization
import torch.nn as nn
from swarmtorch import PSO
# Define model
model = nn.Sequential(
nn.Linear(10, 64),
nn.ReLU(),
nn.Linear(64, 1)
)
# Use PSO as optimizer
optimizer = PSO(model.parameters(), swarm_size=30)
# Training loop
for epoch in range(100):
def closure():
optimizer.zero_grad()
output = model(inputs)
loss = criterion(output, targets)
loss.backward()
return loss
optimizer.step(closure)
Hyperparameter Optimization
from swarmtorch import PSOSearch
# Define search space
searcher = PSOSearch(
model_fn=build_model,
param_space={
'lr': (0.001, 0.1),
'hidden_dim': [32, 64, 128],
'batch_size': [16, 32, 64]
},
train_fn=train_fn,
iterations=50,
swarm_size=20
)
# Run optimization
best_params = searcher.search()
๐ Repository Structure
swarmtorch/
โโโ swarmtorch/ # Main library
โ โโโ swarm/ # Swarm Intelligence algorithms
โ โโโ evolutionary/ # Evolutionary algorithms
โ โโโ physics/ # Physics-based algorithms
โ โโโ bio_inspired/ # Bio-inspired algorithms
โ โโโ human_based/ # Human-based algorithms
โ โโโ hybrid/ # Hybrid algorithms
โโโ benchmarks/ # Experimental benchmarks
โโโ paper/ # Research paper & figures
โโโ README.md
๐ Benchmark Results
Detailed experimental results are available in:
Top Performing HPO Searchers
| Rank | Algorithm | Best Accuracy |
|---|---|---|
| 1 | SA Search | 98.5% |
| 2 | DVBA Search | 98.5% |
| 3 | PBIL Search | 98.0% |
| 4 | AFSA Search | 98.0% |
| 5 | JSO Search | 98.0% |
Top Performing Training Optimizers
| Rank | Algorithm | Final Loss |
|---|---|---|
| 1 | Adam (baseline) | 0.033 |
| 2 | CA | 0.132 |
| 3 | HHO | 0.167 |
| 4 | CEM | 0.199 |
| 5 | PFA | 0.239 |
๐ง Hardware & Reproducibility
All benchmarks were run on:
- GPU: NVIDIA T4x2 (Kaggle)
- CPU: Intel Core i7-12700K (workstation)
- Software: PyTorch 2.9.0+cu126, Python 3.11, NumPy 1.26
Random seeds fixed at 42 for reproducibility.
๐ Citation
If you use SwarmTorch in your research, please cite:
@article{swarmtorch2026,
author = {Halleluyah Darasimi Oludele},
title = {SwarmTorch: A PyTorch Library for 120 Metaheuristic Optimization Algorithms in Deep Learning},
journal = {arXiv preprint arXiv:2503.XXXXX},
year = {2026}
}
๐ License
MIT License - See LICENSE for details.
๐ค Acknowledgments
Inspired by pyMetaheuristic and the broader metaheuristic optimization community.
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.3.0.tar.gz.
File metadata
- Download URL: swarmtorch-0.3.0.tar.gz
- Upload date:
- Size: 84.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ab9113a98319d708de70a38207157879ef438848a1f301f4dbf889d9264e0e6
|
|
| MD5 |
1e85d2cf5dde7cd85a6d4f0ca71e07c1
|
|
| BLAKE2b-256 |
e4dce646665f1201fbfd88d1e7f54585cb6509875ae370a031149e77e64f9a8c
|
File details
Details for the file swarmtorch-0.3.0-py3-none-any.whl.
File metadata
- Download URL: swarmtorch-0.3.0-py3-none-any.whl
- Upload date:
- Size: 103.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
474a0cb30b91785c954dd062a49d4ff800029db44118b503a5e1bb1c18fa1e7d
|
|
| MD5 |
2900923e58ead814a8d4a5136103fb66
|
|
| BLAKE2b-256 |
36b5b5ba90024fa3bab230c45f6df05e2cc281a878495a02964da1d542216535
|