def send_to_device(tensor: Any, device: torch.device):
    """
    Recursively sends the elements in a nested list/tuple/dictionary of tensors to a given device.
    Borrowed from huggingface/accelerate.
    Args:
        tensor (nested list/tuple/dictionary of :obj:`torch.Tensor`):
            The data to send to a given device.
        device (:obj:`torch.device`):
            The device to send the data to

    Returns:
        The same data structure as :obj:`tensor` with all tensors sent to the proper device.
    """

    def _send_to_device(t, device):
        return t.to(device)

    def _has_to_method(t):
        return hasattr(t, "to")

    return recursively_apply(_send_to_device, tensor, device, test_type=_has_to_method)
Recursively sends the elements in a nested list/tuple/dictionary of tensors to a given device.
Borrowed from huggingface/accelerate.
Args:
tensor (nested list/tuple/dictionary of :obj:`torch.Tensor`):
The data to send to a given device.
device (:obj:`torch.device`):
The device to send the data to

Returns:
The same data structure as :obj:`tensor` with all tensors sent to the proper device.
towhee/trainer/utils/trainer_utils.py