Skip to content

bluebbberry/MLTorrent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MLTorrent ๐ŸŒ๐Ÿง 

Distributed Machine Learning via P2P Networks

MLTorrent is a proof-of-concept implementation that demonstrates how BitTorrent-inspired peer-to-peer protocols can be used for distributed machine learning. This MVP showcases federated learning with gossip protocols, where multiple peers collaboratively train a global model while keeping their data private.

MLTorrent Demo React Machine Learning

๐Ÿš€ Features

  • Real Federated Learning: Actual machine learning training across distributed peers
  • P2P Network Simulation: 5 peers with different data shards and network behaviors
  • Gossip Protocol: BitTorrent-inspired model sharing and synchronization
  • Privacy-Preserving: No raw data sharing between peers
  • Real-time Visualization: Live network activity and training progress
  • Interactive Demo: Perfect for presentations and technical demos

๐ŸŽฏ Technical Implementation

Core Components

  • Federated Averaging: Combines peer models using contribution-weighted averaging
  • Gossip Protocol: Peers randomly share model updates with each other
  • Linear Classifier: Simple but effective model for 2D classification
  • Data Sharding: Training data distributed across peers
  • Trust System: Peer reputation and contribution scoring

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Peer 1        โ”‚    โ”‚   Peer 2        โ”‚    โ”‚   Peer 3        โ”‚
โ”‚   SmartHome     โ”‚โ—„โ”€โ”€โ–บโ”‚   IoT Device    โ”‚โ—„โ”€โ”€โ–บโ”‚   Edge Device   โ”‚
โ”‚   Local Model   โ”‚    โ”‚   Local Model   โ”‚    โ”‚   Local Model   โ”‚
โ”‚   Data Shard    โ”‚    โ”‚   Data Shard    โ”‚    โ”‚   Data Shard    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚                       โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚  Global Model   โ”‚
                    โ”‚  (Federated     โ”‚
                    โ”‚   Averaging)    โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“‹ Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • Modern web browser (Chrome, Firefox, Safari, Edge)

๐Ÿ› ๏ธ Installation

1. Clone the repository

git clone https://github.com/yourusername/mltorrent.git
cd mltorrent

2. Install dependencies

npm install

3. Start the development server

npm start

4. Open your browser

Navigate to http://localhost:3000 to see MLTorrent in action!

๐Ÿ“ Project Structure

mltorrent/
โ”œโ”€โ”€ public/
โ”‚   โ”œโ”€โ”€ index.html
โ”‚   โ””โ”€โ”€ favicon.ico
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ””โ”€โ”€ MLTorrent.jsx     # Main component
โ”‚   โ”œโ”€โ”€ App.js
โ”‚   โ”œโ”€โ”€ App.css
โ”‚   โ””โ”€โ”€ index.js
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ .gitignore

๐ŸŽฎ How to Use

Basic Demo Flow

  1. Start Training: Click the "Start Training" button to begin distributed learning
  2. Watch Network Activity: Observe real-time model sharing between peers
  3. Monitor Accuracy: See the global model accuracy improve over time
  4. Peer Behavior: Notice peers going online/offline and their contribution scores
  5. Reset: Use the "Reset" button to start a new training session

Key Metrics to Watch

  • Global Model Accuracy: Shows overall performance of the federated model
  • Epoch Count: Number of training rounds completed
  • Active Peers: Currently participating nodes in the network
  • Data Shared: Total model updates exchanged between peers
  • Network Activity: Real-time model fragment transfers

๐Ÿ”ฌ Technical Details

Machine Learning Algorithm

The system uses a Linear Classifier with Sigmoid Activation for binary classification:

prediction = sigmoid(wโ‚xโ‚ + wโ‚‚xโ‚‚ + bias)

Federated Learning Process

  1. Data Sharding: 1000 samples distributed across 5 peers
  2. Local Training: Each peer trains on its private data shard
  3. Model Aggregation: Global model created via weighted averaging
  4. Gossip Distribution: Peers randomly share model updates
  5. Convergence: Global accuracy improves through collaboration

Dataset

  • Type: 2D Binary Classification
  • Size: 1000 samples total
  • Distribution: 200 samples per peer
  • Features: (xโ‚, xโ‚‚) coordinates
  • Labels: Binary classification based on xโ‚ + xโ‚‚ > 0

๐Ÿšง Development

Available Scripts

# Start development server
npm start

# Build for production
npm run build

# Run tests
npm test

# Eject (not recommended)
npm run eject

Adding New Features

The codebase is modular and easy to extend:

  • New ML Algorithms: Modify the SimpleLinearClassifier class
  • Different Datasets: Update the generateTrainingData function
  • More Peers: Adjust the peer initialization logic
  • Network Protocols: Enhance the gossip protocol implementation

๐ŸŒŸ Future Enhancements

  • Real P2P Networking: Implement actual WebRTC connections
  • Advanced ML Models: Support for neural networks and deep learning
  • Blockchain Integration: Add cryptocurrency incentives for participation
  • Real IoT Integration: Connect to actual smart home devices
  • Advanced Privacy: Implement differential privacy and homomorphic encryption
  • Mobile App: React Native version for mobile devices

๐Ÿค Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Inspired by BitTorrent's decentralized architecture
  • Built on React and modern web technologies
  • Federated learning concepts from research papers
  • P2P networking principles from distributed systems

Made with โค๏ธ for the future of decentralized AI

About

BitTorrent for machine learning. Implementation of https://dl.acm.org/doi/full/10.1145/3703790.3703813 for general machine learning (not just IoT setting)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors