def connect_to_duet(self, loopback=True, server_id=None, name=None): duet = sy.join_duet( loopback=loopback) if loopback else sy.join_duet(server_id) self.duet_list.append(duet) if name: self.do_names.append(name) self.dic_owner_duet[name] = duet return duet
def ds(ct_size: int, batch_size: int) -> None: # syft absolute import syft as sy sy.load("tenseal") sy.logger.add(sys.stderr, "ERROR") duet = sy.join_duet(loopback=True, network_url=f"http://127.0.0.1:{PORT}/") time.sleep(10) cnt = int(ct_size / batch_size) start = time.time() ctx = duet.store[0].get(request_block=True, delete_obj=False) for idx in range(1, cnt + 1): data = duet.store[idx].get(request_block=True, delete_obj=False) for tensor in data: tensor.link_context(ctx) assert len(data) == batch_size, len(data) sys.stderr.write( f"[{ct_size}][{batch_size}] DS get took {time.time() - start} sec\n")
def ds_test(port: int) -> None: # syft absolute import syft as sy sy.logger.add(sys.stderr, "ERROR") duet = sy.join_duet(loopback=True, network_url=f"http://127.0.0.1:{port}/") time.sleep(1) data_ptr = duet.store[0] data = data_ptr.get(request_block=True, delete_obj=False) assert data == [1, 2, 3]
def ds_get(data: Any, port: int) -> None: # syft absolute import syft as sy duet = sy.join_duet(loopback=True, network_url=f"http://127.0.0.1:{port}/") for retry in range(10): if len(duet.store) != 0: break time.sleep(0.1) assert len(duet.store) != 0 remote = duet.store[0].get(request_block=True, delete_obj=False) assert remote == data
def ds_test(port: int) -> None: # third party import torch # syft absolute import syft as sy sy.logger.add(sys.stderr, "ERROR") duet = sy.join_duet(loopback=True, network_url=f"http://127.0.0.1:{port}/") time.sleep(3) data = duet.store[0].get(request_block=True, delete_obj=False) assert data.shape == torch.Size([4, 5]), data.shape
def ds() -> None: # syft absolute import syft as sy _ = sy.logger.add( sink="syft_ds.log", level="TRACE", ) duet = sy.join_duet(loopback=True, network_url="http://localhost:5000") time.sleep(1) print("DS: Store: ", duet.store) start = time.time() t = duet.store[0].get(request_block=True, delete_obj=False) end = time.time() print("DS: Received in:", end - start) print("DS: Shape: ", t.shape) print("DS: Tensor sum:", t.sum())
async def main(n_data_owners: int) -> None: duets = [ sy.join_duet(network_url=NETWORK_URL, loopback=True) for _ in range(n_data_owners) ] n_games_per_epoch = 10_000 q_table = T.zeros((32, 11, 2, 2)) _, pre_rets = run_epoch(n_games_per_epoch, q_table, train=False) print( f"Initial agent - Average return: {sum(pre_rets) / len(pre_rets):.4f}") for _ in range(N_EPOCHS): q_table = await train(duets, q_table) _, post_rets = run_epoch(n_games_per_epoch, q_table, train=False) print( f"Trained agent - Average return: {sum(post_rets) / len(post_rets):.4f}" )
# run this from the interactive command line like: # python -i examples/duet/cli/ds.py # or you can run these commands manually in the python REPL # syft absolute import syft as sy duet = sy.join_duet(loopback=True) print("DS Store", duet.store)
import syft as sy import torch as th import numpy as np from collections import OrderedDict import torch as torch duet1 = sy.join_duet(loopback=True) duet1.store.pandas duet2 = sy.join_duet(loopback=True) duet2.store.pandas data1_ptr = duet1.store[0] data2_ptr = duet2.store[0] print(data1_ptr) print(data2_ptr) # import torch in_dim = 1 out_dim = 1 class SyNet(sy.Module): def __init__(self, torch_ref): super(SyNet, self).__init__(torch_ref=torch_ref) self.linear = self.torch_ref.nn.Linear(in_dim, out_dim) def forward(self, x): x = self.linear(x) return x
def ds_test(port: int) -> None: # syft absolute import syft as sy _ = sy.join_duet(loopback=True, network_url=f"http://127.0.0.1:{port}/")