code: def serialize_torch_tensor(
      tensor: torch.Tensor,
      compression_type: runtime_pb2.CompressionType = runtime_pb2.CompressionType.NONE,
      info: Optional[CompressionInfo] = None,
      allow_inplace: bool = False,
      **kwargs,
  ) -> runtime_pb2.Tensor:
      """Serialize a given tensor into a protobuf message using the specified compression strategy"""
      assert tensor.device == torch.device("cpu")
      compression = _BASE_COMPRESSION_TYPES[
          runtime_pb2.CompressionType.Name(compression_type)
      ]
      info = info or CompressionInfo.from_tensor(tensor, **kwargs)
      return compression.compress(tensor, info, allow_inplace)
  
file_path: hivemind/hivemind/compression/serialization.py
imports: from __future__ import annotations
  from typing import AsyncIterator, Dict, Iterable, List, Optional
  import torch
  from hivemind.compression.base import CompressionBase, CompressionInfo, NoCompression
  from hivemind.compression.floating import Float16Compression, ScaledFloat16Compression
  from hivemind.compression.quantization import BlockwiseQuantization, Quantile8BitQuantization, Uniform8BitQuantization
  from hivemind.proto import runtime_pb2
  from hivemind.utils.streaming import combine_from_streaming
label_desc: Use image node_id 1 for calling a global function with example usage: serialize_torch_tensor(tensor, compression_type, info, allow_inplace) and returns: compression