import torch


def determine_incumbent(learning_rates, valid_errors):
    """Determines and returns the best validation error and the corresponding learning rates.

    Args:
        learning_rates (torch.Tensor): All prior learning rates.
        valid_errors (torch.Tensor): The corresponding validation errors.

    Returns:
        dict: The incumbent.
        int: Position inside valid_errors where the best performing validation error was found.
    """
    pos_best = torch.argmin(valid_errors)

    incumbent = {
        'lrs': learning_rates[pos_best],
        'valid_error': valid_errors[pos_best]
    }
    return incumbent, pos_best