PySyft icon indicating copy to clipboard operation
PySyft copied to clipboard

Stuck in a dead loop when enumerating a remote tensor.

Open uid42 opened this issue 5 years ago • 2 comments

Further Information

A tensor was sent to the data scientist via duet. I get the TensorPointer and want to enumerate it, but the loop doesn't stop after every element was fetched; the exception is thrown on the data owner side.

But everything is ok if I break out of the loop as soon as all the elements are enumerated.

How to reproduce:

On the data owner side:

duet = sy.launch_duet(network_url = 'http://xxx', loopback = True) duet.requests.add_handler( name="get_data", action="accept", print_local=True ) p = torch.tensor([1,2,3]).tag("atensor").send(duet, searchable=True)

On the data scientist side:

duet = sy.join_duet(network_url = 'http://xxx', loopback = True) p = duet_ds1.store['atensor'] for t in p: print(t, t.get(request_block=True, name='get_data', delete_obj=False))

Output: <syft.proxy.torch.TensorPointer object at 0x7f39b27c4350> tensor(1) <syft.proxy.torch.TensorPointer object at 0x7f39b26c3fd0> tensor(2) <syft.proxy.torch.TensorPointer object at 0x7f39b27c2ed0> tensor(3) <syft.proxy.torch.TensorPointer object at 0x7f39b27c4310> None <syft.proxy.torch.TensorPointer object at 0x7f39b59f4a10> None .....

uid42 avatar Jan 06 '21 09:01 uid42

Hello @uid42!

You are right, this is a bug we've found and almost fixed it in the new release!

If you want to understand why this is happening, let's look a bit on some python internals:

example_list = [1, 2, 3]

for elem in example_list:
   pass

Here, python gets an iterator from example_list, when the iterator is exhausted (when the last element gets iterated), an error is being thrown that is being caught by the python interpreter, namely StopIteration. At this point, the for loop is exited.

Now, in the context of syft, we are iterating through a remote list, while the remote iterator gets exhausted and it throws an error on the owner side, the other side (data scientist) of the duet has no mechanism yet to know that the error has been thrown, so it's still looping and waiting for StopIteration to be thrown.

In the next patch we have a few fixes for this problem. :)

tudorcebere avatar Jan 10 '21 18:01 tudorcebere

Copy that, thank you!

uid42 avatar Jan 11 '21 02:01 uid42