class_docstr: Base class to help with generalized loading of pretrained weights.
  
  Subclasses should override `_from_config()` if you want to instantiate them with
  `from_pretrained_module()`.
class_docstr_tok: ["Base","class","to","help","with","generalized","loading","of","pretrained","weights",".","Subclasses","should","override","`","_from_config","(",")","`","if","you","want","to","instantiate","them","with","`","from_pretrained_module","(",")","`","."]
docstr: Get a HuggingFace pretrained `state_dict` corresponding to this module.
docstr_tok: ["Get","a","HuggingFace","pretrained","`","state_dict","`","corresponding","to","this","module","."]
code: def _get_pretrained_state_dict(
      cls,
      model_name: str,
      weights_path: Optional[Union[str, PathLike]] = None,
      relevant_module: Optional[Union[str, List[str]]] = None,
      ignore: Optional[List[str]] = None,
  ) -> StateDictType:
      """
      Get a HuggingFace pretrained `state_dict` corresponding to this module.
      """
      if weights_path is None:
          from transformers.file_utils import WEIGHTS_NAME
  
          # First see if we can find the weights locally.
          if os.path.isdir(model_name):
              local_weights_path = os.path.join(
                  model_name, WEIGHTS_NAME
              )
              if os.path.isfile(local_weights_path):
                  logger.info(
                      "Found weights at local path %s",
                      local_weights_path,
                  )
                  weights_path = local_weights_path
  
          # If we haven't found locally, we assume model ID corresponds to a model
          # on the HuggingFace Hub.
          if weights_path is None:
              from allennlp.common.file_utils import cached_path
  
              weights_path = cached_path(
                  f"hf://{model_name}/{WEIGHTS_NAME}"
              )
  
      # Now load the state dict.
      logger.info("Reading state dict from %s", weights_path)
      state_dict = read_state_dict(
          weights_path,
          ignore=ignore
          if ignore is not None
          else cls._pretrained_ignore,
          strict=False,
      )
  
      # Keep just the relevant_module, remove everything else.
      state_dict = cls._get_relevant_submodule_state(
          state_dict, relevant_module=relevant_module
      )
  
      return state_dict
  
imports: import logging
  import os
  from os import PathLike
  from typing import TYPE_CHECKING, Optional, Dict, Union, List, Any, TypeVar, Type
  import re
  import warnings
  import torch
  import torch.distributed
  from allennlp.common.util import is_distributed, is_global_primary
  from allennlp.nn.parallel import ShardedModuleMixin
  from allennlp.nn.module import Module
  from allennlp.nn.util import StateDictType, read_state_dict, _check_incompatible_keys
label_desc: Use image node_id 4 for calling the TransformerModule obj's underlying member method code with example usage: obj._get_pretrained_state_dict(cls, model_name, weights_path, relevant_module, ignore) and returns: state_dict