sorted_alpha_grad, indices = torch.sort(alpha_grad, descending=True)
compression_weight = torch.ones_like(indices)
compression_weight[indices < alpha_grad_attn.numel()] = 36 # 36 = 12 (number of heads) * [1 (weights of query) + 1 (weights of key) + 1 (weights of value)]
threshold = sorted_alpha_grad[torch.argmin(torch.abs(torch.cumsum(compression_weight, 0) - torch.sum(compression_weight)*pi))]
def update(module, grad):
mask = ((grad <= threshold) | (grad <= torch.min(grad)))
module.data.copy_(mask + (~mask)*(1 - pi/p))
这一部分似乎说明,在update过程中是grad比threshold大的部分参数得到了更新,将其趋于0,这里我有些疑问,为何grad比threshold大的部分参数重要性就小以至于能趋于0呢?希望您解答