Skip to content

【Hackathon 9th No.109】[CppExtension] 添加 fastdeploy_ops 目录到 package_data 以支持现代打包方式 - part#5156

Merged
SigureMo merged 17 commits intoPaddlePaddle:developfrom
megemini:setuptools80_package_data
Nov 21, 2025
Merged

【Hackathon 9th No.109】[CppExtension] 添加 fastdeploy_ops 目录到 package_data 以支持现代打包方式 - part#5156
SigureMo merged 17 commits intoPaddlePaddle:developfrom
megemini:setuptools80_package_data

Conversation

@megemini
Copy link
Contributor

@megemini megemini commented Nov 20, 2025

Motivation

关联:#5106

paddle 框架使用 python 现代的打包方式之后,生成的 .so 文件在 fastdeploy_ops 目录中,因此需要在 setup.py 打包时添加到 package_data 中。

Modifications

setup.pypackage_data

Usage or Command

build.sh 中的:

function build_and_install() {
  echo -e "${BLUE}[build]${NONE} building fastdeploy wheel..."
  ${python} setup.py bdist_wheel --python-tag=py3

  if [ $? -ne 0 ]; then
    echo -e "${RED}[FAIL]${NONE} build fastdeploy wheel failed"
    exit 1
  fi
  echo -e "${BLUE}[build]${NONE} ${GREEN}build fastdeploy wheel success${NONE}\n"
}

Accuracy Tests

关联:#4998

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 帮忙请 fd 的大佬帮忙跑一下 ci 吧 ~

#4998 测试了 patch cpp_extension 后应该是没啥问题了 ~

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.

牛哇顺师傅,可以直接在这个 PR 里 revert 下 #5136,这样就能在这个 PR 里验证修复了~

@codecov-commenter
Copy link

codecov-commenter commented Nov 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@6471dad). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #5156   +/-   ##
==========================================
  Coverage           ?   57.68%           
==========================================
  Files              ?      317           
  Lines              ?    38445           
  Branches           ?     5762           
==========================================
  Hits               ?    22178           
  Misses             ?    14489           
  Partials           ?     1778           
Flag Coverage Δ
diff 57.68% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@megemini
Copy link
Contributor Author

今天定位这个 xpu 的问题,对比 #4998 pass 的https://github.com/PaddlePaddle/FastDeploy/actions/runs/19541739687/job/55949692263?pr=4998 日志,与今天 fail 的日志,fail 的日志显示:

2025-11-21T08:52:00.7069490Z [Error] Neither modern nor legacy directory found in /workspace/FastDeploy/custom_ops/tmp
2025-11-21T08:52:00.7069882Z [Error] Contents of /workspace/FastDeploy/custom_ops/tmp:
2025-11-21T08:52:00.7080416Z total 8
2025-11-21T08:52:00.7080597Z drwxr-xr-x 2 root root 4096 Nov 21 08:51 .
2025-11-21T08:52:00.7080838Z drwxr-xr-x 3 root root 4096 Nov 21 08:51 ..

预期是:

