dmlc / dmlc/MXNet.jl

Call to mx.get_updater(optimizer) gives UndefRefError

Open
#155 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
369
Forks
63
PR merge metrics
No merged PRs in 30d

Description

I am trying to adapt cnn_text_classification example from python, https://github.com/dmlc/mxnet/tree/master/example/cnn_text_classification, to julia. I have error for the following part:

```julia
optimizer = mx.SGD(lr=0.1, momentum=0.9, weight_decay=0.00001)
updater = mx.get_updater(optimizer)
for batch in mx.eachbatch(train_provider)
data = mx.get_data(train_provider, batch)
label = mx.get_label(train_provider, batch)

num_correct = 0
num_total = 0

m.data[:] = data[1]
m.label[:] = label[1]

# forward backward
mx.forward(m.cnn_exec, is_train=true)
mx.backward(m.cnn_exec)

# eval on training data
a = copy(m.cnn_exec.outputs[1])
num_correct += sum(label .== mapslices(indmax, a, 1)[:])
num_total += length(label)

# update weights
sum_norm = 0
for (idx, weight, grad, name) in m.param_blocks
grad /= N
l2_norm = copy(norm(grad))[1]
sum_norm += l2_norm * l2_norm
end

MAX_GRAD_NORM = 5.0
sum_norm = sqrt(sum_norm)
for (idx, weight, grad, name) in m.param_blocks
if sum_norm > MAX_GRAD_NORM
grad *= (MAX_GRAD_NORM / sum_norm)
end

println("idx ", idx)
println("grad ", grad)
println("weight ", weight)
updater(idx, grad, weight) # <-- this line gives error

# reset gradient to zero
grad[:] = 0.0
end

train_acc = num_correct * 100.0 / num_total
println("train_acc ", train_acc)
end
```

```
idx 1
grad mx.NDArray{Float32}(784,100)
weight mx.NDArray{Float32}(784,100)
ERROR: LoadError: UndefRefError: access to undefined reference
in update(::MXNet.mx.SGD, ::Int64, ::MXNet.mx.NDArray, ::MXNet.mx.NDArray, ::MXNet.mx.NDArray) at /home/phuoc/.julia/v0.5/MXNet/src/optimizers/sgd.jl:53
in (::MXNet.mx.#updater#903{MXNet.mx.SGD,Dict{Int64,Any}})(::Int64, ::MXNet.mx.NDArray, ::MXNet.mx.NDArray) at /home/phuoc/.julia/v0.5/MXNet/src/optimizer.jl:188
in train() at cnn.jl:126
in include_from_node1(::String) at ./loading.jl:488
while loading cnn.jl, in expression starting on line 167
```

Is the error from MXNet.jl or mxnet core library? I can run the cnn_text_classification python version normally.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.