class_docstr: A class providing methods for saving and loading prediction head modules from the file system.
  
  Model classes supporting configurable head modules via config files should provide a prediction head dict at
  `model.heads` and a method `add_prediction_head(head_name, config)`.
class_docstr_tok: ["A","class","providing","methods","for","saving","and","loading","prediction","head","modules","from","the","file","system",".","Model","classes","supporting","configurable","head","modules","via","config","files","should","provide","a","prediction","head","dict","at","`","model.heads","`","and","a","method","`","add_prediction_head","(","head_name",",","config",")","`","."]
docstr: Loads a prediction head module from the given state dict, which contains a static head checkpoint.
  
  Args:
      state_dict (dict): The static head checkpoint from which to load the head module. Can be None.
      load_as (str, optional): Load the weights with this name. Defaults to None.
  
  Returns:
      Tuple[dict, dict]: A tuple consisting of the head config and the state dict of the loaded weights.
code: def convert_static_to_flex_head(self, state_dict, load_as="default"):
      """
      Loads a prediction head module from the given state dict, which contains a static head checkpoint.
  
      Args:
          state_dict (dict): The static head checkpoint from which to load the head module. Can be None.
          load_as (str, optional): Load the weights with this name. Defaults to None.
  
      Returns:
          Tuple[dict, dict]: A tuple consisting of the head config and the state dict of the loaded weights.
      """
      assert (
          self.convert_to_flex_head
      ), "load_from_state_dict() can only be used with convert_to_flex_head=True."
      assert hasattr(
          self.model, "heads"
      ), "load_from_state_dict() can only be used with flex heads model class."
  
      conversion_rename_func = None
  
      original_model_class = (
          self.model.config.architectures[0]
          if self.model.config.architectures
          else None
      )
      if original_model_class in STATIC_TO_FLEX_HEAD_MAP:
          (
              head_config,
              conversion_rename_func,
          ) = get_head_config_and_rename_list(
              original_model_class,
              load_as,
              getattr(self.model.config, "label2id"),
          )
      elif self.error_on_missing:
          raise ValueError(
              f"Cannot automatically convert prediction head of model class {original_model_class} to flex head."
          )
      else:
          return None, None
  
      # Load head weights
      if state_dict is not None:
          new_state_dict = {}
          for k, v in state_dict.items():
              new_k = conversion_rename_func(k)
              new_state_dict[new_k] = v
      else:
          new_state_dict = None
      return head_config, new_state_dict
  
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 6 for calling the PredictionHeadLoader obj's underlying member method code with example usage: obj.convert_static_to_flex_head(state_dict, load_as) and returns: head_config,  new_state_dict, None,  None