Stream Processing Architecture for Resource Subtle Environments
Project description
Sparse
This repository contains source code for Stream Processing Architecture for Resource Subtle Environments (or just Sparse for short). Additionally, sample applications utilizing Sparse for deep learning can be found in examples directory.
Quick start with deep learning
Follow these instructions to start creating your own sparse applications for distributed deep learning with PyTorch.
First, install sparse framework from PyPi:
pip install sparse-framework
Create a sparse worker node which trains a neural network using data sent by master:
"""model_trainer.py
"""
import torch
from torch import nn
from sparse_framework.node.worker import Worker
from sparse_framework.dl.gradient_calculator import GradientCalculator
# PyTorch model
class NeuralNetwork(nn.Module):
def __init__(self):
super().__init__()
self.flatten = nn.Flatten()
self.linear_relu_stack = nn.Sequential(
nn.Linear(28*28, 512),
nn.ReLU(),
nn.Linear(512, 512),
nn.ReLU(),
nn.Linear(512, 10)
)
def forward(self, x):
x = self.flatten(x)
logits = self.linear_relu_stack(x)
return logits
# Sparse node
class ModelTrainer(Worker):
def __init__(self):
model = NeuralNetwork()
loss_fn = nn.CrossEntropyLoss()
optimizer = torch.optim.SGD(model.parameters(), lr=1e-3)
Worker.__init__(self,
task_executor = GradientCalculator(model=model,
loss_fn=loss_fn,
optimizer=optimizer))
if __name__ == '__main__':
ModelTrainer().start()
Then create the corresponding sparse master node:
"""data_source.py
"""
from torch.utils.data import DataLoader
from torchvision import datasets
from torchvision.transforms import ToTensor
import asyncio
from sparse_framework.dl.serialization import encode_offload_request, decode_offload_response
from sparse_framework.node.master import Master
# Sparse node
class TrainingDataSource(Master):
async def train(self, batch_size = 64, epochs = 1):
# torchvision dataset
training_data = datasets.FashionMNIST(
root="data",
train=True,
download=True,
transform=ToTensor(),
)
for t in range(epochs):
for batch, (X, y) in enumerate(DataLoader(training_data, batch_size)):
input_data = encode_offload_request(X, y)
result_data = await self.task_deployer.deploy_task(input_data)
split_grad, loss = decode_offload_response(result_data)
print('Loss: {}'.format(loss))
if __name__ == '__main__':
asyncio.run(TrainingDataSource().train())
To run training, start the worker and the master processes (in separate terminal sessions):
python model_trainer.py
python data_source.py
Example Applications
The repository includes example applications (in the examples directory). The applications are tested tested with the following devices and the following software:
| Device | JetPack version | Python version | PyTorch version | Docker version | Base image | Docker tag suffix |
|---|---|---|---|---|---|---|
| Jetson AGX Xavier | 5.0 preview | 3.8.10 | 1.12.0a0 | 20.10.12 | nvcr.io/nvidia/l4t-pytorch:r34.1.0-pth1.12-py3 | jp50 |
| Lenovo ThinkPad | - | 3.8.12 | 1.11.0 | 20.10.15 | pytorch/pytorch:1.11.0-cuda11.3-cudnn8-runtime | amd64 |
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 sparse-framework-1.1.0.tar.gz.
File metadata
- Download URL: sparse-framework-1.1.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c5e3f25adc16164a40d14293caed4cf70ce23c7f9112680a0a57792cff78787
|
|
| MD5 |
af5be76e52d2fd67e51d0797b178bcfb
|
|
| BLAKE2b-256 |
bae3222b0f059b0bc517ff702ccedc09485c7929f15b1fa422ddfbbed2008b96
|
File details
Details for the file sparse_framework-1.1.0-py3-none-any.whl.
File metadata
- Download URL: sparse_framework-1.1.0-py3-none-any.whl
- Upload date:
- Size: 25.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75f30c6e3c15e10ae9168f143f3af93b6cbae155a3534e74fe148c9224648e6c
|
|
| MD5 |
1c791d8770182dec1174797fff206f2a
|
|
| BLAKE2b-256 |
c432312a5784018a2eaddd1693978b9614eab3ba17b1b8697c6a546c0c70494c
|