class_docstr: TransformerGeneratorAgent.
  
  Implementation of TorchGeneratorAgent, where the model is a Transformer
class_docstr_tok: ["TransformerGeneratorAgent",".","Implementation","of","TorchGeneratorAgent",",","where","the","model","is","a","Transformer"]
docstr: Resize the token embeddings when are adding extra special tokens.
docstr_tok: ["Resize","the","token","embeddings","when","are","adding","extra","special","tokens","."]
code: def _resize_token_embeddings(self, state_dict, msg=None):
      """
      Resize the token embeddings when are adding extra special tokens.
      """
      # map extra special tokens carefully
      new_size = self.model.embeddings.weight.size()[0]
      orig_size = state_dict["embeddings.weight"].size()[0]
      logging.info(
          f"Resizing token embeddings from {orig_size} to {new_size}"
      )
      if new_size <= orig_size:
          # new size should be greater than original size,
          # as we are adding special tokens
          raise RuntimeError(msg)
  
      for emb_weights in [
          "embeddings.weight",
          "encoder.embeddings.weight",
          "decoder.embeddings.weight",
      ]:
          # get new_embs
          old_embs = state_dict[emb_weights]
          new_embs = recursive_getattr(self.model, emb_weights).to(
              old_embs.device
          )
          # copy over old weights
          new_embs.data[:orig_size, :] = old_embs.data[:orig_size, :]
          # reset in state dict
          state_dict[emb_weights] = new_embs
  
      return state_dict
  
imports: from typing import Optional
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  from parlai.core.agents import Agent
  from parlai.utils.torch import padded_3d
  from parlai.core.torch_classifier_agent import TorchClassifierAgent
  from parlai.core.torch_ranker_agent import TorchRankerAgent
  from parlai.core.torch_generator_agent import TorchGeneratorAgent
  from parlai.utils.misc import recursive_getattr, warn_once
  from parlai.utils.logging import logging
  from parlai.utils.fsdp import should_use_fsdp
  from .modules import TransformerMemNetModel, TransformerGeneratorModel, TransformerLinearWrapper
  import torch
label_desc: Use image node_id 3 for calling the TransformerGeneratorAgent obj's underlying member method code with example usage: obj._resize_token_embeddings(state_dict, msg) and returns: state_dict