let torch = get_module(py, &TORCH_MODULE)?;
let dtype: PyObject = get_pydtype(torch, info.dtype, false)?;
let torch_uint8: PyObject = get_pydtype(torch, Dtype::U8, false)?;
- let kwargs = [(intern!(py, "dtype"), torch_uint8)].into_py_dict(py)?;
+ let device: PyObject = self.device.clone().into_pyobject(py)?.into();
+ let kwargs = [
+ (intern!(py, "dtype"), torch_uint8),
+ (intern!(py, "device"), device),
+ ]
+ .into_py_dict(py)?;
let view_kwargs = [(intern!(py, "dtype"), dtype)].into_py_dict(py)?;
let shape = info.shape.to_vec();
let shape: PyObject = shape.into_pyobject(py)?.into();
}
tensor = tensor.getattr(intern!(py, "reshape"))?.call1((shape,))?;
- if self.device != Device::Cpu {
- let device: PyObject = self.device.clone().into_pyobject(py)?.into();
- let kwargs = PyDict::new(py);
- tensor = tensor.call_method("to", (device,), Some(&kwargs))?;
- }
Ok(tensor.into_pyobject(py)?.into())
- // torch.asarray(storage[start + n : stop + n], dtype=torch.uint8).view(dtype=dtype).reshape(shape)
})
}
}
def test_hpu(self):
# must be run to load torch with Intel Gaudi bindings
try:
- import habana_frameworks.torch.core as htcore
+ import habana_frameworks.torch.core as htcore # noqa: F401
except ImportError:
self.skipTest("HPU is not available")
self.assertTrue(torch.allclose(v, tv))
self.assertEqual(v.device, torch.device("cpu"))
+ @unittest.skipIf(not torch.cuda.is_available(), "Cuda is not available")
+ def test_deserialization_device(self):
+ with torch.device("cuda:0"):
+ weights = load_file(self.sf_filename)
+ self.assertEqual(weights["test"].device, torch.device("cpu"))
+
+ torch.set_default_device(torch.device("cuda:0"))
+ weights = load_file(self.sf_filename)
+ self.assertEqual(weights["test"].device, torch.device("cpu"))
+
@unittest.skipIf(not torch.cuda.is_available(), "Cuda is not available")
def test_deserialization_safe_gpu(self):
# First time to hit disk