songyouwei / ABSA-PyTorch

Aspect Based Sentiment Analysis, PyTorch Implementations. 基于方面的情感分析,使用PyTorch实现。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BERT预训练模型大小

moka1994 opened this issue · comments

您好,请问如果想知道BERT的预训练模型的大小,应该怎样查看呢?

n_trainable_params, n_nontrainable_params = 0, 0
for p in model.parameters():
    n_params = torch.prod(torch.tensor(p.shape))
    if p.requires_grad:
        n_trainable_params += n_params
    else:
        n_nontrainable_params += n_params
print('n_trainable_params: {0}, n_nontrainable_params: {1}'.format(n_trainable_params, n_nontrainable_params))

您好,谢谢回信。依照您回复的代码已经解决了我的问题,十分感谢。