From ef638848ef8f76804547125987dfbb0b50e3f1ba Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 3 May 2026 14:40:02 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20optimize=20get=5Ftensor=20t?= =?UTF-8?q?ype=20check=20for=20PySafeSlice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/bolt.md | 3 +++ fastdeploy/model_executor/layers/utils.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000000..3ab07c55e82 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2025-05-18 - FastDeploy get_tensor PySafeSlice parsing +**Learning:** Checking for `PySafeSlice` by calling `str(type(input))` and looking for a substring (`"PySafeSlice" in str(type(input))`) creates unneeded string formatting overhead in the extremely hot path of `get_tensor` logic since it's frequently called across weight loading and other utils. +**Action:** Replace `str(type(input))` with `type(input).__name__ == "PySafeSlice"` to speed it up. diff --git a/fastdeploy/model_executor/layers/utils.py b/fastdeploy/model_executor/layers/utils.py index f3444173e18..3059cef3da3 100644 --- a/fastdeploy/model_executor/layers/utils.py +++ b/fastdeploy/model_executor/layers/utils.py @@ -332,7 +332,9 @@ def get_tensor(input: Union[paddle.Tensor, np.ndarray, str], model_path=None) -> paddle.Tensor: Returns a PaddlePaddle tensor. """ - if "PySafeSlice" in str(type(input)): + # Optimize type checking: type(input).__name__ avoids the overhead of converting + # the type object to a string for substring matching. + if type(input).__name__ == "PySafeSlice": input = input.get() if isinstance(input, paddle.Tensor):