I have transformers 3.5.1 and ‘1.7.1’. I am getting the same error.
Here is my code:
class SentimentClassifier(nn.Module):
    def __init__(self, n_classes):
        super(SentimentClassifier, self).__init__()
        self.bert = DistilBertModel.from_pretrained("distilbert-base-uncased",cache_dir=cache_path
                                                    ,output_hidden_states=True, return_dict=False)
        self.drop = nn.Dropout(p=0.3)
        self.out = nn.Linear(self.bert.config.hidden_size, n_classes)
    def forward(self, input_ids, attention_mask):
        _, pooled_output = self.bert(input_ids=input_ids,attention_mask=attention_mask, return_dict=False)
        output = self.drop(pooled_output)
        return self.out(output)