ankane / torch.rb

Deep learning for Ruby, powered by LibTorch
Other
704 stars 30 forks source link

cannot load such file -- [...]/torch-rb-0.13.1/lib/torch/ext #41

Closed RuhmUndAnsehen closed 1 year ago

RuhmUndAnsehen commented 1 year ago

Trying to require 'torch', I'm getting the following error:

/home/.../.gem/ruby/gems/torch-rb-0.13.1/lib/torch.rb:2:in `require_relative': cannot load such file -- /home/.../.gem/ruby/gems/torch-rb-0.13.1/lib/torch/ext (LoadError)                                                         
        from /home/.../.gem/ruby/gems/torch-rb-0.13.1/lib/torch.rb:2:in `<top (required)>'
        from <internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:159:in `require'
        from <internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:159:in `rescue in require'
        from <internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:39:in `require'
        from (irb):1:in `<main>'                                                 
        from /usr/share/gems/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'     
        from /usr/bin/irb:25:in `load'                                           
        from /usr/bin/irb:25:in `<main>'

Environment:

The source of the error is commit https://github.com/ankane/torch.rb/commit/4202447cc23c2770355b13de0c3d9858cad915ca, which modified the import of native extentions in lib/torch.rb#2.

Here's the directory structure of a 0.12.0 install that worked in Ruby 3.1, vs. the directory structure of 0.13.1 in my current environment. The point I'm trying to make with this is that there is no file torch/ext in both instances, which require_relative seems to target. Instead, ext lives in the gem's root directory.

[... torch-rb-0.12.0]$ ls
CHANGELOG.md  codegen  ext  lib  LICENSE.txt  README.md
[... torch-rb-0.12.0]$ ls lib
torch  torch.rb  torch-rb.rb
[... torch-rb-0.12.0]$ ls lib/torch
hub.rb  inspector.rb  nn  optim  tensor.rb  utils  version.rb
[... torch-rb-0.13.1]$ ls
CHANGELOG.md  codegen  ext  lib  LICENSE.txt  README.md
[... torch-rb-0.13.1]$ ls lib
torch  torch.rb  torch-rb.rb
[... torch-rb-0.13.1]$ ls lib/torch
hub.rb  inspector.rb  nn  optim  tensor.rb  utils  version.rb

I can make this error go away by changing the aforementioned require_relative back to require.

ankane commented 1 year ago

Hi @RuhmUndAnsehen, I'm not sure how to reproduce. The shared library should be located at lib/torch/ext.so on Linux, and require_relative shouldn't make a difference.

RuhmUndAnsehen commented 1 year ago

Apparently, on my system the extensions are located separately in /home/.../.gem/ruby/extensions/x86_64-linux/3.2.0/torch-rb-0.13.1/torch.

This is all with default configurations and a pristine install. When I change the import in the already installed gem as mentioned in the OP, it works.

ankane commented 1 year ago

Thanks, can confirm extensions are placed in a separate directory with the system Ruby. Pushed a fix in the commit above. Thanks for reporting!