code: def load_encoder_from_transformers_weights(
      encoder: nn.Module, weights_dict: dict, return_remainder=False
  ):
      """Find encoder weights in weights dict, load them into encoder, return any remaining weights.
  
      TODO: clarify how we know the encoder weights will be prefixed by transformer name.
  
      Args:
          encoder (PreTrainedModel): Transformer w/o heads (embedding layer + self-attention layer).
          weights_dict (Dict): model weights.
          return_remainder (bool): If True, return any leftover weights.
  
      Returns:
          Dict containing any leftover weights.
  
      """
      remainder_weights_dict = {}
      load_weights_dict = {}
      model_arch = ModelArchitectures.from_model_type(
          model_type=encoder.config.model_type
      )
      encoder_prefix = model_arch.get_encoder_prefix() + "."
      # Encoder
      for k, v in weights_dict.items():
          if k.startswith(encoder_prefix):
              load_weights_dict[
                  strings.remove_prefix(k, encoder_prefix)
              ] = v
          elif k.startswith(encoder_prefix.split("-")[0]):
              # workaround for deberta-v2
              # remove "-v2" suffix. weight names are prefixed with "deberta" and not "deberta-v2"
              load_weights_dict[
                  strings.remove_prefix(
                      k, encoder_prefix.split("-")[0] + "."
                  )
              ] = v
          else:
              remainder_weights_dict[k] = v
      encoder.load_state_dict(load_weights_dict, strict=False)
      if remainder_weights_dict:
          warnings.warn(
              "The following weights were not loaded: {}".format(
                  remainder_weights_dict.keys()
              )
          )
      if return_remainder:
          return remainder_weights_dict
  
imports: from dataclasses import dataclass
  from typing import Any
  from typing import Dict
  from typing import List
  import torch
  import torch.nn
  import transformers
  import warnings
  import jiant.proj.main.components.container_setup
  import jiant.proj.main.modeling.primary
  import jiant.utils.python.strings
  from jiant.proj.main.modeling.heads import JiantHeadFactory
  from jiant.proj.main.modeling.taskmodels import JiantTaskModelFactory, Taskmodel, MLMModel
  from jiant.shared.model_resolution import ModelArchitectures
  from jiant.tasks.core import Task
label_desc: Use image node_id 4 for calling a global function with example usage: load_encoder_from_transformers_weights(encoder, weights_dict, return_remainder) and returns: remainder_weights_dict