huawei-noah / Pretrained-Language-Model

Pretrained language model and its related optimization techniques developed by Huawei Noah's Ark Lab.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get obtain the size (MB) of the BERT (TernaryBERT and BinaryBERT)

xwuShirley opened this issue · comments

Dear Authors of TernaryBERT and BinaryBERT,

Thanks for the great work. I have tried my best to figure out the number you put in the table here
image

The BERT-base model (fp32) is
embedding_param = 23835648
num_param = 85526016 (here I only get the matrices)
(embedding_param + num_param) / 1e6 * 4 =437.4MB instead of 418MB?

for n, p in model.items():
    if 'Norm' in n:
        continue
    if len(p.size()) ==2 :
        if 'embedding' in n:
            embedding_param += p.numel()
        else:
            num_param += p.numel()

It would be great if you can clarify this. Similar repo htqin/BiBERT#3 (comment)

found the error should be (embedding_param + num_param) / (1024*1024) * 4 =437.4MB