Xpu(usize),
Xla(usize),
Mlu(usize),
- /// User didn't specify acceletor, torch
+ Hpu,
+ /// User didn't specify accelerator, torch
/// is responsible for choosing.
Anonymous(usize),
}
"xpu" => Ok(Device::Xpu(0)),
"xla" => Ok(Device::Xla(0)),
"mlu" => Ok(Device::Mlu(0)),
+ "hpu" => Ok(Device::Hpu),
name if name.starts_with("cuda:") => parse_device(name).map(Device::Cuda),
name if name.starts_with("npu:") => parse_device(name).map(Device::Npu),
name if name.starts_with("xpu:") => parse_device(name).map(Device::Xpu),
Device::Xpu(n) => format!("xpu:{n}").into_pyobject(py).map(|x| x.into_any()),
Device::Xla(n) => format!("xla:{n}").into_pyobject(py).map(|x| x.into_any()),
Device::Mlu(n) => format!("mlu:{n}").into_pyobject(py).map(|x| x.into_any()),
+ Device::Hpu => "hpu".into_pyobject(py).map(|x| x.into_any()),
Device::Anonymous(n) => n.into_pyobject(py).map(|x| x.into_any()),
}
}
for k, v in reloaded.items():
self.assertTrue(torch.allclose(data[k], reloaded[k]))
+ def test_hpu(self):
+ # must be run to load torch with Intel Gaudi bindings
+ try:
+ import habana_frameworks.torch.core as htcore
+ except ImportError:
+ self.skipTest("HPU is not available")
+
+ data = {
+ "test1": torch.zeros((2, 2), dtype=torch.float32).to("hpu"),
+ "test2": torch.zeros((2, 2), dtype=torch.float16).to("hpu"),
+ }
+ local = "./tests/data/out_safe_pt_mmap_small_hpu.safetensors"
+ save_file(data, local)
+
+ reloaded = load_file(local, device="hpu")
+ for k, v in reloaded.items():
+ self.assertTrue(torch.allclose(data[k], reloaded[k]))
+
@unittest.skipIf(not torch.cuda.is_available(), "Cuda is not available")
def test_anonymous_accelerator(self):
data = {