def count_unique_params(tensor):
    """
    Returns number of unique parameters in the same tensor.
    Set a defaulted absolute tolerance, so that very close values can be treated as identical in palletization.
    """
    unique_set = {tensor[0]}
    for elem in tensor[1:]:
        if all(not torch.isclose(elem, uelem, atol=1e-6) for uelem in unique_set):
            unique_set.add(elem)
    return len(unique_set)

    Returns number of unique parameters in the same tensor.
    Set a defaulted absolute tolerance, so that very close values can be treated as identical in palletization.
    
coremltools/test/optimize/torch/utils.py