1

I have just started using pysyft to implement federated-learning. While following one of the tutorials, I got stuck on an error:

enter image description here

Code which I have used:

import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms
import logging
import syft as sy

westside = sy.VirtualMachine(name = "westside")
grapevine = sy.VirtualMachine(name = "grapevine")

# Introducing hyperparameters to control the learning process
args = {
    'use_cuda': True,
    'batch_size': 64,
    'test_batch_size': 1000,
    'lr': 0.01,
    'log_interval': 100,
    'epochs': 10
}

# Check to use GPU or not
use_cuda = args['use_cuda'] and torch.cuda.is_available()
device = torch.device('cuda' if use_cuda else 'cpu')

# Create a simple CNN net
class Net(nn.Module):
    
    def __init__(self):
        super(Net, self).__init__()
        
        self.conv = nn.Sequential(
            nn.Conv2d(in_channels = 1, out_channels = 32, kernel_size = 3, stride = 1),
            nn.ReLU(),
            nn.Conv2d(in_channels=32,out_channels = 64, kernel_size = 3, stride = 1),
            nn.ReLU()
        )
        
        self.fc = nn.Sequential(
            nn.Linear(in_features=64*12*12, out_features=128),
            nn.ReLU(),
            nn.Linear(in_features=128, out_features=10),
        )
    
    def forward(self, x):
        x = self.conv(x)
        x = F.max_pool2d(x,2)
        x = x.view(-1, 64*12*12)
        x = self.fc(x)
        x = F.log_softmax(x, dim=1)
        return x

# Load the data and transform it into a federated dataset
federated_train_loader = sy.FederatedDataLoader(
    datasets.MNIST('../data', train=True, download=True,
                   transform=transforms.Compose([
                       transforms.ToTensor(),
                       transforms.Normalize((0.1307,), (0.3081,))
                   ]))
    .federate((grapevine, westside)),
    batch_size=args['batch_size'], shuffle=True)

The tutorial which I am following uses an old version of pysyft so the support for hooks has been deprecated. Also, I had to use syft.VirtualMachine(name="Some-name") instead of syft.VirtualWorker(hook, id="Some-name"). The purpose of sy.FederatedDataLoader as given in the tutorial is to load data and hence, transform it to federated dataset. This is the link for the tutorial. Is there any equivalent function instead of FederatedDataLoader() to load data in the new version?

onapte
  • 217
  • 2
  • 8

1 Answers1

0

try to install PySyft version : 0.2.9

seni
  • 659
  • 1
  • 8
  • 20