torch.nn.modules.module.ModuleAttributeError: 'RecursiveScriptModule' object has no attribute 'resize_token_embeddings'
## Environment info

- `transformers` version: 2.0.0 (tried with 4.1.1 as well)
- Python version: 3.6.9
- PyTorch version (GPU?): 1.7(False)
- Tensorflow version (GPU?): 1.14.0(False)
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

@LysandreJik @mfuntowicz

## Information
Model I am using: GPT2

The tasks I am working on is:
* Question generation given a paragraph, clue, style, and answer

The problem arises when using:
* Torchscript version of fine-tuned GPT2. I have an inference script in which I load the pre-trained tokenizer and add special tokens to it. I resize the token embeddings using the model.resize_token_embeddings() function after adding the special tokens. It works fine for the original PyTorch GPT2 model but fails for the traced(Torchscript) model. The code snippet is as follows:

    tokenizer = GPT2Tokenizer.from_pretrained(args.model_name_or_path)
    if args.model_name != "":
        model = GPT2LMHeadModel.from_pretrained(args.model_name)
    else:
        if args.torchscript:
            model = torch.jit.load(args.ts_model_name_or_path)
        else:
            model = GPT2LMHeadModel.from_pretrained(args.model_name_or_path)
    tokenizer.add_tokens(SPECIAL_TOKENS)
    model.resize_token_embeddings(len(tokenizer))

Following is the error stack trace:

Traceback (most recent call last):
  File "QG_gpt2_generate.py", line 5, in <module>
    run()
  File "/content/drive/MyDrive/home/FQG/src/model/FactorizedQG/GPT2_QG/interact.py", line 231, in run
    model.resize_token_embeddings(len(tokenizer))
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/_script.py", line 558, in __getattr__
    return super(RecursiveScriptModule, self).__getattr__(attr)
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/_script.py", line 288, in __getattr__
    return super(ScriptModule, self).__getattr__(attr)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 779, in __getattr__
    type(self).__name__, name))
torch.nn.modules.module.ModuleAttributeError: 'RecursiveScriptModule' object has no attribute 'resize_token_embeddings'

Is there any other way in which I can perform the same operation of resizing for torchscript models? 
Thanks
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.<|||||>Hi @Mounika2405. Were you able to find a solution for this issue? I am facing a similar issue with another torch_script model<|||||>Facing the same issue. 