Exemple #1
0
def do(ct_size: int, batch_size: int) -> None:
    # third party
    import numpy as np
    import tenseal as ts

    # syft absolute
    import syft as sy

    sy.load("tenseal")
    sy.logger.add(sys.stderr, "ERROR")

    duet = sy.launch_duet(loopback=True,
                          network_url=f"http://127.0.0.1:{PORT}/")
    duet.requests.add_handler(action="accept")

    context = ts.context(ts.SCHEME_TYPE.CKKS,
                         8192,
                         coeff_mod_bit_sizes=[60, 40, 40, 60],
                         n_threads=1)
    context.global_scale = pow(2, 40)

    data = np.random.uniform(-10, 10, 100)
    enc = []
    for i in range(ct_size):
        enc.append(ts.ckks_vector(context, data))

    start = time.time()
    _ = context.send(duet, pointable=True)
    for chunk in chunks(enc, batch_size):
        _ = sy.lib.python.List(chunk).send(duet, pointable=True)
    sys.stderr.write(
        f"[{ct_size}][{batch_size}] DO sending took {time.time() - start} sec\n"
    )

    sy.core.common.event_loop.loop.run_forever()
Exemple #2
0
async def main():
    duet = sy.launch_duet(network_url=NETWORK_URL, loopback=True)
    duet.requests.add_handler(action="accept")

    n_iterations_per_epoch = 10_000

    for i in range(N_EPOCHS):
        rets = await train(duet, i, n_iterations_per_epoch)
        print(f"Epoch {i+1} - Average return: {sum(rets) / len(rets):.4f}")
Exemple #3
0
def do_test(port: int) -> None:
    # syft absolute
    import syft as sy

    duet = sy.launch_duet(loopback=True,
                          network_url=f"http://127.0.0.1:{port}/")
    _ = sy.lib.python.List([1, 2, 3]).send(duet)

    sy.core.common.event_loop.loop.run_forever()
def do_send(data: Any, port: int) -> None:
    # syft absolute
    import syft as sy

    duet = sy.launch_duet(loopback=True,
                          network_url=f"http://127.0.0.1:{port}/")
    duet.requests.add_handler(action="accept")

    _ = data.send(duet, pointable=True)

    sy.core.common.event_loop.loop.run_forever()
Exemple #5
0
def do_test(port: int) -> None:
    # syft absolute
    import syft as sy

    sy.logger.add(sys.stderr, "ERROR")

    duet = sy.launch_duet(loopback=True,
                          network_url=f"http://127.0.0.1:{port}/")
    duet.requests.add_handler(action="accept")

    _ = sy.lib.python.List([1, 2, 3]).send(duet, pointable=True)

    sy.core.common.event_loop.loop.run_forever()
Exemple #6
0
def do_test(port: int) -> None:
    # third party
    import torch

    # syft absolute
    import syft as sy

    sy.logger.add(sys.stderr, "ERROR")

    duet = sy.launch_duet(loopback=True,
                          network_url=f"http://127.0.0.1:{port}/")
    duet.requests.add_handler(action="accept")

    t = torch.randn(20).reshape(4, 5)
    _ = t.send(duet, pointable=True)

    sy.core.common.event_loop.loop.run_forever()
Exemple #7
0
def do() -> None:
    # syft absolute
    import syft as sy

    _ = sy.logger.add(
        sink="syft_do.log",
        level="TRACE",
    )

    duet = sy.launch_duet(loopback=True, network_url="http://localhost:5000")
    duet.requests.add_handler(action="accept")
    t = th.randn(4000000)
    print("DO: Tensor sum:", t.sum())
    start = time.time()
    tp = t.send(duet, pointable=True)
    end = time.time()
    print("DO: Pointer: ", tp, "serialized in", end - start)
    print("DO: Store: ", duet.store)
    sy.core.common.event_loop.loop.run_forever()
    print("DO: DONE")
Exemple #8
0
import syft as sy

# Launch a Duet Server and upload data
duet = sy.launch_duet(loopback=True)
import torch as th
import numpy as np

data = th.FloatTensor(np.array([5, 15, 25, 35, 45, 55]).reshape(-1, 1))

data = data.tag("DO1 data")
data = data.describe("Dataset of 6 samples, 1 feature")

data_ptr = data.send(duet, pointable=True)

duet.store.pandas
data
duet.requests.add_handler(
    action="accept",
    print_local=True,  # print the result in your notebook
)
Exemple #9
0
 def connect_to_duet(self, loopback=True):
     self.duet = sy.launch_duet(loopback=loopback)
     return self.duet