From: Ilyas Moutawwakil <57442720+IlyasMoutawwakil@users.noreply.github.com> Date: Tue, 25 Feb 2025 11:11:12 +0000 (+0100) Subject: hpu index (#578) X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=579ddf974953ce28c0ae63b2f3b1ec441b7b6644;p=safetensors.git hpu index (#578) --- diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index df3de7d..1e6ba85 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -202,7 +202,7 @@ enum Device { Xpu(usize), Xla(usize), Mlu(usize), - Hpu, + Hpu(usize), /// User didn't specify accelerator, torch /// is responsible for choosing. Anonymous(usize), @@ -232,12 +232,13 @@ 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), + "hpu" => Ok(Device::Hpu(0)), 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), name if name.starts_with("xla:") => parse_device(name).map(Device::Xla), name if name.starts_with("mlu:") => parse_device(name).map(Device::Mlu), + name if name.starts_with("hpu:") => parse_device(name).map(Device::Hpu), name => Err(SafetensorError::new_err(format!( "device {name} is invalid" ))), @@ -264,7 +265,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::Hpu(n) => format!("hpu:{n}").into_pyobject(py).map(|x| x.into_any()), Device::Anonymous(n) => n.into_pyobject(py).map(|x| x.into_any()), } }