twitter-archive / torch-autograd

Autograd automatically differentiates native Torch code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"failed to parse generated code."

tuananhle7 opened this issue · comments

Running the following:

grad = require 'autograd'
params = {
    [":a1"] = 1,
    [":a2"] = 2
}
f = function(params, x)
    val = x["value"]
    w = params[x["address"].raw]
    return w * val
end
df = grad(f, {optimize = true})
x = {value = 47, address = ":a1"}
dparam, loss = df(params, x)

produces

return function(locals, rlocals, vlocals)
local nn = require('autograd').nn
local util = require('autograd.util')
return function(p1, p2)
    locals[1] = p2.value * 1
    locals[2] = p1.:a1 * p2.value
    return {
        :a1 = locals[1],
    }, locals[2]
end
end

[string "return function(locals, rlocals, vlocals)..."]:6: '<name>' expected near ':'
/Users/username/torch/install/bin/luajit: ...re/lua/5.1/autograd/runtime/codegen/backend/lua/init.lua:757: failed to parse generated code.
stack traceback:
    [C]: in function 'error'
    ...re/lua/5.1/autograd/runtime/codegen/backend/lua/init.lua:757: in function 'generateFn'
    .../install/share/lua/5.1/autograd/runtime/codegen/init.lua:140: in function 'df'
    test2.lua:25: in main chunk
    [C]: in function 'dofile'
    ...nhle/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
    [C]: at 0x010c506bc0

while running

grad = require 'autograd'
params = {
    ["a1"] = 1,
    ["a2"] = 2
}
f = function(params, x)
    val = x["value"]
    w = params[x["address"].raw]
    return w * val
end
df = grad(f, {optimize = true})
x = {value = 47, address = "a1"}
dparam, loss = df(params, x)

doesn't.

In the first case, keys of params are strings that start with a colon while in the second they don't.

Hrm, seems like we should be doing table lookups using brackets, and not dot, syntax.