You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can add new tags based on the PR content, but the semantics must be clear.
Format your code, run pre-commit before commit.
Add unit tests. Please write the reason in this PR if no unit tests.
Provide accuracy results.
If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.
megemini
changed the title
【Hackathon 9th No.109】[CppExtension] Support build Custom OP in setuptools 80+
【Hackathon 9th No.109】[CppExtension] [XPU] Support build Custom OP in setuptools 80+
Nov 18, 2025
megemini
changed the title
【Hackathon 9th No.109】[CppExtension] [XPU] Support build Custom OP in setuptools 80+
【Hackathon 9th No.109】[CppExtension] [XPU] Support build Custom OP in setuptools 80+ -part
Nov 18, 2025
2025-11-18T05:40:05.4489410Z Directory not found: .//workspace/FastDeploy/custom_ops/tmp
2025-11-18T05:40:05.4489817Z [Error] Neither modern nor legacy directory found in /workspace/FastDeploy/custom_ops/tmp
# 模拟 fd 中拷贝之后的目录结构
➜ build git:(setuptools80) ✗ tree tmp_setuptools
tmp_setuptools
...
`-- tmp_install
|-- __init__.py
|-- __pycache__
| |-- __init__.cpython-39.pyc
| `-- custom_setup_ops.cpython-39.pyc
|-- custom_setup_ops
| |-- __init__.py
| |-- __pycache__
| | `-- __init__.cpython-39.pyc
| `-- custom_setup_ops_pd_.so
|-- custom_setup_ops-0.0.0-py3.9.egg-info
| |-- PKG-INFO
| |-- SOURCES.txt
| |-- dependency_links.txt
| |-- not-zip-safe
| `-- top_level.txt
`-- version.txt
# 将 import_custom_ops 放到 __init__.py 中,并在 __init__.py 中导入拷贝之后的算子
➜ build git:(setuptools80) ✗ cat tmp_setuptools/tmp_install/__init__.py
...
def import_custom_ops(package, module_name, global_ns):
"""
Imports custom operations from a specified module within a package and adds them to a global namespace.
Args:
package (str): The name of the package containing the module.
module_name (str): The name of the module within the package.
global_ns (dict): The global namespace to add the imported functions to.
"""
module = importlib.import_module(module_name, package=package)
print(">"*20, module)
functions = inspect.getmembers(module)
print(">"*20, functions)
for func_name, func in functions:
if func_name.startswith("__") or func_name == "_C_ops":
continue
print(f"Import {func_name} from {package}")
try:
global_ns[func_name] = func
except Exception as e:
print(f"Failed to import op {func_name}: {e}")
preprocess_static_op(global_ns)
...
PACKAGE = "tmp_setuptools.tmp_install"
import_custom_ops(PACKAGE, ".custom_setup_ops", globals())
# 可以看到,算子可以正确导入,`Import custom_relu from tmp_setuptools.tmp_install`
➜ build git:(setuptools80) ✗ ipython
Python 3.9.18 (main, Aug 25 2023, 13:20:04)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.18.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from tmp_setuptools.tmp_install import custom_relu
Files in directory: /paddle/Paddle/build/tmp_setuptools/tmp_install
/paddle/Paddle/build/tmp_setuptools/tmp_install/version.txt
/paddle/Paddle/build/tmp_setuptools/tmp_install/__init__.py
/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops/custom_setup_ops_pd_.so
/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops/__init__.py
/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops/__pycache__/__init__.cpython-39.pyc
/paddle/Paddle/build/tmp_setuptools/tmp_install/__pycache__/__init__.cpython-39.pyc
/paddle/Paddle/build/tmp_setuptools/tmp_install/__pycache__/custom_setup_ops.cpython-39.pyc
/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops-0.0.0-py3.9.egg-info/SOURCES.txt
/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops-0.0.0-py3.9.egg-info/top_level.txt
/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops-0.0.0-py3.9.egg-info/not-zip-safe
/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops-0.0.0-py3.9.egg-info/dependency_links.txt
/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops-0.0.0-py3.9.egg-info/PKG-INFO
>>>>>>>>>>>>>>>>>>>> <module 'tmp_setuptools.tmp_install.custom_setup_ops' from '/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops/__init__.py'>
>>>>>>>>>>>>>>>>>>>> [('LayerHelper', <class 'paddle.base.layer_helper.LayerHelper'>), ...
All Rights Reserved.
Copyright (c) 2000 BeOpen.com.
All Rights Reserved.
Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.
Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved., 'credits': Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
for supporting Python development. See www.python.org for more information., 'license': Type license() to see the full license text, 'help': Type help() for interactive help, or help(object) for help about object., '__IPYTHON__': True, 'display': <function display at 0x7f83e6f42160>, 'get_ipython': <bound method InteractiveShell.get_ipython of <IPython.terminal.interactiveshell.TerminalInteractiveShell object at 0x7f83e5ff6310>>, '__pybind11_internals_v4_gcc_libstdcpp_cxxabi1013__': <capsule object NULL at 0x7f83e4aa61b0>}), ('__cached__', '/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops/__pycache__/__init__.cpython-39.pyc'), ('__doc__', None), ('__file__', '/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops/__init__.py'), ('__loader__', <_frozen_importlib_external.SourceFileLoader object at 0x7f836f0b3a60>), ('__name__', 'tmp_setuptools.tmp_install.custom_setup_ops'), ('__package__', 'tmp_setuptools.tmp_install.custom_setup_ops'), ('__path__', ['/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops']), ('__spec__', ModuleSpec(name='tmp_setuptools.tmp_install.custom_setup_ops', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f836f0b3a60>, origin='/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops/__init__.py', submodule_search_locations=['/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops'])), ('cur_dir', '/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops'), ('custom_relu', <function custom_relu at 0x7f836f0a45e0>), ('importlib', <module 'importlib' from '/usr/lib/python3.9/importlib/__init__.py'>), ('in_dynamic_or_pir_mode', <function in_dynamic_or_pir_mode at 0x7f83910c9c10>), ('os', <module 'os' from '/usr/lib/python3.9/os.py'>), ('paddle', <module 'paddle' from '/usr/local/lib/python3.9/dist-packages/paddle/__init__.py'>), ('so_path', '/paddle/Paddle/build/tmp_setuptools/tmp_install/custom_setup_ops/custom_setup_ops_pd_.so'), ('sys', <module 'sys' (built-in)>), ('types', <module 'types' from '/usr/lib/python3.9/types.py'>), ('unified', <function unified at 0x7f83ab924f70>)]
Import LayerHelper from tmp_setuptools.tmp_install
Import cur_dir from tmp_setuptools.tmp_install
Import custom_relu from tmp_setuptools.tmp_install
Import importlib from tmp_setuptools.tmp_install
Import in_dynamic_or_pir_mode from tmp_setuptools.tmp_install
Import os from tmp_setuptools.tmp_install
Import paddle from tmp_setuptools.tmp_install
Import so_path from tmp_setuptools.tmp_install
Import sys from tmp_setuptools.tmp_install
Import types from tmp_setuptools.tmp_install
Import unified from tmp_setuptools.tmp_install
从日志和本地测试来看,不应该出现算子找不到的问题 ~
而那个 debug 的 pr 中的日志提示错误:
2025-11-17T14:30:47.4854245Z from fastdeploy.model_executor.ops.gpu import (
2025-11-17T14:30:47.4854927Z ImportError: cannot import name '\''append_attention'\'' from '\''fastdeploy.model_executor.ops.gpu'\'' (/usr/local/lib/python3.10/site-packages/fastdeploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
关联 #4977
框架兼容 setuptools80+ 之后,cpp_extension 的打包方式发生了改变,因此需要修改 FD 中 copy_ops 的逻辑。
本 PR 修改 XPU 的 build 部分,以补充 #4977 修改。
Modifications
参考 #4977
Usage or Command
参考 #4977
Accuracy Tests
参考 #4977
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.@SigureMo