code: def flat_nest_dict(
      d: Dict,
      separator: str = "#",
      compress_none_key: bool = True,
      top_down: bool = False,
  ) -> Dict:
      """
      将一个 nested 的 dict 转成 flat 的 dict，例如
      ex::
          d = {'test': {'f1': {'f': 0.2, 'rec': 0.1}}} -> {'f#f1#test':0.2, 'rec#f1#test':0.1}
  
      :param d: 需要展平的 dict 对象。
      :param separator: 不同层级之间的 key 之间的连接符号。
      :param compress_none_key: 如果有 key 为 None ，则忽略这一层连接。
      :param top_down: 新的 key 的是否按照从最底层往最底层的顺序连接。
      :return:
      """
      assert isinstance(d, Dict)
      assert isinstance(separator, str)
      flat_d = {}
      for key, value in d.items():
          if key is None:
              key = ()
          else:
              key = (key,)
          if isinstance(value, Mapping):
              flat_d.update(
                  _flat_nest_dict(
                      value,
                      parent_key=key,
                      compress_none_key=compress_none_key,
                  )
              )
          else:
              flat_d[key] = value
  
      str_flat_d = {}
      for key, value in flat_d.items():
          if top_down:
              key = map(str, key)
          else:
              key = map(str, key[::-1])
          key = separator.join(key)
          str_flat_d[key] = value
      return str_flat_d
  
imports: import functools
  import inspect
  from inspect import Parameter
  import dataclasses
  from dataclasses import is_dataclass
  from copy import deepcopy
  from collections import defaultdict, OrderedDict
  from typing import Callable, List, Any, Dict, AnyStr, Union, Mapping, Sequence
  from typing import Tuple, Optional
  from time import sleep
  import os
  from contextlib import contextmanager
  from functools import wraps
  from prettytable import PrettyTable
  from pathlib import Path
  from fastNLP.core.log import logger
label_desc: Use image node_id 20 for calling a global function with example usage: flat_nest_dict(d, separator, compress_none_key, top_down) and returns: str_flat_d