]> khamidou — GitHub mirrors - safetensors.git/commitdiff
hpu index (#578)
authorIlyas Moutawwakil <57442720+IlyasMoutawwakil@users.noreply.github.com>
Tue, 25 Feb 2025 11:11:12 +0000 (12:11 +0100)
committerGitHub <noreply@github.com>
Tue, 25 Feb 2025 11:11:12 +0000 (12:11 +0100)
bindings/python/src/lib.rs

index df3de7d3239df00993860699e5e8b3e430546ddb..1e6ba8531057296b94fcca14f8d985ed1ed1935f 100644 (file)
@@ -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()),
         }
     }