Skip to main content

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

Project description

SwarmTorch ๐Ÿ๐Ÿ”ฅ

A PyTorch Library for Metaheuristic Optimization in Deep Learning

arXiv License: MIT Python 3.10+ PyTorch


๐Ÿ“„ 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


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.3.0.tar.gz (84.2 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.3.0-py3-none-any.whl (103.1 kB view details)

Uploaded Python 3

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

Hashes for swarmtorch-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3ab9113a98319d708de70a38207157879ef438848a1f301f4dbf889d9264e0e6
MD5 1e85d2cf5dde7cd85a6d4f0ca71e07c1
BLAKE2b-256 e4dce646665f1201fbfd88d1e7f54585cb6509875ae370a031149e77e64f9a8c

See more details on using hashes here.

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

Hashes for swarmtorch-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 474a0cb30b91785c954dd062a49d4ff800029db44118b503a5e1bb1c18fa1e7d
MD5 2900923e58ead814a8d4a5136103fb66
BLAKE2b-256 36b5b5ba90024fa3bab230c45f6df05e2cc281a878495a02964da1d542216535

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