import torch


def clone_hidden(h):
    """Clone hidden states in new Tensors."""
    if isinstance(h, torch.Tensor):
        return h.clone()
    else:
        return tuple(clone_hidden(v) for v in h)