code: def load_service_config_file(path: Union[str, TextIO]) -> Dict:
      import mars
  
      mars_path = os.path.dirname(os.path.abspath(mars.__file__))
  
      cfg_stack = []  # type: List[Dict]
      cfg_file_set = set()
      if isinstance(path, str):
          path = os.path.abspath(path)
  
      while path is not None:
          if path in cfg_file_set:  # pragma: no cover
              raise ValueError("Recursive config inherit detected")
  
          if not hasattr(path, "read"):
              with open(path) as file:
                  cfg = yaml.safe_load(file)
          else:
              cfg = yaml.safe_load(path)
          cfg_stack.append(cfg)
          cfg_file_set.add(path)
  
          inherit_path = cfg.pop("@inherits", None)
          if not inherit_path:
              path = None
          elif os.path.isfile(inherit_path):
              path = inherit_path
          elif inherit_path == "@default":
              path = DEFAULT_CONFIG_FILE
          elif inherit_path.startswith("@mars"):
              path = inherit_path.replace("@mars", mars_path)
          else:
              path = os.path.join(os.path.dirname(path), inherit_path)
  
      def _override_cfg(
          src: Union[Dict, List], override: Union[Dict, List]
      ):
          if isinstance(override, dict):
              overriding_fields = set(
                  src.get("@overriding_fields") or set()
              )
              for key, val in override.items():
                  if (
                      key not in src
                      or not isinstance(val, (list, dict))
                      or key in overriding_fields
                  ):
                      src[key] = val
                  else:
                      _override_cfg(src[key], override[key])
          else:
              src.extend(override)
  
      def _clear_meta_cfg(src: Dict):
          meta_keys = []
          for k, v in src.items():
              if k.startswith("@"):
                  meta_keys.append(k)
              elif isinstance(v, dict):
                  _clear_meta_cfg(v)
  
          for k in meta_keys:
              src.pop(k)
  
      cfg = cfg_stack[-1]
      for new_cfg in cfg_stack[-2::-1]:
          _override_cfg(cfg, new_cfg)
  
      _clear_meta_cfg(cfg)
      return cfg
  
file_path: mars/mars/deploy/utils.py
imports: import asyncio
  import os
  import time
  import warnings
  from typing import Callable, Dict, List, Union, TextIO
  import yaml
  from ..services import NodeRole
  from ..utils import merge_dict, flatten_dict_to_nested_dict
label_desc: Use image node_id 2 for calling a global function with example usage: load_service_config_file(path) and returns: cfg