def flat_to_deep(cfg):
    """
    Function converts a flat config to a nested config in dictionary format. This is
    the inverse of `deep_to_flat()`.
    """
    res_cfg = {}
    # By iterating over the items of `cfg` we resolve one level of nesting.
    for key, val in cfg.items():
        if "." in key:
            root, leaf = tuple(key.split(".", 1))  # Split off the first part
            if root not in res_cfg:
                res_cfg[root] = {}
            res_cfg[root][leaf] = val
        else:
            res_cfg[key] = val

    # Now we iterate again and call the function recursively to resolve deeper levels
    # of nesting.
    for key, val in res_cfg.items():
        if isinstance(val, dict):
            res_cfg[key] = flat_to_deep(val)

    return res_cfg