Error "if input.dim() == 2 and bias is not None"
Author: renjiege
Pull request: no

Pytorch version: pytorch-1.7.1-py3.8_cuda11.0.221_cudnn8.0.5_0
Transformer version: 4.0.0

Code:
```
import torch
import torch.nn as nn
from torch.utils.data import TensorDataset, DataLoader, RandomSampler, SequentialSampler
from transformers import AutoModel, BertTokenizerFast

class BERT_Arch(nn.Module):
    def __init__(self, bert):
        super(BERT_Arch, self).__init__()
        self.bert = bert 
    
        # dropout layer
        self.dropout = nn.Dropout(0.1)
        # relu activation function
        self.relu =  nn.ReLU()
        # dense layer 1
        self.fc1 = nn.Linear(768,512)
      
        # dense layer 2 (Output layer)
        self.fc2 = nn.Linear(512,2)
        #softmax activation function
        self.softmax = nn.LogSoftmax(dim=1)

    #define the forward pass
    def forward(self, sent_id, mask):

        #pass the inputs to the model  
        _, cls_hs = self.bert(sent_id, attention_mask=mask)
        x = self.fc1(cls_hs)
        x = self.relu(x)
        x = self.dropout(x)

        # output layer
        x = self.fc2(x)

        # apply softmax activation
        x = self.softmax(x)
        
        return x


# import BERT-base pretrained model
bert = AutoModel.from_pretrained('bert-base-uncased')
# pass the pre-trained BERT to our define architecture
model = BERT_Arch(bert)
# push the model to GPU
model = model.to(device)

# dataLoader for train set
train_dataloader = DataLoader(train_data, sampler=train_sampler, batch_size=batch_size)

for step,batch in enumerate(train_dataloader):
    batch = [r.to(device) for r in batch]
    sent_id, mask, labels = batch
    preds = model(sent_id, mask)
```

Error:

> ---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-46-3656917b982b> in <module>
      2     batch = [r.to(device) for r in batch]
      3     sent_id, mask, labels = batch
----> 4     preds = model(sent_id, mask)

~/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    725             result = self._slow_forward(*input, **kwargs)
    726         else:
--> 727             result = self.forward(*input, **kwargs)
    728         for hook in itertools.chain(
    729                 _global_forward_hooks.values(),

<ipython-input-43-05830d6f294e> in forward(self, sent_id, mask)
     21         #pass the inputs to the model
     22         _, cls_hs = self.bert(sent_id, attention_mask=mask)
---> 23         x = self.fc1(cls_hs)
     24         x = self.relu(x)
     25         x = self.dropout(x)

~/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    725             result = self._slow_forward(*input, **kwargs)
    726         else:
--> 727             result = self.forward(*input, **kwargs)
    728         for hook in itertools.chain(
    729                 _global_forward_hooks.values(),

~/anaconda3/lib/python3.8/site-packages/torch/nn/modules/linear.py in forward(self, input)
     91 
     92     def forward(self, input: Tensor) -> Tensor:
---> 93         return F.linear(input, self.weight, self.bias)
     94 
     95     def extra_repr(self) -> str:

~/anaconda3/lib/python3.8/site-packages/torch/nn/functional.py in linear(input, weight, bias)
   1686         if any([type(t) is not Tensor for t in tens_ops]) and has_torch_function(tens_ops):
   1687             return handle_torch_function(linear, tens_ops, input, weight, bias=bias)
-> 1688     if input.dim() == 2 and bias is not None:
   1689         # fused op is marginally faster
   1690         ret = torch.addmm(bias, input, weight.t())

AttributeError: 'str' object has no attribute 'dim'



Comments:
Please try
`_, cls_hs = self.bert(sent_id, attention_mask=mask)`
to
`_, cls_hs = self.bert(sent_id, attention_mask=mask)[:2]`
or
`_, cls_hs = self.bert(sent_id, attention_mask=mask, return_dict=False)`

It fixes the issue. Thanks!

> Please try
> `_, cls_hs = self.bert(sent_id, attention_mask=mask)`
> to
> `_, cls_hs = self.bert(sent_id, attention_mask=mask)[:2]`
> or
> `_, cls_hs = self.bert(sent_id, attention_mask=mask, return_dict=False)`

You the man! I also got stuck in this issue for an hour, and your solution just fixes it perfectly! 
Thanks man!