Open dr4g0n7ly opened 1 year ago
Hi @dr4g0n7ly , are you still seeing this error? if so, could you tell us what platform do you use (windows, linux, mac)
Hi @dr4g0n7ly , are you still seeing this error? if so, could you tell us what platform do you use (windows, linux, mac)
look like windows,i think you shoud check print of your server.py @dr4g0n7ly
Describe the bug
I used the exact same code to follow along with the PyTorch Quickstart tutorial at https://flower.dev/docs/framework/quickstart-pytorch.html I get an error saying DNS resolution failed for 127:0:01:8080: UNAVAILABLE: WSA Error
Steps/Code to Reproduce
client.py
from collections import OrderedDict
import torch import torch.nn as nn import torch.nn.functional as F import torchvision.transforms as transforms from torch.utils.data import DataLoader from torchvision.datasets import CIFAR10
import flwr as fl
DEVICE = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
Load CIFAR-10
def load_data(): transform = transforms.Compose([ transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) ]) trainset = CIFAR10(".", train=True, download=True, transform=transform) testset = CIFAR10(".", train=False, download=True, transform=transform) trainloader = DataLoader(trainset, batch_size=32, shuffle=True) testloader = DataLoader(testset, batch_size=32) num_examples = {"trainset" : len(trainset), "testset" : len(testset)} return trainloader, testloader, num_examples
Train network on training set
def train(net, trainloader, epochs): criterion = torch.nn.CrossEntropyLoss() optimizer = torch.optim.SGD(net.parameters(), lr=0.001, momentum=0.9) for _ in range(epochs): for images, labels in trainloader: images, labels = images.to(DEVICE), labels.to(DEVICE) optimizer.zero_grad() loss = criterion(net(images), labels) loss.backward() optimizer.step()
Validate the network on the entire test set
def test(net, testloader): criterion = torch.nn.CrossEntropyLoss() correct, total, loss = 0, 0, 0.0 with torch.nograd(): for data in testloader: images, labels = data[0].to(DEVICE), data[1].to(DEVICE) outputs = net(images) loss += criterion(outputs, labels).item() , predicted = torch.max(outputs.data, 1) total += labels.size(0) correct += (predicted == labels).sum().item() accuracy = correct / total return loss, accuracy
model
class Net(nn.Module): def init(self) -> None: super(Net, self).init() self.conv1 = nn.Conv2d(3, 6, 5) self.pool = nn.MaxPool2d(2, 2) self.conv2 = nn.Conv2d(6, 16, 5) self.fc1 = nn.Linear(16 5 5, 120) self.fc2 = nn.Linear(120, 84) self.fc3 = nn.Linear(84, 10)
Load model and data
net = Net().to(DEVICE) trainloader, testloader, num_examples = load_data()
class CifarClient(fl.client.NumPyClient): def getparameters(self, config): return [val.cpu().numpy() for , val in net.state_dict().items()]
fl.client.start_numpy_client( server_address="127:0:01:8080", client=CifarClient() )
-------------
server.py
import flwr as fl
strategy = fl.server.strategy.FedAvg()
fl.server.start_server( server_address="0.0.0.0:8080", config=fl.server.ServerConfig(num_rounds=3), strategy=strategy, )
Expected Results
Once I run the server.py and then the client.py, as per my understanding the model should start training at the client
Actual Results
I get the following error