A streamlined framework for distribution of GPU-accelerated PyTorch workloads via Docker Swarm
918
A streamlined framework for setting up a multi-node, GPU-accelerated, distributed system for PyTorch workloads using Docker Swarm. With ShadowSWARM, you can quickly configure and deploy a scalable environment for machine learning inference or training across multiple machines.


config.py).Docker and NVIDIA Drivers:
sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
docker run --rm --gpus all nvidia/cuda:12.1.1-base-ubuntu20.04 nvidia-smi
Python 3.8+:
sudo apt-get install python3 python3-pip
Passwordless SSH:
ssh-keygen -t rsa -b 2048
ssh-copy-id user@worker-ip
Clone the Repository (Only on Master):
git clone https://github.com/DJStompZone/shadowswarm.git
cd shadowswarm
Build the Docker Image: Build the Docker image on the master node:
docker build -t shadowswarm-app .
Run the Configuration Script: Use the interactive CLI to gather and validate the necessary configuration:
python3 config.py
This script will:
.env file.bootstrap.sh script to initialize Docker Swarm and add workers.Verify Swarm Setup: Check the Swarm status after the bootstrap:
docker node ls
Deploy the Docker Stack: Once the Swarm is ready, deploy the application:
docker stack deploy --compose-file docker-compose.yml shadowswarm
Open a browser and navigate to the master node IP:
http://<master-node-ip>:8501
Use the Streamlit interface to interact with your distributed PyTorch system.
shadowswarm/
├── config.py # CLI script for gathering configuration
├── bootstrap.sh # Script for initializing Docker Swarm and adding workers
├── docker-compose.yml # Docker Swarm stack configuration
├── Dockerfile # Docker image definition
├── .env # Environment variables for the deployment
├── app/ # Application directory
│ ├── main.py # PyTorch and Streamlit code
│ └── utils.py # Utility functions
Configuration:
config.py prompts for master and worker node details, saves them to .env, and triggers bootstrap.sh.Swarm Initialization:
bootstrap.sh initializes Docker Swarm on the master node and connects workers via SSH.Stack Deployment:
docker-compose.yml orchestrates the master and worker containers, assigning roles using environment variables.Distributed Workload:
| Variable | Description |
|---|---|
MASTER_HOSTNAME | Hostname of the master node. |
MASTER_IP | IP address of the master node. |
WORKER_HOSTNAMES | Comma-separated list of worker hostnames. |
NODE_RANK | Rank of the node in the distributed setup. |
WORLD_SIZE | Total number of nodes in the cluster. |
MASTER_PORT | Port for master-worker communication. |
Docker Swarm Issues:
docker info
docker node ls
SSH Issues:
ssh <worker-ip>
Container Logs:
docker service logs shadowswarm_master
docker service logs shadowswarm_worker1
GPU Issues:
docker run --rm --gpus all nvidia/cuda:12.1.1-base-ubuntu20.04 nvidia-smi
Add a new worker node to the swarm:
docker swarm join --token <worker-join-token> <master-ip>:2377
Update the WORKER_HOSTNAMES in the .env file to include the new worker.
Re-deploy the stack:
docker stack deploy --compose-file docker-compose.yml shadowswarm
Contributions are welcome! Please open an issue or submit a pull request if you have problems, suggestions, or improvements.
This project is licensed under the MIT License.
Content type
Image
Digest
sha256:e8098d2bf…
Size
4.4 GB
Last updated
over 1 year ago
docker pull djstomp/shadowswarm-app