import torch


def dict_to_torchGMM(gmm: dict) -> torch.distributions.MixtureSameFamily:
    """Convert a dictionary to a Gaussian mixture distribution in PyTorch

    Args:
        gmm: dictionary of GMM parameters
    
    Return: a GMM in PyTorch distribution
    """
    mixture_distribution = torch.distributions.Categorical(probs=gmm['pi'])
    comp_distribution = torch.distributions.multivariate_normal.MultivariateNormal(
        loc=gmm['mean'],
        covariance_matrix=gmm['cov']
    )
    gm_distribution = torch.distributions.mixture_same_family.MixtureSameFamily(
        mixture_distribution=mixture_distribution,
        component_distribution=comp_distribution
    )
    return gm_distribution