def test_search_obj(self): hook = sy.TorchHook() hook.local_worker.is_client_worker = False x = sy.Var(sy.FloatTensor( [-2, -1, 0, 1, 2, 3])).set_id('#boston_housing #target #dataset') y = sy.Var(sy.FloatTensor( [-2, -1, 0, 1, 2, 3])).set_id('#boston_housing #input #dataset') hook.local_worker.is_client_worker = True assert len(hook.local_worker.search("#boston_housing")) == 2 assert len(hook.local_worker.search(["#boston_housing", "#target"])) == 1
def test_set_id(self): init_state = hook.local_worker.is_client_worker hook.local_worker.is_client_worker = False x = torch.FloatTensor([-2, -1, 0, 1, 2, 3]).set_id('bobs tensor') assert x.id == 'bobs tensor' assert x.child.id == 'bobs tensor' assert x.id in hook.local_worker._objects assert list(x.child.old_ids)[0] in hook.local_worker._objects assert list(x.child.old_ids)[0] != x.id x = sy.Var(sy.FloatTensor([-2, -1, 0, 1, 2, 3])).set_id('bobs variable') assert x.id == 'bobs variable' assert x.child.id == 'bobs variable' assert x.id in hook.local_worker._objects assert list(x.child.old_ids)[0] in hook.local_worker._objects assert list(x.child.old_ids)[0] != x.id
])) # create a couple workers bob = sy.VirtualWorker(id="bob") alice = sy.VirtualWorker(id="alice") secure_worker = sy.VirtualWorker(id="secure_worker") #bob.add_workers([alice, secure_worker]) #alice.add_workers([bob, secure_worker]) #secure_worker.add_workers([alice, bob]) train_distributed_dataset = [] for batch_idx, (data, target) in enumerate(train_loader): if batch_idx > 4: break data = sy.Var(data) target = sy.Var(target.long()) data.send(bob) target.send(bob) train_distributed_dataset.append((data, target)) #bobs_model = model.copy().send(bob) #alices_model = model.copy().send(alice) bobs_model = Net() bobs_opt = optim.SGD(params=bobs_model.parameters(), lr=0.1) #alices_opt = optim.SGD(params=alices_model.parameters(),lr=0.1) bobs_model = bobs_model.send(bob)