PySyft icon indicating copy to clipboard operation
PySyft copied to clipboard

Data Centric Federated Learning: remote_torch not working

Open maltetoelle opened this issue 3 years ago • 0 comments

Question

Is the remote_torch the torch Module of the data owner in the data centric setting?

Further Information

I have implemented a rudimentary working example of a data centric federated learning framework that I have deployed locally. I used the example from https://github.com/OpenMined/PySyft/blob/dev/packages/syft/examples/federated-learning/data-centric/Data%20centric%20Federated%20learning.ipynb. For me both of the following versions do not work

remote_torch = do_client.torch
remote_torch = ROOT_CLIENT.torch

If I use the network or data scientist client it does not work either. My question is which torch do I have to use?

The full exception message is:

An <class 'Exception'> has been triggered by <class 'syft.core.node.common.action.get_object_action.GetObjectAction'> from <Address - Domain:<SpecificLocation:..3f838>>
Unable to Get Object with ID <UID: 07fb38c4751347f096d3b32706fc1987> from store. Possible dangling Pointer. Object not found!

Full code:

from syft.grid.client.client import connect
from syft.core.plan.plan_builder import make_plan, ROOT_CLIENT
from syft import SyModule
import torch as th

NETWORK_URL = "http://localhost:7000"
DOMAIN_URL = "http://localhost:5000"
net_email, net_pw = "[email protected]", "12345"
do_email, do_pw = "[email protected]", "23456"
ds_email, ds_pw = "[email protected]", "34567"
token = "9G9MJ06OQH"
network_whitelist = [DOMAIN_URL]

tag = "#mydataset"

query = f"{tag}:x"

network_client = connect(NETWORK_URL, credentials={"email": net_email, "password": net_pw})

urls = network_client.search(query=[query])["match-nodes"]
url = urls[0]

ds_client = connect(url=url, credentials={"email": ds_email, "password": ds_pw})

class MySyModule(SyModule):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.layer1 = th.nn.Linear(28 * 28, 100)
        self.relu1 = th.nn.ReLU()
        self.layer2 = th.nn.Linear(100, 10)

    def forward(self, x):
        x_reshaped = x.view(-1, 28 * 28)
        o1 = self.layer1(x_reshaped)
        a1 = self.relu1(o1)
        out = self.layer2(a1)
        return out

model = MySyModule(input_size=(32,28*28))
data_x, data_y = th.randn(1024,1,28,28), th.randint(10, (1024,))

do_client = connect(DOMAIN_URL, credentials={"email": do_email, "password": do_pw})

remote_torch = do_client.torch

@make_plan
def train(x=data_x, y=data_y, model=model):
    optimizer = remote_torch.optim.SGD(model.parameters(), lr=1e-1, momentum=0)
    optimizer.zero_grad()
    out = model(x=x)[0]
    loss = remote_torch.nn.functional.cross_entropy(out, y)
    loss.backward()
    optimizer.step()

    return [model]

x = [t for t in ds_client.store if f"{tag}:x" in t.tags][-1]
y = [t for t in ds_client.store if f"{tag}:y" in t.tags][-1]

train_ptr = train.send(ds_client)

out_ptr = train_ptr(x=x, y=y, model=model.send(do_client))
out_ptr.request()

do_client.requests[-1].accept()

updated_model, = out_ptr.get()

System Information

  • OS: iOS
  • OS Version: macOS Catalina
  • Language Version: Python3.8
  • Package Manager Version: Conda 4.10.1, pip 21.1.3

maltetoelle avatar Jul 01 '21 13:07 maltetoelle