def get_pretrain_stop_metric(early_stopping_method, pretrain_tasks):
    """
    Get stop_metric, which is used for early stopping. 

    Parameters
    -------------------
     early_stopping_method: str,
     pretrain_tasks: List[Task]

    Returns 
    -------------------
    stop_metric: str

    """
    if early_stopping_method != "auto":
        pretrain_names = [task.name for task in pretrain_tasks]
        if early_stopping_method in pretrain_names:
            index = pretrain_names.index(early_stopping_method)
            stop_metric = pretrain_tasks[index].val_metric
        else:
            raise ValueError("args.early_stopping_method must be either 'auto' or a task name")

    else:
        stop_metric = pretrain_tasks[0].val_metric if len(pretrain_tasks) == 1 else "macro_avg"
    return stop_metric