code: def resolve_dataset_name_from_cfg(cfg: "DictConfig") -> Optional[str]:
      """
      Parses items of the provided sub-config to find the first potential key that
      resolves to an existing file or directory.
  
      # Fast-path Resolution
      In order to handle cases where we need to resolve items that are not paths, a fastpath
      key can be provided as defined in the global `_VAL_TEST_FASTPATH_KEY`.
  
      This key can be used in two ways :
  
      ## _VAL_TEST_FASTPATH_KEY points to another key in the config
  
      If this _VAL_TEST_FASTPATH_KEY points to another key in this config itself,
      then we assume we want to loop through the values of that key.
  
      This allows for any key in the config to become a fastpath key.
  
      Example:
      validation_ds:
          splits: "val"
          ...
          <_VAL_TEST_FASTPATH_KEY>: "splits"  <-- this points to the key name "splits"
  
      Then we can write the following when overriding in hydra:
      ```python
      python train_file.py ... \
          model.validation_ds.splits=[val1, val2, dev1, dev2] ...
      ```
  
      ## _VAL_TEST_FASTPATH_KEY itself acts as the resolved key
  
      If this _VAL_TEST_FASTPATH_KEY does not point to another key in the config, then
      it is assumed that the items of this key itself are used for resolution.
  
      Example:
      validation_ds:
          ...
          <_VAL_TEST_FASTPATH_KEY>: "val"  <-- this points to the key name "splits"
  
      Then we can write the following when overriding in hydra:
      ```python
      python train_file.py ... \
          model.validation_ds.<_VAL_TEST_FASTPATH_KEY>=[val1, val2, dev1, dev2] ...
      ```
  
      # IMPORTANT NOTE:
      It <can> potentially mismatch if there exist more than 2 valid paths, and the
      first path does *not* resolve the the path of the data file (but does resolve to
      some other valid path).
  
      To avoid this side-effect, place the data path as the first item on the config file.
  
      Args:
          cfg: DictConfig (Sub-config) that should be parsed.
  
      Returns:
          A str representing the `key` of the config which hosts the filepath(s),
          or None in case path could not be resolved.
      """
      if (
          _VAL_TEST_FASTPATH_KEY in cfg
          and cfg[_VAL_TEST_FASTPATH_KEY] is not None
      ):
          fastpath_key = cfg[_VAL_TEST_FASTPATH_KEY]
  
          if isinstance(fastpath_key, str) and fastpath_key in cfg:
              return cfg[fastpath_key]
          else:
              return _VAL_TEST_FASTPATH_KEY
  
      for key, value in cfg.items():
          if type(value) in [list, tuple, ListConfig]:
              # Count the number of valid paths in the list
              values_are_paths = 0
              for val_i in value:
                  val_i = str(val_i)
                  if (
                      os.path.exists(val_i)
                      or os.path.isdir(val_i)
                      or is_datastore_path(val_i)
                  ):
                      values_are_paths += 1
                  else:
                      # reset counter and break inner loop
                      break
  
              if values_are_paths == len(value):
                  return key
  
          else:
              if (
                  os.path.exists(str(value))
                  or os.path.isdir(str(value))
                  or is_datastore_path(str(value))
              ):
                  return key
  
      return None
  
imports: import copy
  import importlib
  import os
  from dataclasses import dataclass, is_dataclass
  from enum import Enum
  from functools import lru_cache
  from pathlib import Path
  from typing import List, Optional, Tuple, Union
  import wrapt
  from nemo.utils import AppState, logging
  from nemo.utils.data_utils import resolve_cache_dir
  from nemo.utils.data_utils import is_datastore_path
label_desc: Use image node_id 1 for calling a global function with example usage: resolve_dataset_name_from_cfg(cfg) and returns: None, cfg, _VAL_TEST_FASTPATH_KEY, key, key