import torch


def get_to_kwargs(x) -> dict:
    """
    Get kwargs for ``Tensor.to(dtype=?, device=?)``
    :param x: A tensor or Module.
    :return: Dictionary of kwargs.
    """
    if isinstance(x, torch.nn.Module):
        return get_to_kwargs(next(iter(x.parameters())))
    return {'dtype': x.dtype, 'device': x.device}