code: def _object_to_tensor(obj, device=None):
      f = io.BytesIO()
      _pickler(f).dump(obj)
      byte_storage = torch.ByteStorage.from_buffer(f.getvalue())  # type: ignore[attr-defined]
      # Do not replace `torch.ByteTensor` or `torch.LongTensor` with torch.tensor and specifying dtype.
      # Otherwise, it will casue 100X slowdown.
      # See: https://github.com/pytorch/pytorch/issues/65696
      byte_tensor = torch.ByteTensor(byte_storage)
      local_size = torch.LongTensor([byte_tensor.numel()])
      if device is not None:
          byte_tensor = byte_tensor.to(device)
          local_size = local_size.to(device)
      return byte_tensor, local_size
  
file_path: fastNLP/fastNLP/core/drivers/torch_driver/dist_utils.py
imports: import io
  import pickle
  import os
  from typing import Any, List
  from fastNLP.envs.imports import _TORCH_GREATER_EQUAL_1_8
  from fastNLP.core.utils.torch_utils import DEFAULT_TORCH_GROUP
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH
  from fastNLP.envs.env import FASTNLP_NO_SYNC
  from fastNLP.core.utils import apply_to_collection
label_desc: Use image node_id 3 for calling a global function with example usage: _object_to_tensor(obj, device) and returns: byte_tensor,  local_size