Closed orlando-labs closed 2 years ago
Hi, @ankane. As I found out recently, on the latest libtorch/torch.rb version (1.11.0/0.10.0) *_like methods lose the device affinity:
require 'torch-rb'; Torch.ones(5).to('cuda:0').then { |t| [t.device, Torch.zeros_like(t).device] } => ["cuda:0", "cpu"]
Meanwhile, the same version with python works well:
import torch; t = torch.ones(5).cuda(); [t.device, torch.zeros_like(t).device] [device(type='cuda', index=0), device(type='cuda', index=0)]
The only older version of torch.rb I'm able to test is 0.8.3 build on top on libtorch 1.9.0, and it produces the expected result:
require 'torch-rb'; Torch.ones(5).cuda.then { |t| [t.device, Torch.zeros_like(t).device] } => ["cuda:0", "cuda:0"]
Given misbehaviour, e. g., totally breaks optimizers when using GPUs.
Hey @orlando-labs, thanks for reporting! It looks like this was broken for like_* methods in 0.9.1 when they were moved to C++. Fixed in the commit above, and will push a new release shortly.
like_*
Hi, @ankane. As I found out recently, on the latest libtorch/torch.rb version (1.11.0/0.10.0) *_like methods lose the device affinity:
Meanwhile, the same version with python works well:
The only older version of torch.rb I'm able to test is 0.8.3 build on top on libtorch 1.9.0, and it produces the expected result:
Given misbehaviour, e. g., totally breaks optimizers when using GPUs.