import dataclasses


def to_dict_format(cfg):
    """
    A configuration is a nested dictionary with potentially dataclasses as values. This
    function converts dataclasses to dictionaries for easier serialization.
    """
    if dataclasses.is_dataclass(cfg):
        cfg = dataclasses.asdict(cfg)
        return to_dict_format(cfg)

    res_cfg = {}
    for key, val in cfg.items():
        if isinstance(val, dict):
            res_cfg[key] = to_dict_format(val)
        elif dataclasses.is_dataclass(val):
            res_cfg[key] = dataclasses.asdict(val)
        else:
            res_cfg[key] = val
    return res_cfg