smolcluster
Distributed Deep Learning Library for Heterogeneous Hardware
Train and serve neural networks across Mac minis, Raspberry Pis, MacBooks, and Windows machines using only PyTorch and Python's socket library, without NCCL or MPI.
smolcluster is an educational project for learning how distributed training and inference work from the ground up. The codebase prioritizes readability over speed and is under active development.
Overview
smolcluster implements distributed training and inference across mixed consumer hardware using PyTorch and raw Python sockets. It is built for learning rather than production throughput, with code kept small and readable while the project is under active development.
It includes Fully Sharded Data Parallelism (FSDP), Classic Data Parallelism (ClassicDP), Elastic Distributed Parallelism (EDP), Model Parallelism, Pipeline Model Parallelism, and Expert Parallelism, running across Mac minis, Raspberry Pis, MacBooks, and Windows machines.
Training Algorithms
| Algorithm | Best for |
|---|---|
| FSDP (ZeRO Stage 0/1) | Memory-constrained nodes; ZeRO Stage 1 cuts memory to ~1/N per worker via optimizer state partitioning |
| ClassicDP (All-Reduce) | Balanced clusters; ring all-reduce gradient averaging with configurable bounded staleness |
| EDP (Elastic DP) | Heterogeneous clusters; async training with stale gradient tolerance that handles stragglers |
| SyncPS (Parameter Server) | Homogeneous clusters; barrier-based synchronization with strict consistency |
| Expert Parallelism | MoE models; distributed expert assignment across nodes |
| Model Parallelism | Large model inference; layer-wise distribution with streaming token generation |
All algorithms support configurable bounded staleness (K=0 for strict sync, K>0 for async up to K steps).
Cluster Architecture
Quick Start
Step-by-step setup guide for Mac Mini (Thunderbolt) and Jetson / home router clusters, with commands ready to copy.
git clone https://github.com/YuvrajSingh-mist/smolcluster.git
cd smolcluster
uv sync
# launch training
bash scripts/launch_edp_train_gpt.sh
# launch inference
bash scripts/inference/launch_mp_inference.sh
bash scripts/inference/launch_api.sh
Key Features
Distributed Training Algorithms
- Fully Sharded Data Parallelism (FSDP): ZeRO-style data parallelism with Stage 0 (All-Reduce) and Stage 1 (optimizer state partitioning for ~1/N memory per worker), plus bounded staleness for async training.
- Classic Data Parallelism (ClassicDP): All-Reduce data parallelism where workers exchange gradients directly in a fully connected topology, with configurable bounded staleness.
- Elastic Distributed Parallelism (EDP): asynchronous data parallelism with stale gradient tolerance, built for mixed-speed clusters.
- Model Parallelism (MP): layer-wise model distribution for large models and inference serving.
- Model Parallelism with Pipeline (MPPipeline): pipeline model parallelism that overlaps inter-layer transfers with computation during inference.
- Expert Parallelism (EP): sparse mixture-of-experts (MoE) training with expert routing distributed across nodes.
Distributed Inference
grove start <script> -n N on the coordinator
and grove join on each worker.
- Supported Inference Algorithms: Pipeline Parallelism and Data Parallelism (DP).
- Streaming Token Generation: token-by-token generation with activations forwarded sequentially across distributed layers.
- FastAPI Backend: REST API server for connecting web and mobile clients (iPad, browsers, and more).
- Multi-Device Support: serve models across Mac minis and Raspberry Pis with automatic activation routing.
- Interactive Chat Interface: React web UI and iOS Swift app for chatting with distributed models.
Hardware Support
Train and run inference across Mac minis, Raspberry Pis, MacBooks, Windows machines, and iPad clients.
Model Support
Data Parallelism (DP) works with models from Hugging Face Transformers. Model Parallelism (MP) currently supports GPT-2 (117M), with more models planned.
Monitoring & Logging
- Weights & Biases Integration: logs training metrics, gradient norms, and hardware utilization automatically.
- Web Interface: React chat UI for GPT inference with streaming responses.
Demo
- Model: GPT-2 (117M parameters)
- Hardware: iPad client + 2× Mac Mini M4 (2025)
- Algorithm: Model Parallelism with layer distribution
- Demo: Real-time streaming token generation across distributed layers
- Workflow: User prompts from iPad → activations forwarded between Mac Minis → tokens streamed back
- Model: Llama3.2-1B-Instruct
- Hardware: 3× Mac Minis M4 2025 16GB RAM over LAN
- Algorithm: ClassicDP with all-to-all gradient exchange
- Model: Llama3.2-1B-Instruct
- Hardware: 3× Mac Minis M4 2025 + dedicated parameter server node
- Algorithm: SyncPS with barrier-based synchronization
- Package by Swarnim Jain, integrated into smolcluster
- Auto node discovery over mDNS (Mac) / TCP + Zeroconf (Linux)
- Live per-rank TUI: loss, grad norm, tokens/sec, network I/O
Technical Details
Each algorithm in smolcluster is written to show how a specific cluster layout, network topology, and communication pattern works in practice, prioritizing clarity over raw throughput.
Communication Infrastructure
- Socket-based Communication: raw TCP sockets handle gradient and activation transfers directly between nodes, with no MPI or specialized networking libraries.
- Pickle Serialization: PyTorch tensors are serialized with pickle for network transmission, with optional gradient quantization to reduce bandwidth.
- Asynchronous I/O: non-blocking sockets let workers keep computing while waiting on network transfers in EDP mode.
Distributed Training Modes
- Elastic Distributed Parallelism (EDP): workers train independently with stale gradient tolerance. The parameter server accepts gradients from any model version, so stragglers and variable network latency do not stall the cluster. Workers pull updated weights periodically without synchronization barriers.
- Model Parallelism: sequential layer distribution across nodes with activation forwarding, letting you train and serve models that exceed single-device memory. Each worker holds a slice of layers and forwards activations to the next rank.
- Pipeline Model Parallelism: temporal pipeline parallelism with multiple microbatches in flight across stages, reducing idle bubbles and raising device utilization on larger models.
- Expert Parallelism: distributed mixture-of-experts training with experts placed across nodes and routed across mixed hardware.
Data Management
- Automatic Data Partitioning: shards the dataset across workers by global rank and world size with no overlap.
- Deterministic Shuffling: seeded random number generators keep data ordering reproducible across runs.
- Streaming Support: streams large datasets through PyTorch DataLoader.
Fault Tolerance & Monitoring
- Checkpointing: saves periodic model snapshots at configurable intervals so training can resume after a failure.
- Weights & Biases Integration: logs training metrics, gradient norms, per-layer statistics, and system metrics (GPU utilization, memory usage, and network throughput).
- Timeout Handling: configurable timeouts prevent deadlocks when workers drop or network partitions happen.
Performance Optimizations
- Gradient Quantization: optional 8-bit quantization cuts gradient transfer size by 4× with minimal accuracy impact.
- CPU-based Computation: runs on CPU cores in commodity machines (Mac minis, Raspberry Pis) when GPUs are not available.
- Mixed Precision Training: FP16 automatic mixed precision support for compatible hardware.
- Gradient Accumulation: simulates larger batch sizes by accumulating gradients across multiple microbatches before stepping.
Documentation
Guides for setting up and running smolcluster:
- Cluster Setup Hardware configuration, network topology, and SSH setup
- Network Configuration Thunderbolt bridges, Ethernet, and mDNS discovery
- Training Guide Algorithm comparison, launch scripts, and hyperparameters
- Configuration YAML config reference for cluster and model settings
- Inference Guide Model parallelism, FastAPI server, and streaming SSE
- Logging Setup Grafana + Loki distributed log aggregation
License
smolcluster is released under the Apache License 2.0 for code, and the CC BY 4.0 for documentation, diagrams and published experiment artifacts.
Contributions are welcome! Visit the GitHub repository to get involved.