code: def generate_matching_config(
      superset: Dict[str, Any], config_class: Any
  ) -> Any:
      """Given a superset of the inputs and a reference config class,
      return exactly the needed config"""
  
      # Extract the required fields
      field_names = list(map(lambda x: x.name, fields(config_class)))
      subset = {k: v for k, v in superset.items() if k in field_names}
  
      # The missing fields get Noned
      for k in field_names:
          if k not in subset.keys():
              subset[k] = None
  
      return config_class(**subset)
  
file_path: xformers/xformers/utils.py
imports: import importlib
  import os
  import sys
  from collections import namedtuple
  from dataclasses import fields
  from typing import Any, Callable, Dict, List
label_desc: Use image node_id 3 for calling a global function with example usage: generate_matching_config(superset, config_class) and returns: config_class