def get_averaged_weights_by_path_mask(
    path_mask: str, logdir: Union[str, Path] = None
) -> OrderedDict:
    """
    Averaging of input weights and saving them.

    Args:
        path_mask: globe-like pattern for models to average
        logdir: Path to logs directory

    Returns:
        Averaged weights
    """
    if logdir is None:
        models_pathes = glob.glob(path_mask)
    else:
        models_pathes = glob.glob(os.path.join(logdir, "checkpoints", path_mask))

    all_weights = [_load_weights(path) for path in models_pathes]
    averaged_dict = average_weights(all_weights)

    return averaged_dict

    Averaging of input weights and saving them.

    Args:
        path_mask: globe-like pattern for models to average
        logdir: Path to logs directory

    Returns:
        Averaged weights
    
catalyst/contrib/utils/swa.py