code: def test_tensor_serializer():
      seed_everything(42)
  
      serializer_tensor = TensorSerializer()
      serializer_pickle = PickleSerializer()
  
      ratio_times = []
      ratio_bytes = []
      shapes = [
          (10,),
          (10, 10),
          (10, 10, 10),
          (10, 10, 10, 5),
          (10, 10, 10, 5, 4),
      ]
      for dtype in _TORCH_DTYPES_MAPPING.values():
          for shape in shapes:
              # Not serializable for some reasons
              if dtype in [torch.bfloat16]:
                  continue
              tensor = torch.ones(shape, dtype=dtype)
  
              t0 = time()
              data, _ = serializer_tensor.serialize(tensor)
              deserialized_tensor = serializer_tensor.deserialize(data)
              tensor_time = time() - t0
              tensor_bytes = len(data)
  
              assert deserialized_tensor.dtype == dtype
              assert torch.equal(tensor, deserialized_tensor)
  
              t1 = time()
              data, _ = serializer_pickle.serialize(tensor)
              deserialized_tensor = serializer_pickle.deserialize(data)
              pickle_time = time() - t1
              pickle_bytes = len(data)
  
              assert deserialized_tensor.dtype == dtype
              assert torch.equal(tensor, deserialized_tensor)
  
              ratio_times.append(pickle_time / tensor_time)
              ratio_bytes.append(pickle_bytes / tensor_bytes)
  
      assert np.mean(ratio_times) > 1.6
      assert np.mean(ratio_bytes) > 2
  
file_path: pytorch-lightning/tests/tests_data/streaming/test_serializer.py
imports: import os
  import sys
  from time import time
  import numpy
  import pytest
  import torch
  from lightning import seed_everything
  from lightning.data.streaming.serializers import _AV_AVAILABLE, _NUMPY_DTYPES_MAPPING, _SERIALIZERS, _TORCH_DTYPES_MAPPING, _TORCH_VISION_AVAILABLE, IntSerializer, NoHeaderNumpySerializer, NoHeaderTensorSerializer, NumpySerializer, PickleSerializer, PILSerializer, TensorSerializer, VideoSerializer
  from lightning_utilities.core.imports import RequirementCache
label_desc: Use image node_id 4 for calling a global function with example usage: test_tensor_serializer() without return types