class_docstr: This class manages the setup and configuration of adapter modules in a pre-trained model.
class_docstr_tok: ["This","class","manages","the","setup","and","configuration","of","adapter","modules","in","a","pre-trained","model","."]
docstr: Tries to match the given criteria to an existing adapter. Return the adapter config if a match is found,
  otherwise None.
docstr_tok: ["Tries","to","match","the","given","criteria","to","an","existing","adapter",".","Return","the","adapter","config","if","a","match","is","found",",","otherwise","None","."]
code: def match(
      self,
      adapter_name: str,
      config_type: type,
      layer_idx: Optional[int] = None,
      location_key: Optional[str] = None,
  ) -> Optional[dict]:
      """
      Tries to match the given criteria to an existing adapter. Return the adapter config if a match is found,
      otherwise None.
      """
      config = self.get(adapter_name)
      if config is None:
          return None
      elif not isinstance(config, AdapterConfig):
          config = AdapterConfig.load(config)
  
      if isinstance(config, config_type):
          leave_out = config.get("leave_out", [])
          if layer_idx is None or layer_idx not in leave_out:
              if location_key is None or config.get(
                  location_key, False
              ):
                  return config
      # if we have a config union, match with all child configs
      elif isinstance(config, ConfigUnion):
          results = []
          for c in config.configs:
              if isinstance(c, config_type):
                  leave_out = c.get("leave_out", [])
                  if layer_idx is None or layer_idx not in leave_out:
                      if location_key is None or c.get(
                          location_key, False
                      ):
                          results.append(c)
          if len(results) == 1:
              return results[0]
          elif len(results) > 1:
              raise ValueError(
                  "Multiple adapter definitions conflict for adapter '{}' in layer {}. "
                  "Please make sure there is only one adaptation block used per location and adapter.".format(
                      adapter_name, layer_idx
                  )
              )
  
      return None
  
imports: import copy
  import logging
  from collections.abc import Collection, Mapping
  from typing import List, Optional, Union
  from ..None import __version__
  from ..composition import AdapterCompositionBlock
  from ..utils import get_adapter_config_hash
  from .adapter_config import ADAPTER_CONFIG_MAP, DEFAULT_ADAPTER_CONFIG, AdapterConfig, ConfigUnion
  from .adapter_fusion_config import ADAPTERFUSION_CONFIG_MAP, DEFAULT_ADAPTERFUSION_CONFIG
label_desc: Use image node_id 6 for calling the ModelAdaptersConfig obj's underlying member method code with example usage: obj.match(adapter_name, config_type, layer_idx, location_key) and returns: None, None, config, results