code: def to_data(value):
      
      # TODO: Use get_framework() for better detection.
      if value.__class__.__module__.startswith("torch"):
          import torch
          if isinstance(value, torch.nn.parameter.Parameter):
              value = value.data
          if isinstance(value, torch.Tensor):
              if value.requires_grad:
                  value = value.detach()
              value = value.cpu().numpy().copy()
          # If 0-dim array, convert to scalar
          if not value.shape:
              value = value.item()
      # Convert Numpy scalar types to Python types
      if value.__class__.__module__ == "numpy" and value.__class__.__name__ != "ndarray":
          value = value.item()
      return value
docs: Standardize data types. Converts PyTorch tensors to Numpy arrays,
      and Numpy scalars to Python scalars.