def valid_aux_task_layer_list(aux_layer_ids, enc_num_layers):
    """Check whether input list of auxiliary layer ids is valid.

       Return the valid list sorted with duplicated removed.

    Args:
        aux_layer_ids (list): Auxiliary layers ids
        enc_num_layers (int): Number of encoder layers

    Returns:
        valid (list): Validated list of layers for auxiliary task

    """
    if (
        not isinstance(aux_layer_ids, list)
        or not aux_layer_ids
        or not all(isinstance(layer, int) for layer in aux_layer_ids)
    ):
        raise ValueError("--aux-task-layer-list argument takes a list of layer ids.")

    sorted_list = sorted(aux_layer_ids, key=int, reverse=False)
    valid = list(filter(lambda x: 0 <= x < enc_num_layers, sorted_list))

    if sorted_list != valid:
        raise ValueError(
            "Provided list of layer ids for auxiliary task is incorrect. "
            "IDs should be between [0, %d]" % (enc_num_layers - 1)
        )

    return valid