diff options
author | David Seetapun <dseetapun@netflix.com> | 2016-04-12 21:32:15 +0300 |
---|---|---|
committer | David Seetapun <dseetapun@netflix.com> | 2016-04-12 21:32:15 +0300 |
commit | 477a5e7a60914bf14412b78cbbaa572418098d81 (patch) | |
tree | 7b6487b5dd7b95b94cbc641577fa67741339ef35 /nag.lua | |
parent | 5e11b9fc448f3612c93429dbd125c8aa0862d3d5 (diff) |
remove copy of x to save memory
Diffstat (limited to 'nag.lua')
-rw-r--r-- | nag.lua | 10 |
1 files changed, 3 insertions, 7 deletions
@@ -42,11 +42,7 @@ function optim.nag(opfunc, x, config, state) -- (1) evaluate f(x) and df/dx -- first step in the direction of the momentum vector - if not state.x_copy then - state.x_copy = x:clone() - else - state.x_copy:resizeAs(x):copy(x) - end + if state.dfdx then x:add(mom, state.dfdx) end @@ -75,12 +71,12 @@ function optim.nag(opfunc, x, config, state) state.deltaParameters = torch.Tensor():typeAs(x):resizeAs(dfdx) end state.deltaParameters:copy(lrs):cmul(dfdx) + x:add(-clr, state.deltaParameters) state.dfdx:add(-clr, state.deltaParameters) else + x:add(-clr, dfdx) state.dfdx:add(-clr, dfdx) end - state.x_copy:add(state.dfdx) - x:copy(state.x_copy) -- (6) update evaluation counter state.evalCounter = state.evalCounter + 1 |