class_docstr: Provides base test running methods for testing an adapter method implementation.
class_docstr_tok: ["Provides","base","test","running","methods","for","testing","an","adapter","method","implementation","."]
code: def run_average_test(self, model, adapter_config, filter_keys):
      model.eval()
  
      weights = [0.1, 0.6, 0.3]
  
      # add adapters to average
      name = "test_adapter_" + adapter_config.__class__.__name__
      for i in range(len(weights)):
          model.add_adapter(name + f"_{i}", config=adapter_config)
  
      # collect weighted average of adapter weights
      averaged_weights = {}
      for i, w in enumerate(weights):
          this_filter_keys = [
              k.format(name=name + f"_{i}") for k in filter_keys
          ]
          for k, v in self.filter_parameters(
              model, this_filter_keys
          ).items():
              base_k = k.replace(name + f"_{i}", name)
              if base_k not in averaged_weights:
                  averaged_weights[base_k] = w * v
              else:
                  averaged_weights[base_k] += w * v
  
      # average adapters
      model.average_adapter(
          name,
          [name + f"_{i}" for i in range(len(weights))],
          weights=weights,
      )
  
      # adapter is correctly added to config
      self.assertTrue(name in model.adapters_config)
      self.assertEqual(adapter_config, model.adapters_config.get(name))
  
      # compare averaged weights to collected weights
      this_filter_keys = [k.format(name=name) for k in filter_keys]
      for k, v in self.filter_parameters(
          model, this_filter_keys
      ).items():
          self.assertTrue(torch.allclose(v, averaged_weights[k]), k)
  
imports: import copy
  import os
  import tempfile
  import torch
  import adapters
  from adapters import ADAPTER_MODEL_MAPPING, AdapterSetup, AdapterTrainer, AutoAdapterModel
  from adapters.heads import CausalLMHead
  from adapters.utils import WEIGHTS_NAME
  from adapters.wrappers import load_model
  from transformers import TrainingArguments
  from transformers.testing_utils import require_torch, torch_device
label_desc: Use image node_id 4 for calling the AdapterMethodBaseTestMixin obj's underlying member method code with example usage: obj.run_average_test(model, adapter_config, filter_keys) without return types