Skip to content

Conversation

@megemini
Copy link
Contributor

@megemini megemini commented Nov 18, 2025

Motivation

关联 #4977

框架兼容 setuptools80+ 之后,cpp_extension 的打包方式发生了改变,因此需要修改 FD 中 copy_ops 的逻辑。

本 PR 修改 XPU 的 build 部分,以补充 #4977 修改。

Modifications

参考 #4977

Usage or Command

参考 #4977

Accuracy Tests

参考 #4977

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[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]]
    • 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.

@SigureMo

@paddle-bot
Copy link

paddle-bot bot commented Nov 18, 2025

Thanks for your contribution!

@paddle-bot paddle-bot bot added the contributor External developers label Nov 18, 2025
@megemini 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 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
@SigureMo
Copy link
Member

Error:  Neither modern nor legacy directory found in /workspace/FastDeploy/custom_ops/tmp
[FAIL] build wheel failed
          please check your code

好像失败了?

貌似 gpu 的算子找不到

PaddlePaddle/Paddle#76008 (comment) 提到的 gpu 算子找不到是完全找不到嘛?我之前测的 case 是能跑起来的来着

@megemini
Copy link
Contributor Author

megemini commented Nov 18, 2025

Error:  Neither modern nor legacy directory found in /workspace/FastDeploy/custom_ops/tmp
[FAIL] build wheel failed
          please check your code

好像失败了?

貌似 gpu 的算子找不到

PaddlePaddle/Paddle#76008 (comment) 提到的 gpu 算子找不到是完全找不到嘛?我之前测的 case 是能跑起来的来着

  1. 关于 xpu 的问题

我在 xpu 的 build.sh 打日志:


list_files_recursive "./${OPS_TMP_DIR}"

${python} setup_ops.py install --install-lib ${OPS_TMP_DIR}

list_files_recursive "./${OPS_TMP_DIR}"

结果,连 tmp 目录都木有


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

所以日志里面提示找不到安装的内容也就很合理了 ~ 只不过,那么之前是怎么安装的?

  1. 关于 gpu 算子找不到的问题

build 的日志:


2025-11-17T14:27:00.6021197Z Listing files in: ./tmp/
...
2025-11-17T14:27:00.6342533Z ./tmp/deep_gemm/paddle_utils.py
2025-11-17T14:27:00.6342745Z ./tmp/deep_gemm/utils.py
2025-11-17T14:27:00.6342996Z ./tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/PKG-INFO
2025-11-17T14:27:00.6343302Z ./tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/SOURCES.txt
2025-11-17T14:27:00.6343624Z ./tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/dependency_links.txt
2025-11-17T14:27:00.6343963Z ./tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/not-zip-safe
2025-11-17T14:27:00.6344269Z ./tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/top_level.txt
2025-11-17T14:27:00.6344553Z ./tmp/fastdeploy_ops/__init__.py
2025-11-17T14:27:00.6344801Z ./tmp/fastdeploy_ops/fastdeploy_ops_pd_.so
2025-11-17T14:27:00.6345036Z ./tmp/version.txt

...
2025-11-17T14:27:00.6345284Z Listing files in: ../fastdeploy/model_executor/ops/gpu
...
2025-11-17T14:27:00.6605899Z ../fastdeploy/model_executor/ops/gpu/deep_gemm/paddle_utils.py
2025-11-17T14:27:00.6606021Z ../fastdeploy/model_executor/ops/gpu/deep_gemm/utils.py
2025-11-17T14:27:00.6606216Z ../fastdeploy/model_executor/ops/gpu/fastdeploy_ops-0.0.0-py3.10.egg-info/PKG-INFO
2025-11-17T14:27:00.6606423Z ../fastdeploy/model_executor/ops/gpu/fastdeploy_ops-0.0.0-py3.10.egg-info/SOURCES.txt
2025-11-17T14:27:00.6606646Z ../fastdeploy/model_executor/ops/gpu/fastdeploy_ops-0.0.0-py3.10.egg-info/dependency_links.txt
2025-11-17T14:27:00.6606845Z ../fastdeploy/model_executor/ops/gpu/fastdeploy_ops-0.0.0-py3.10.egg-info/not-zip-safe
2025-11-17T14:27:00.6607081Z ../fastdeploy/model_executor/ops/gpu/fastdeploy_ops-0.0.0-py3.10.egg-info/top_level.txt
2025-11-17T14:27:00.6607221Z ../fastdeploy/model_executor/ops/gpu/fastdeploy_ops/__init__.py
2025-11-17T14:27:00.6607386Z ../fastdeploy/model_executor/ops/gpu/fastdeploy_ops/fastdeploy_ops_pd_.so
2025-11-17T14:27:00.6607506Z ../fastdeploy/model_executor/ops/gpu/version.txt


说明,算子正确的拷贝到 gpu 目录中了 ~

并且,我在本地模拟测试了 fastdeploy/model_executor/ops/gpu/__init__.pyimport_custom_ops 逻辑:


# 模拟 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

难道是这个算子有问题?

综上,我这里是搞不清楚为啥 debug 的那个 ci 会出问题了 ~ 难道是 ci 的设置的问题?

关联 #4998

@megemini
Copy link
Contributor Author

megemini commented Nov 18, 2025

#4998 我试了一下不 patch cpp_extension ,结果 CI_XPU 同样不行 ~

看了一下其他 PR :https://github.com/PaddlePaddle/FastDeploy/actions/runs/19395322592/job/55548597877?pr=5069

RUN CI UNITTEST 提示:Received len(custom_op) = 0, using cpp extension only

而我们这里的 PR :Received len(custom_op) = 66, using custom operator

难道之前的 CI_XPU 都没有编译安装 custom_op ?

@SigureMo

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾

我看 #4998 已经过了,gpu 那边还有问题嘛?没有问题的话 Paddle 那边也可以推进合入了~

@megemini
Copy link
Contributor Author

LGTMeow 🐾

我看 #4998 已经过了,gpu 那边还有问题嘛?没有问题的话 Paddle 那边也可以推进合入了~

要不就先合了吧 ~

从日志上看应该没问题,出问题再定位吧,现在瞎猜也是浪费时间 ~

@SigureMo
Copy link
Member

从日志上看应该没问题,出问题再定位吧,现在瞎猜也是浪费时间 ~

ok,我推进下

@YuanRisheng YuanRisheng merged commit 3c8c0f0 into PaddlePaddle:develop Nov 19, 2025
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants