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
  import uuid
  from typing import Dict, Optional, List
  import torch
  from torch import Tensor, nn
  from torch.nn import Parameter, LayerNorm, Dropout
  from lightseq.training.ops.pytorch import util
  from lightseq.training.ops.pytorch.layer_base import TransformerEmbeddingLayerBase, TransformerEncoderLayerBase, TransformerDecoderLayerBase
  from .quantization import QuantLinear, TensorQuantizer, act_quant_config, weight_quant_config, out_quant_config, emb_quant_config
label_desc: Use image node_id 11 for calling the MultiheadAttention obj's underlying member method code with example usage: obj.upgrade_state_dict_named(state_dict, name) without return types