Closed nerdinand closed 4 years ago
I just experimented a bit and it turns out that this code here fails too:
require 'torch'
module DQN
class Model < Torch::NN::Module
def initialize
@fc = Torch::NN::Linear.new(4, 128)
end
end
end
m1 = DQN::Model.new
m2 = DQN::Model.new
m1.load_state_dict(m2.state_dict)
Error is:
Traceback (most recent call last):
3: from model.rb:14:in `<main>'
2: from /Users/ferdi/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/torch-rb-0.3.0/lib/torch/nn/module.rb:110:in `state_dict'
1: from /Users/ferdi/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/torch-rb-0.3.0/lib/torch/nn/module.rb:147:in `named_parameters'
/Users/ferdi/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/torch-rb-0.3.0/lib/torch/nn/module.rb:179:in `named_children': undefined method `each' for nil:NilClass (NoMethodError)
Hey @nerdinand, thanks for reporting! It should be fixed on master.
Hi!
First of all, thanks so much for your work. I think it's fantastic to be able to use torch with Ruby!
I have a problem that might stem from me holding torch.rb wrong. But here's what I'm doing:
Essentially want to copy over the parameters of one
Torch::NN::Module
to another (of the same structure). I'm doing this in order to reimplement https://pythonprogramming.net/training-deep-q-learning-dqn-reinforcement-learning-python-tutorial/?completed=/deep-q-learning-dqn-reinforcement-learning-python-tutorial/ in Ruby and with Torch. There's this line in the source code (using Tensorflow/Keras):So that's what I want to achieve.
Now I'm getting this error when doing that:
It's particularly weird, because when I try the same thing in IRB, no exception is thrown.
Can you tell me if this is a bug or if I should be doing this an entirely different way anyway?
Thanks again for your great work!