from typing import Any
import io
import torch


def _serialize(data: Any):
    """
    Serializes to bytes using PyTorch's
    serialization tools.

    Args:
        data (Any): The data to be serialized.

    Returns:
        bytes: The data serialized to bytes.
    """
    buff = io.BytesIO()
    torch.save(data, buff)
    buff.seek(0)
    return buff.read()