def deep_to_flat(cfg):
    """
    Function flattens a nested config in dictionary format by joining keys of nested
    dictionaries with ".".

    For example,
    ```
    >>> cfg = {"a": {"b": 1, "c": 2}, "d": 3}
    >>> print(deep_to_flat(cfg))
    {"a.b": 1, "a.c": 2, "d": 3}
    ```
    """
    res_cfg = {}
    for key, val in cfg.items():
        if isinstance(val, dict):
            val = deep_to_flat(val)
            # After recursive flattening, `val` is now a flat dictionary. Add its keys
            # to the current level
            for sub_key, sub_val in val.items():
                res_cfg[f"{key}.{sub_key}"] = sub_val
        else:
            res_cfg[key] = val
    return res_cfg