Repository: pytorch
Issue: 'LSTM' object has no attribute '_flat_weights_names'
Labels: module: rnn,triaged

## 🐛 Bug
This bug occurs when using inltk with python3.9 on debian machine.

## To Reproduce

Steps to reproduce the behavior:

1. pip install torch
2. pip install inltk
3. from inltk.inltk import get_similar_sentences
4. output = get_similar_sentences('मैं आज बहुत खुश हूं', 5, 'hi')

Following is the error trace
```
Traceback (most recent call last):                                                                      
  File "<stdin>", line 1, in <module>
  File "/home/sumit/.local/lib/python3.9/site-packages/inltk/inltk.py", line 137, in get_similar_sentences
    embedding_vectors = get_embedding_vectors(sen, language_code)
  File "/home/sumit/.local/lib/python3.9/site-packages/inltk/inltk.py", line 100, in get_embedding_vectors
    learn = load_learner(path / 'models' / f'{language_code}')
  File "/home/sumit/.local/lib/python3.9/site-packages/fastai/basic_train.py", line 626, in load_learner
    res = clas_func(data, model, **state)
  File "/home/sumit/.local/lib/python3.9/site-packages/fastai/text/learner.py", line 52, in __init__
    super().__init__(data, model, metrics=metrics, **learn_kwargs)
  File "<string>", line 20, in __init__
  File "/home/sumit/.local/lib/python3.9/site-packages/fastai/basic_train.py", line 166, in __post_init__
    self.model = self.model.to(self.data.device)
  File "/home/sumit/.local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 852, in to
    return self._apply(convert)
  File "/home/sumit/.local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 530, in _apply
    module._apply(fn)
  File "/home/sumit/.local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 530, in _apply
    module._apply(fn)
  File "/home/sumit/.local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 530, in _apply
    module._apply(fn)
  [Previous line repeated 1 more time]
  File "/home/sumit/.local/lib/python3.9/site-packages/torch/nn/modules/rnn.py", line 187, in _apply
    self._flat_weights = [(lambda wn: getattr(self, wn) if hasattr(self, wn) else None)(wn) for wn in self._flat_weights_names]
  File "/home/sumit/.local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1130, in __getattr__
    raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'LSTM' object has no attribute '_flat_weights_names'

'LSTM' object has no attribute '_flat_weights_names'
```

## Expected behavior
https://ibb.co/qM2Vw7t

## Environment

PyTorch version: 1.9.0+cu102
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Parrot OS 4.11 (x86_64)
GCC version: (Debian 10.2.1-6) 10.2.1 20210110
Clang version: 11.0.1-2
CMake version: version 3.18.4
Libc version: glibc-2.31

Python version: 3.9.2 (default, Feb 28 2021, 17:03:44)  [GCC 10.2.1 20210110] (64-bit runtime)
Python platform: Linux-5.10.0-8parrot1-amd64-x86_64-with-glibc2.31
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.19.5
[pip3] numpydoc==1.1.0
[pip3] torch==1.9.0
[pip3] torchvision==0.10.0
[conda] Could not collect


## Additional context

<!-- Add any other context about the problem here. -->


cc @zou3519