PySyft icon indicating copy to clipboard operation
PySyft copied to clipboard

Part 2 of the Grid Tutorials Series throws TypeError in Step 2.2

Open hallojs opened this issue 6 years ago • 4 comments

Description

Running part 2 step 2.2 of the grid tutorial series with mpc = True throws TypeError: can not serialize ‘NodeClient’ object. With mpc = False the tutorial section works. This seems to be related to #3648.

How to Reproduce

Just run the tutorial.

Expected Behavior

An error message as below.

Screenshots

TypeError                                 Traceback (most recent call last)
<ipython-input-4-e72cafd212c8> in <module>
      9 receive the mpc results and aggregate it, returning the inference's result.
     10 '''
---> 11 result = cloud_grid_service.run_remote_inference("convnet", user_input_data, mpc=True)# If mpc flag is False, It will send your real data to the platform.
     12 print("Inference's result: ", result) # ( [2.0, 4.0] * [5.0, 3.0] ) + [1000] = [1022]

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/grid/public_grid.py in run_remote_inference(self, id, data, mpc)
    103             return self._run_unencrypted_inference(id, data)
    104         else:
--> 105             return self._run_encrypted_inference(id, data)
    106 
    107     def _serve_unencrypted_model(

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/grid/public_grid.py in _run_encrypted_inference(self, id, data, copy)
    285         # Perform Inference
    286         fetched_plan = self.hook.local_worker.fetch_plan(id, host_node, copy=copy)
--> 287         return fetched_plan(shared_data).get().float_prec()
    288 
    289     def __connect_with_node(self, node_id, node_url):

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/execution/plan.py in __call__(self, *args)
    348                 self.input_types.input_check(self, args)
    349             self.role.instantiate_inputs(args)
--> 350             result = self.role.execute()
    351             if len(result) == 1:
    352                 return result[0]

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/execution/role.py in execute(self)
    165         """
    166         for action in self.actions:
--> 167             self._execute_action(action)
    168 
    169         output_placeholders = tuple(

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/execution/role.py in _execute_action(self, action)
    226             response = method(*args_, **kwargs_)
    227         else:
--> 228             response = getattr(_self, cmd)(*args_, **kwargs_)
    229 
    230         if not isinstance(response, (tuple, list)):

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/generic/frameworks/hook/tensors.py in tracing_method(self, *args, **kwargs)
    174         def create_tracing_method(base_method, name):
    175             def tracing_method(self, *args, **kwargs):
--> 176                 response = base_method(self, *args, **kwargs)
    177                 command = (name, self, args, kwargs), response
    178                 if self.tracing:

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/generic/frameworks/hook/hook.py in overloaded_syft_method(self, *args, **kwargs)
    114 
    115             # Send it to the appropriate class and get the response
--> 116             response = getattr(new_self, attr)(*new_args, **new_kwargs)
    117 
    118             # Put back SyftTensor on the tensors found in the response

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/generic/frameworks/hook/hook.py in overloaded_native_method(self, *args, **kwargs)
    208                 # Send the new command to the appropriate class and get the response
    209                 method = getattr(new_self, method_name)
--> 210                 response = method(*new_args, **new_kwargs)
    211 
    212                 # For inplace methods, just directly return self

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/frameworks/torch/tensors/interpreters/precision.py in matmul(self, *args, **kwargs)
    430 
    431         # Send it to the appropriate class and get the response
--> 432         response = getattr(new_self, "matmul")(*new_args, **new_kwargs)
    433 
    434         # Put back SyftTensor on the tensors found in the response

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/frameworks/torch/tensors/interpreters/additive_shared.py in matmul(self, other)
    646             return self._public_mul(other, "matmul")
    647 
--> 648         return self._private_mul(other, "matmul")
    649 
    650     def mm(self, *args, **kwargs):

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/frameworks/torch/tensors/interpreters/additive_shared.py in _private_mul(self, other, equation)
    536             raise AttributeError("For multiplication a crypto_provider must be passed.")
    537 
--> 538         shares = spdz.spdz_mul(cmd, self, other, self.crypto_provider, self.field, self.dtype)
    539 
    540         return shares

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/frameworks/torch/mpc/spdz.py in spdz_mul(cmd, x_sh, y_sh, crypto_provider, field, dtype)
     32     # Get triples
     33     a, b, a_mul_b = request_triple(
---> 34         crypto_provider, cmd, field, dtype, x_sh.shape, y_sh.shape, locations
     35     )
     36 

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/frameworks/torch/mpc/beaver.py in request_triple(crypto_provider, cmd, field, dtype, a_size, b_size, locations)
     37 
     38     shares = (
---> 39         res.share(*locations, field=field, dtype=dtype, crypto_provider=crypto_provider).get().child
     40     )
     41     a_shared = shares[: a.numel()].reshape(a_size)

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/frameworks/torch/tensors/interpreters/native.py in share(self, protocol, field, dtype, crypto_provider, requires_grad, no_wrap, *owners)
    907                 dtype=dtype,
    908                 crypto_provider=crypto_provider,
--> 909                 **kwargs_,
    910             )
    911         else:

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/generic/pointers/pointer_tensor.py in share(self, *args, **kwargs)
    380             raise RuntimeError("Error, share must have > 1 arguments all of type syft.workers")
    381 
--> 382         response = self.owner.send_command(self.location, "share", self, args, kwargs)
    383         return response
    384 

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/workers/base.py in send_command(self, recipient, cmd_name, target, args_, kwargs_, return_ids, return_value)
    624                 cmd_name, target, args_, kwargs_, return_ids, return_value
    625             )
--> 626             ret_val = self.send_msg(message, location=recipient)
    627         except ResponseSignatureError as e:
    628             ret_val = None

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/workers/base.py in send_msg(self, message, location)
    269 
    270         # Step 1: serialize the message to a binary
--> 271         bin_message = sy.serde.serialize(message, worker=self)
    272 
    273         # Step 2: send the message and wait for a response

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/serde/serde.py in serialize(obj, worker, simplified, force_full_simplification, strategy)
     43         strategy = serialize
     44 
---> 45     return strategy(obj, worker, simplified, force_full_simplification)
     46 
     47 

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/serde/msgpack/serde.py in serialize(obj, worker, simplified, force_full_simplification)
    335 
    336     simple_objects = _serialize_msgpack_simple(obj, worker, simplified, force_full_simplification)
--> 337     return _serialize_msgpack_binary(simple_objects)
    338 
    339 

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/syft/serde/msgpack/serde.py in _serialize_msgpack_binary(simple_objects, worker, simplified, force_full_simplification)
    289     # 2) Serialize
    290     # serialize into a binary
--> 291     binary = msgpack_lib.dumps(simple_objects)
    292 
    293     # 3) Compress

~/.pyenv/versions/pysyft_playground/lib/python3.7/site-packages/msgpack/__init__.py in packb(o, **kwargs)
     33     See :class:`Packer` for options.
     34     """
---> 35     return Packer(**kwargs).pack(o)
     36 
     37 

msgpack/_packer.pyx in msgpack._cmsgpack.Packer.pack()

msgpack/_packer.pyx in msgpack._cmsgpack.Packer.pack()

msgpack/_packer.pyx in msgpack._cmsgpack.Packer.pack()

msgpack/_packer.pyx in msgpack._cmsgpack.Packer._pack()

msgpack/_packer.pyx in msgpack._cmsgpack.Packer._pack()

msgpack/_packer.pyx in msgpack._cmsgpack.Packer._pack()

msgpack/_packer.pyx in msgpack._cmsgpack.Packer._pack()

msgpack/_packer.pyx in msgpack._cmsgpack.Packer._pack()

msgpack/_packer.pyx in msgpack._cmsgpack.Packer._pack()

msgpack/_packer.pyx in msgpack._cmsgpack.Packer._pack()

TypeError: can not serialize 'NodeClient' object

System Information

  • OS: MacOS
  • OS Version: 10.15.5
  • Language Version: Python 3.7.7
  • Package Manager Version: pip 20.1.1

hallojs avatar Jun 14 '20 15:06 hallojs

I am facing the same issue. Has it been resolved for you?

hammad45 avatar Jul 08 '20 09:07 hammad45

No, unfortunately for me there is no solution yet.

hallojs avatar Jul 08 '20 09:07 hallojs

Hi, I found a solution for this, take a look here https://github.com/kuronosec/PySyft/commit/bd69d25c22aa106bbbeb13764e09a938bb617858 and here https://github.com/kuronosec/syft-proto/commit/e63901e5ffb003fec2c6bf98fe5b10b863c3e6db. But I don't know if that's the right solution or just a workaround.

kuronosec avatar Jul 08 '20 10:07 kuronosec

This issue has been marked stale because it has been open 30 days with no activity. Leave a comment or remove the stale label to unmark it. Otherwise, this will be closed in 7 days.

github-actions[bot] avatar Aug 08 '20 00:08 github-actions[bot]