From: Nicolas Patry Date: Mon, 18 Aug 2025 14:49:55 +0000 (+0200) Subject: Fix clippy lint. (#648) X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=54b35101e4fead20d5104468e1093250f267ead1;p=safetensors.git Fix clippy lint. (#648) * Fix clippy lint. * Format. --- diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index f48f102..891d310 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -382,12 +382,12 @@ enum Storage { /// This allows us to not manage it /// so Pytorch can handle the whole lifecycle. /// https://pytorch.org/docs/stable/storage.html#torch.TypedStorage.from_file. - TorchStorage(OnceLock), + Torch(OnceLock), // Paddle specific mmap // This allows us to not manage the lifecycle of the storage, // Paddle can handle the whole lifecycle. // https://www.paddlepaddle.org.cn/documentation/docs/en/develop/api/paddle/MmapStorage_en.html - PaddleStorage(OnceLock), + Paddle(OnceLock), } #[derive(Debug, PartialEq, Eq, PartialOrd)] @@ -517,7 +517,7 @@ impl Open { .into(); let gil_storage = OnceLock::new(); gil_storage.get_or_init_py_attached(py, || storage); - Ok(Storage::PaddleStorage(gil_storage)) + Ok(Storage::Paddle(gil_storage)) } else { let module = PyModule::import(py, intern!(py, "numpy"))?; NUMPY_MODULE.get_or_init_py_attached(py, || module.into()); @@ -568,7 +568,7 @@ impl Open { let gil_storage = OnceLock::new(); gil_storage.get_or_init_py_attached(py, || storage); - Ok(Storage::TorchStorage(gil_storage)) + Ok(Storage::Torch(gil_storage)) } else { Ok(Storage::Mmap(buffer)) } @@ -658,7 +658,7 @@ impl Open { &self.device, ) } - Storage::PaddleStorage(storage) => { + Storage::Paddle(storage) => { Python::with_gil(|py| -> PyResult { let paddle = get_module(py, &PADDLE_MODULE)?; let cur_type = if info.dtype == Dtype::U16 { @@ -744,7 +744,7 @@ impl Open { Ok(tensor.into_pyobject(py)?.into()) }) } - Storage::TorchStorage(storage) => { + Storage::Torch(storage) => { Python::with_gil(|py| -> PyResult { let torch = get_module(py, &TORCH_MODULE)?; let dtype: PyObject = get_pydtype(torch, info.dtype, false)?; @@ -1128,7 +1128,7 @@ impl PySafeSlice { ) }) } - Storage::TorchStorage(storage) => Python::with_gil(|py| -> PyResult { + Storage::Torch(storage) => Python::with_gil(|py| -> PyResult { let torch = get_module(py, &TORCH_MODULE)?; let dtype: PyObject = get_pydtype(torch, self.info.dtype, false)?; let torch_uint8: PyObject = get_pydtype(torch, Dtype::U8, false)?; @@ -1207,7 +1207,7 @@ impl PySafeSlice { } Ok(tensor.into()) }), - Storage::PaddleStorage(storage) => Python::with_gil(|py| -> PyResult { + Storage::Paddle(storage) => Python::with_gil(|py| -> PyResult { let paddle = get_module(py, &PADDLE_MODULE)?; let cur_type = if self.info.dtype == Dtype::U16 { Dtype::BF16 diff --git a/bindings/python/tests/test_paddle_comparison.py b/bindings/python/tests/test_paddle_comparison.py index 47ad022..0f8b8d9 100644 --- a/bindings/python/tests/test_paddle_comparison.py +++ b/bindings/python/tests/test_paddle_comparison.py @@ -59,7 +59,9 @@ class WithOpenCase(unittest.TestCase): save_file(tensors, "./tensor_paddle.safetensors") # Now loading cpu - with safe_open("./tensor_paddle.safetensors", framework="paddle", device="cpu") as f: + with safe_open( + "./tensor_paddle.safetensors", framework="paddle", device="cpu" + ) as f: tensor = f.get_tensor("a") self.assertEqual(list(tensor.shape), [10, 5]) assert paddle.allclose(tensor, A).item() @@ -72,7 +74,9 @@ class WithOpenCase(unittest.TestCase): } save_file(tensors, "./tensor_paddle.safetensors") # Now loading gpu - with safe_open("./tensor_paddle.safetensors", framework="paddle", device="cuda") as f: + with safe_open( + "./tensor_paddle.safetensors", framework="paddle", device="cuda" + ) as f: tensor = f.get_tensor("a") self.assertEqual(list(tensor.shape), [10, 5]) assert paddle.allclose(tensor, A).item() @@ -86,7 +90,9 @@ class WithOpenCase(unittest.TestCase): save_file(tensors, "./slice_paddle.safetensors") # Now loading - with safe_open("./slice_paddle.safetensors", framework="paddle", device="cpu") as f: + with safe_open( + "./slice_paddle.safetensors", framework="paddle", device="cpu" + ) as f: slice_ = f.get_slice("a") tensor = slice_[:] self.assertEqual(list(tensor.shape), [10, 5]) @@ -141,7 +147,9 @@ class WithOpenCase(unittest.TestCase): save_file(tensors, "./slice_paddle.safetensors") # Now loading - with safe_open("./slice_paddle.safetensors", framework="paddle", device="cuda") as f: + with safe_open( + "./slice_paddle.safetensors", framework="paddle", device="cuda" + ) as f: slice_ = f.get_slice("a") tensor = slice_[:] self.assertEqual(list(tensor.shape), [10, 5])