class_docstr: Multi-headed attention.
  
  See "Attention Is All You Need" for more details.
class_docstr_tok: ["Multi-headed","attention",".","See","``","Attention","Is","All","You","Need","''","for","more","details","."]
code: def upgrade_state_dict_named(self, state_dict, name):
      prefix = name + "." if name != "" else ""
      items_to_add = {}
      keys_to_remove = []
      for k in state_dict.keys():
          if k.endswith(prefix + "in_proj_weight"):
              # in_proj_weight used to be q + k + v with same dimensions
              dim = int(state_dict[k].shape[0] / 3)
              items_to_add[prefix + "q_proj.weight"] = state_dict[k][
                  :dim
              ]
              items_to_add[prefix + "k_proj.weight"] = state_dict[k][
                  dim : 2 * dim
              ]
              items_to_add[prefix + "v_proj.weight"] = state_dict[k][
                  2 * dim :
              ]
  
              keys_to_remove.append(k)
  
              k_bias = prefix + "in_proj_bias"
              if k_bias in state_dict.keys():
                  dim = int(state_dict[k].shape[0] / 3)
                  items_to_add[prefix + "q_proj.bias"] = state_dict[
                      k_bias
                  ][:dim]
                  items_to_add[prefix + "k_proj.bias"] = state_dict[
                      k_bias
                  ][dim : 2 * dim]
                  items_to_add[prefix + "v_proj.bias"] = state_dict[
                      k_bias
                  ][2 * dim :]
  
                  keys_to_remove.append(prefix + "in_proj_bias")
  
      for k in keys_to_remove:
          del state_dict[k]
  
      for key, value in items_to_add.items():
          state_dict[key] = value
  
imports: import math
  from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn.functional
  from torch import Tensor, nn
  from torch.nn import Parameter
  from fairseq import utils
  from fairseq.modules.fairseq_dropout import FairseqDropout
  from fairseq.modules.quant_noise import quant_noise
  from fairseq.models.fairseq_incremental_decoder import FairseqIncrementalDecoder
label_desc: Use image node_id 18 for calling the MultiheadAttention obj's underlying member method code with example usage: obj.upgrade_state_dict_named(state_dict, name) without return types