Created
May 27, 2016 16:23
-
-
Save bartvm/0c89afae109f3e08958f5914c6148118 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grad = require 'autograd' | |
torch = require 'torch' | |
params={ | |
W=torch.range(0, 8):view(3, 3), | |
storage=torch.zeros(3, 3) | |
} | |
function f(params, x) | |
params.storage[2] = params.W * x | |
return torch.mean(params.storage) | |
end | |
grad, _ = grad(f)(params, torch.ones(3)) | |
print(grad.W) | |
print(grad.storage) | |
--[[ | |
This gives a zero gradient to W, which is incorrect. | |
0 0 0 | |
0 0 0 | |
0 0 0 | |
[torch.DoubleTensor of size 3x3] | |
0.1111 0.1111 0.1111 | |
0.0000 0.0000 0.0000 | |
0.1111 0.1111 0.1111 | |
[torch.DoubleTensor of size 3x3] | |
--]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment