I want understand BertForMaskedLM model, in huggingface github code, BertForMaskedLM is bert model with additional 2 linear layers with shape (input 768, output 768) and (input 768, output 30522). Count of all weights will be weights of BertModel + 768 * 768 + 768 * 30522, but when I check the numbers don't match.
from transformers import BertModel, BertForMaskedLM
import torch
bertmodel = BertModel.from_pretrained('bert-base-uncased')
bertForMaskedLM = BertForMaskedLM.from_pretrained('bert-base-uncased')
def count_parameters(model):
return sum(p.numel() for p in model.parameters() if p.requires_grad)
count_parameters(bertmodel)
#output 109482240
count_parameters(bertForMaskedLM)
#output 109514298
109482240 + 768 * 768 + 768 * 30522 != 109514298
what am I doing wrong?

