def module_equals(model1, model2):
    """Check if 2 pytorch modules have the same weights

    """
    for p1, p2 in zip(model1.parameters(), model2.parameters()):
        if p1.data.ne(p2.data).sum() > 0:
            return False
    return True