code: def recv_obj(sender: int) -> typing.Any:
      """Receive an arbitrary python object from ``sender``.
  
      WARN: This incur a CPU <-> GPU transfers and should be used sparingly
      for performance reasons.
  
      Args:
          sender (int): The rank sending the message.
      """
      # Get message meta
      length = torch.tensor([0], dtype=torch.long).cuda()
      dist.recv(length, src=sender)
  
      # Receive and deserialize
      msg = torch.empty(length.item(), dtype=torch.uint8).cuda()
      dist.recv(msg, src=sender)
  
      msg = pickle.loads(msg.cpu().numpy().tobytes())
  
      def _to(x):
          """Recursively move to the current device."""
          if torch.is_tensor(x):
              return x.cuda()
          if isinstance(x, (tuple, list)):
              ret = [_to(x_) for x_ in x]
              if isinstance(x, tuple):
                  ret = tuple(ret)
              return ret
          # handle kwargs
          if isinstance(x, dict):
              ret = dict()
              for key, val in x.items():
                  ret[_to(key)] = _to(val)
              return ret
  
          # Anything else is a no-op
          return x
  
      msg = _to(msg)
      return msg
  
file_path: H2O/h2o_flexgen/benchmark/third_party/DeepSpeed/deepspeed/runtime/pipe/p2p.py
imports: import pickle
  import typing
  import torch
  from deepspeed import comm
  from packaging.version import Version
  from deepspeed.git_version_info import torch_info
label_desc: Use image node_id 8 for calling a global function with example usage: recv_obj(sender) and returns: msg, x, x, ret, ret