2025-11-20T15:21:05.6596399Z [Info] Ready to use ops from modern directory fastdeploy_ops
2025-11-20T15:21:05.6596654Z >>> 3
2025-11-20T15:21:05.6596856Z Listing files in: /workspace/FastDeploy/custom_ops/tmp
2025-11-20T15:21:05.6597234Z /workspace/FastDeploy/custom_ops/tmp/__pycache__/fastdeploy_ops.cpython-310.pyc
2025-11-20T15:21:05.6597669Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/PKG-INFO
2025-11-20T15:21:05.6598333Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/SOURCES.txt
2025-11-20T15:21:05.6598811Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/dependency_links.txt
2025-11-20T15:21:05.6599303Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/not-zip-safe
2025-11-20T15:21:05.6599773Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/top_level.txt
2025-11-20T15:21:05.6600193Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops/__init__.py
2025-11-20T15:21:05.6600578Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops/fastdeploy_ops_pd_.so
2025-11-20T15:21:05.6600917Z /workspace/FastDeploy/custom_ops/tmp/version.txt
2025-11-20T15:21:05.6601098Z 
2025-11-20T15:21:05.6601163Z >>> 3 1
2025-11-20T15:21:05.6601401Z Listing files in: /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops
2025-11-20T15:21:05.6601763Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops/__init__.py
2025-11-20T15:21:05.6602145Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops/fastdeploy_ops_pd_.so
2025-11-20T15:21:05.6602375Z 
2025-11-20T15:21:05.6606387Z >>> 4
2025-11-20T15:21:05.6606601Z Listing files in: /workspace/FastDeploy/custom_ops/tmp
2025-11-20T15:21:05.6617353Z /workspace/FastDeploy/custom_ops/tmp/__pycache__/fastdeploy_ops.cpython-310.pyc
2025-11-20T15:21:05.6617796Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/PKG-INFO
2025-11-20T15:21:05.6618258Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/SOURCES.txt
2025-11-20T15:21:05.6618736Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/dependency_links.txt
2025-11-20T15:21:05.6619227Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/not-zip-safe
2025-11-20T15:21:05.6619682Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops-0.0.0-py3.10.egg-info/top_level.txt
2025-11-20T15:21:05.6620097Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops/__init__.py
2025-11-20T15:21:05.6620481Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops/fastdeploy_ops_pd_.so
2025-11-20T15:21:05.6620815Z /workspace/FastDeploy/custom_ops/tmp/version.txt
2025-11-20T15:21:05.6620982Z 
2025-11-20T15:21:05.6621056Z >>> 4 1
2025-11-20T15:21:05.6621291Z Listing files in: /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops
2025-11-20T15:21:05.6628909Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops/__init__.py
2025-11-20T15:21:05.6629426Z /workspace/FastDeploy/custom_ops/tmp/fastdeploy_ops/fastdeploy_ops_pd_.so
2025-11-20T15:21:05.6629686Z 
2025-11-20T15:21:06.0310478Z �[0;34m[build]�[0m �[1;32mbuild fastdeploy_ops success �[0m
2025-11-20T15:21:06.0806695Z �[1;32m[Info]�[0m Ready to copy ops from modern directory fastdeploy_ops to target directory

上面日志里面 >>> 开头的是调试部分,listing 安装目录的内容,最后一句最关键:Ready to copy ops from modern directory fastdeploy_ops to target directory,说明安装命令执行成功:

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

而 fail 的日志说明,这条安装命令应该就没有执行成功 ~

仔细对比了昨天 pass 和今天 fail 的日志,发现,pass 的 custom_ops 是 66 个

2025-11-20T15:21:05.0373483Z Received len(custom_op) = 66, using custom operator

而今天 fail 的是 67 个

2025-11-21T08:52:00.0822675Z Received len(custom_op) = 67, using custom operator

结合前两天 debug 的时候也发现,Neither modern nor legacy directory found in /workspace/FastDeploy/custom_ops/tmp ,应该是这两天一直有一个 custom_op 在测试?导致 CI 时好时坏?

其他 CI 测试目前看基础功能没啥问题,应该不是 cpp_extension 的问题了 ~

@SigureMo 目前定位的情况是这样,得请大佬看看其他环节?

@SigureMo
Copy link
Member

我要到 XPU 机器了,我调试下

@SigureMo
Copy link
Member

应该搞定了

@SigureMo
Copy link
Member

单测问题我再看看

@megemini
Copy link
Contributor Author

应该搞定了

gpu 那边 tmp 目录是个相对路径,xpu 这边是个绝对路径 ~ 太细了 ... ... 👍️👍️👍️

单测问题我再看看

看上去是算子加载有问题?

@SigureMo
Copy link
Member

看上去是算子加载有问题?

rpath 的问题,相对路径不一样,因为现在多了一层目录,从自定义算子找 libs 需要 $ORIGIN/../libs

@SigureMo
Copy link
Member

xpu 这边是个绝对路径

对的,xpu 是从上层 build.sh 传过来的,不是用的默认值 tmp

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for modern Python packaging methods (PEP 517/518) by including the fastdeploy_ops directory in package_data for various hardware backends (GPU, CPU, XPU, NPU, GCU, Iluvatar). The changes ensure that .so files generated under the new packaging structure are properly included in the wheel distribution.

Key changes:

  • Updated setup.py to include fastdeploy_ops subdirectories in package_data for all device types
  • Refactored build scripts to handle both modern (directory-based) and legacy (egg-based) packaging methods
  • Updated CI/CD workflows to use --pre flag for installing nightly paddlepaddle-gpu builds

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
setup.py Added fastdeploy_ops/* patterns to package_data for all hardware backends (gpu, cpu, xpu, npu, gcu, iluvatar, base) to support modern Python packaging
build.sh Refactored variable naming (WHEEL_NAME→EGG_NAME) and added logic to detect and handle both modern and legacy package directory structures
custom_ops/xpu_ops/build.sh Refactored to support modern packaging with improved directory handling, rpath configuration, and directory existence checks
scripts/run_ci_xpu.sh Updated paddlepaddle-xpu installation to use package index instead of direct URL
.github/workflows/*.yml Updated all workflow files to use --pre flag for installing nightly paddlepaddle-gpu builds consistently

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 9 comments.

Comments suppressed due to low confidence (1)

build.sh:177

  • The variable WHEEL_CPU_NAME is undefined. It was renamed to EGG_CPU_NAME in this PR. This should likely use TMP_PACKAGE_DIR_BASE which is set earlier in the function to handle both legacy and modern packaging methods.
    cp -r ${OPS_TMP_DIR}/${WHEEL_CPU_NAME}/* ../fastdeploy/model_executor/ops/cpu

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 🐾

@SigureMo SigureMo merged commit c06cfe2 into PaddlePaddle:develop Nov 21, 2025
21 of 23 checks passed
@SigureMo SigureMo changed the title 【Hackathon 9th No.109】[CppExtension] 添加 fastdeploy_ops 目录到 package_data 以支持现代打包方式 【Hackathon 9th No.109】[CppExtension] 添加 fastdeploy_ops 目录到 package_data 以支持现代打包方式 - part Nov 21, 2025
@EmmonsCurse
Copy link
Collaborator

@megemini @SigureMo

这个 PR 的修改导致了单测覆盖率统计增加了 fastdeploy/model_executor/ops/gpu/fastdeploy_ops/__init__.py 文件的计算,造成整体覆盖率有 3% 的下降,需要高优处理一下。

Name                                                                                       Stmts   Miss Branch BrPart  Cover
----------------------------------------------------------------------------------------------------------------------------
fastdeploy/model_executor/ops/gpu/fastdeploy_ops/__init__.py                                4870   3486    982     40    24%

@SigureMo
Copy link
Member

#5177 会修复该问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants