code: def explode_key_values(
      primary_key: str,
      mapping: Dict[str, List[Dict[Literal["key", "values"], Any]]],
      process_key: Callable[[str, str], str] = lambda _, s: s,
  ) -> List[Dict[str, Any]]:
      """
      Explodes a mapping from primary keys to a list of key to value mappings
      into independent configurations.
      """
      all_combinations = {
          primary: itertools.product(
              *[
                  [(option["key"], value) for value in option["values"]]
                  for option in choices
              ]
          )
          if choices
          else []
          for primary, choices in mapping.items()
      }
  
      # Generate configs
      configs = []
      for primary, combinations in all_combinations.items():
          if not combinations:
              configs.append({primary_key: primary})
          for item in combinations:
              primary_config = {primary_key: primary}
              for key, value in item:
                  if isinstance(key, (list, tuple)):
                      primary_config.update(
                          {
                              process_key(primary, k): v
                              for k, v in zip(key, value)
                          }
                      )
                  else:
                      primary_config[process_key(primary, key)] = value
              configs.append(primary_config)
  
      # Explode repetitions
      result = []
      for config in configs:
          if "__repeat__" in config:
              for _ in range(config["__repeat__"]):
                  result.append(
                      {
                          k: v
                          for k, v in config.items()
                          if k != "__repeat__"
                      }
                  )
          else:
              result.append(config)
  
      return result
  
file_path: gluonts/src/gluonts/nursery/tsbench/src/cli/utils/config.py
imports: import itertools
  from pathlib import Path
  from typing import Any, Callable, Dict, Iterator, List, Literal, TextIO
  import yaml
  from tsbench.config import TrainConfig
label_desc: Use image node_id 3 for calling a global function with example usage: explode_key_values(primary_key, mapping, process_key) and returns: result