It may seem weird, but I’m trying to modify the backpropagation itself. (It’s hard to explain in short, but it’s about the adversarial attack.)
I want to modify the saved values of the graph that used in backpropagation. I want something like :
x = Variable(torch.ones(5,3,32,32))
conv = nn.Conv2d(3,24,kernel_size=3, padding=1)
y = F.conv2d(x, conv.weight)
loss = y.sum()
loss.backward()
print(conv.weight.grad[0,0,0]) # tensor([4500., 4500., 4500.])
x = Variable(torch.ones(5,3,32,32))
conv = nn.Conv2d(3,24,kernel_size=3, padding=1)
y = F.conv2d(x, conv.weight)
loss = y.sum()
x.data = 2*x.data
loss.backward()
print(conv.weight.grad[0,0,0]) # It gives ([4500., 4500., 4500.]), but I want ([9000., 9000., 9000.])
It’s not x, also not inside the nn.Conv2d, and F.conv2d looks like a function and looks like have no place for saving something. Where should I found it?
Any help would be greatly appreciated. Thank you.