class_docstr: A class providing helper methods for saving and loading module weights.
class_docstr_tok: ["A","class","providing","helper","methods","for","saving","and","loading","module","weights","."]
code: def load_weights_from_state_dict(
      self,
      state_dict,
      filter_func,
      rename_func=None,
      loading_info=None,
      in_base_model=False,
      start_prefix="",
  ):
      # Rename weights if needed
      if rename_func:
          if isinstance(rename_func, Sequence):
              state_dict = self.rename_state_dict(
                  state_dict, *rename_func
              )
          else:
              state_dict = self.rename_state_dict(
                  state_dict, rename_func
              )
  
      # Add the weights to the model
      # Make sure we are able to load base models as well as derived models (with heads)
      model_to_load = self.model
      has_prefix_module = any(
          s.startswith(self.model.base_model_prefix)
          for s in state_dict.keys()
      )
      if (
          not start_prefix
          and not hasattr(self.model, self.model.base_model_prefix)
          and has_prefix_module
      ):
          start_prefix = self.model.base_model_prefix + "."
      if (
          in_base_model
          and hasattr(self.model, self.model.base_model_prefix)
          and not has_prefix_module
      ):
          model_to_load = self.model.base_model
  
      missing_keys, unexpected_keys = self._load_module_state_dict(
          model_to_load, state_dict, start_prefix=start_prefix
      )
  
      missing_keys = [k for k in missing_keys if filter_func(k)]
      if len(missing_keys) > 0:
          logger.info(
              "Some module weights could not be found in loaded weights file: {}".format(
                  ", ".join(missing_keys)
              )
          )
      if self.model._keys_to_ignore_on_load_unexpected:
          unexpected_keys = [
              k
              for k in unexpected_keys
              if k not in self.model._keys_to_ignore_on_load_unexpected
          ]
      if len(unexpected_keys) > 0:
          logger.info(
              "Some weights of the state_dict could not be loaded into model: {}".format(
                  ", ".join(unexpected_keys)
              )
          )
  
      if isinstance(loading_info, dict):
          if "missing_keys" not in loading_info:
              loading_info["missing_keys"] = []
          if "unexpected_keys" not in loading_info:
              loading_info["unexpected_keys"] = []
          loading_info["missing_keys"].extend(missing_keys)
          loading_info["unexpected_keys"].extend(unexpected_keys)
  
      return missing_keys, unexpected_keys
  
imports: import json
  import logging
  from abc import ABC, abstractmethod
  from os import mkdir
  from os.path import exists, isdir, isfile, join
  from typing import Callable, Mapping, Sequence, Tuple
  import torch
  from .configuration import AdapterConfig, build_full_config
  from .head_utils import STATIC_TO_FLEX_HEAD_MAP, get_head_config_and_rename_list
  from .utils import ACTIVATION_RENAME, ADAPTERFUSION_CONFIG_NAME, ADAPTERFUSION_WEIGHTS_NAME, CONFIG_NAME, HEAD_CONFIG_NAME, HEAD_WEIGHTS_NAME, WEIGHTS_NAME, AdapterType, resolve_adapter_path
label_desc: Use image node_id 9 for calling the WeightsLoaderHelper obj's underlying member method code with example usage: obj.load_weights_from_state_dict(state_dict, filter_func, rename_func, loading_info, in_base_model, start_prefix) and returns: missing_keys,  unexpected_keys