Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2025-05-18 - FastDeploy get_tensor PySafeSlice parsing
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 建议 .jules/ 目录是 Jules AI bot 自动生成的内部学习笔记,建议将其加入 .gitignore 而非提交到生产仓库。

随着 Jules 后续 PR 的合入,此文件会持续累积条目,对 FastDeploy 仓库来说是无关噪声。建议在根目录 .gitignore 添加 .jules/

**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.
4 changes: 3 additions & 1 deletion fastdeploy/model_executor/layers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading