Skip to content

Commit

Permalink
Add support for Intel Gaudi hpu accelerators (#566)
Browse files Browse the repository at this point in the history
* Add support for Intel Gaudi hpu accelerators

* Fixing the `find_spec` dep.

* Fixing unused import.

---------

Co-authored-by: Nicolas Patry <[email protected]>
  • Loading branch information
asafkar and Narsil authored Feb 4, 2025
1 parent ea1a2d0 commit ee109c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ enum Device {
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),
}
Expand Down Expand Up @@ -296,6 +297,7 @@ impl<'source> FromPyObject<'source> for Device {
"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),
Expand Down Expand Up @@ -327,6 +329,7 @@ impl<'py> IntoPyObject<'py> for Device {
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()),
}
}
Expand Down
18 changes: 18 additions & 0 deletions bindings/python/tests/test_pt_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ def test_npu(self):
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 = {
Expand Down

1 comment on commit ee109c6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: ee109c6 Previous: ea1a2d0 Ratio
benches/test_pt.py::test_pt_pt_load_cpu_small 10.158733739765273 iter/sec (stddev: 0.0007967088864946675) 27.30529092832197 iter/sec (stddev: 0.00035593015980442443) 2.69

This comment was automatically generated by workflow using github-action-benchmark.

CC: @Narsil

Please sign in to comment.