pytorch中输出模型参数名和梯度的一些操作

1. 输出参数名字的一些操作

输出需要梯度的参数的名字

1
2
3
for n,p in self.lm_head.named_parameters():
if p.requires_grad == True:
print(n)