avish
(avish)
July 9, 2021, 1:15pm
4
Given a model (inherited from nn.Module), calculate Jacobian of parameters of this model with respect to output vector.
This looks like a hack to do this,
I’m also working on this issue when calculating the influence function.
My current solution is to follow this workaround:
So I write this sample code (which works as a workaround):
import torch
import torch.nn as nn
_input=torch.randn(32,3)
layer = nn.Linear(3,4)
criterion=nn.CrossEntropyLoss()
weight = layer.weight
def func(weight):
del layer.weight
layer.weight=weight
return criterion(layer(_input), torch.zeros(len(_input),dtype=torch.long))
torch.autograd.functional.hessia…