Skip to content

Commit c06cfe2

Browse files
megeminiEmmonsCurseSigureMoCopilot
authored
【Hackathon 9th No.109】[CppExtension] 添加 fastdeploy_ops 目录到 package_data 以支持现代打包方式 (#5156)
--------- Co-authored-by: YuBaoku <49938469+EmmonsCurse@users.noreply.github.com> Co-authored-by: SigureMo <sigure.qaq@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent cceaba1 commit c06cfe2

11 files changed

Lines changed: 83 additions & 55 deletions

File tree

.github/workflows/_accuracy_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ jobs:
143143
-v "${CACHE_DIR}/ConfigDir:/root/.config" \
144144
-e TZ="Asia/Shanghai" \
145145
--gpus '"device='"${DEVICES}"'"' ${docker_image} /bin/bash -xc '
146-
python -m pip install paddlepaddle-gpu==3.3.0.dev20251118 -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
146+
python -m pip install --pre paddlepaddle-gpu -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
147147
148148
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
149149

.github/workflows/_base_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ jobs:
143143
-v "${CACHE_DIR}/ConfigDir:/root/.config" \
144144
-e TZ="Asia/Shanghai" \
145145
--gpus '"device='"${DEVICES}"'"' ${docker_image} /bin/bash -xc '
146-
python -m pip install paddlepaddle-gpu==3.3.0.dev20251118 -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
146+
python -m pip install --pre paddlepaddle-gpu -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
147147
148148
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
149149

.github/workflows/_build_linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ jobs:
155155
elif [[ "${PADDLEVERSION}" != "" ]];then
156156
python -m pip install paddlepaddle-gpu==${PADDLEVERSION} -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
157157
else
158-
python -m pip install paddlepaddle-gpu==3.3.0.dev20251118 -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
158+
python -m pip install --pre paddlepaddle-gpu -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
159159
fi
160160
161161
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

.github/workflows/_logprob_test_linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
-v "${CACHE_DIR}/ConfigDir:/root/.config" \
135135
-e TZ="Asia/Shanghai" \
136136
--gpus '"device='"${DEVICES}"'"' ${docker_image} /bin/bash -xc '
137-
python -m pip install paddlepaddle-gpu==3.3.0.dev20251118 -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
137+
python -m pip install --pre paddlepaddle-gpu -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
138138
139139
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
140140

.github/workflows/_pre_ce_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ jobs:
154154
--gpus "\"device=${DEVICES}\"" ${docker_image} /bin/bash -c '
155155
git config --global --add safe.directory /workspace/FastDeploy
156156
cd FastDeploy
157-
python -m pip install paddlepaddle-gpu==3.3.0.dev20251118 -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
157+
python -m pip install --pre paddlepaddle-gpu -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
158158
python -m pip install ${fd_wheel_url}
159159
bash scripts/run_pre_ce.sh
160160
'

.github/workflows/_stable_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ jobs:
146146
-v "${CACHE_DIR}/ConfigDir:/root/.config" \
147147
-e TZ="Asia/Shanghai" \
148148
--gpus '"device='"${DEVICES}"'"' ${docker_image} /bin/bash -xc '
149-
python -m pip install paddlepaddle-gpu==3.3.0.dev20251118 -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
149+
python -m pip install --pre paddlepaddle-gpu -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
150150
151151
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
152152

.github/workflows/_unit_test_coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ jobs:
175175
git config --global --add safe.directory /workspace/FastDeploy
176176
cd FastDeploy
177177
git diff origin/${BASE_REF}..HEAD --unified=0 > diff.txt
178-
python -m pip install paddlepaddle-gpu==3.3.0.dev20251118 -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
178+
python -m pip install --pre paddlepaddle-gpu -i https://www.paddlepaddle.org.cn/packages/nightly/cu126/
179179
pip config set global.extra-index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
180180
181181
python -m pip install -r scripts/unittest_requirement.txt

build.sh

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -77,79 +77,81 @@ function copy_ops(){
7777
PY_VERSION="py${PY_MAIN_VERSION}.${PY_SUB_VERSION}"
7878
SYSTEM_VERSION=`${python} -c "import platform; print(platform.system().lower())"`
7979
PROCESSOR_VERSION=`${python} -c "import platform; print(platform.processor())"`
80-
WHEEL_NAME="fastdeploy_ops-${OPS_VERSION}-${PY_VERSION}-${SYSTEM_VERSION}-${PROCESSOR_VERSION}.egg"
81-
WHEEL_CPU_NAME="fastdeploy_cpu_ops-${OPS_VERSION}-${PY_VERSION}-${SYSTEM_VERSION}-${PROCESSOR_VERSION}.egg"
80+
EGG_NAME="fastdeploy_ops-${OPS_VERSION}-${PY_VERSION}-${SYSTEM_VERSION}-${PROCESSOR_VERSION}.egg"
81+
EGG_CPU_NAME="fastdeploy_cpu_ops-${OPS_VERSION}-${PY_VERSION}-${SYSTEM_VERSION}-${PROCESSOR_VERSION}.egg"
8282

8383
# Add compatibility for modern python packaging methods
84-
WHEEL_MODERN_NAME="fastdeploy_ops"
85-
WHEEL_MODERN_CPU_NAME="fastdeploy_cpu_ops"
84+
LEGACY_PACKAGE_DIR="${OPS_TMP_DIR}/${EGG_NAME}"
85+
MODERN_PACKAGE_DIR="${OPS_TMP_DIR}/fastdeploy_ops"
86+
LEGACY_PACKAGE_DIR_CPU="${OPS_TMP_DIR}/${EGG_CPU_NAME}"
87+
MODERN_PACKAGE_DIR_CPU="${OPS_TMP_DIR}/fastdeploy_cpu_ops"
8688

87-
# Handle GPU ops directories (WHEEL_MODERN_NAME and WHEEL_NAME)
88-
if [ -d "./${OPS_TMP_DIR}/${WHEEL_MODERN_NAME}" ]; then
89+
# Handle GPU ops directory compatibility between modern and legacy naming
90+
if [ -d "${MODERN_PACKAGE_DIR}" ]; then
8991
echo -e "${GREEN}[Info]${NONE} Ready to copy ops from modern directory ${WHEEL_MODERN_NAME} to target directory"
90-
# Set WHEEL_NAME to empty string to ignore the directory path
91-
WHEEL_NAME=""
92+
TMP_PACKAGE_DIR="${OPS_TMP_DIR}"
93+
# If modern directory doesn't exist, check for legacy directory, this branch should be removed in the future
94+
elif [ -d "${LEGACY_PACKAGE_DIR}" ]; then
95+
echo -e "${YELLOW}[Warning]${NONE} ${EGG_NAME} directory exists. This is a legacy packaging and distribution method."
96+
TMP_PACKAGE_DIR="${LEGACY_PACKAGE_DIR}"
9297
else
93-
# If modern directory doesn't exist, check for deprecated directory
94-
if [ -d "./${OPS_TMP_DIR}/${WHEEL_NAME}" ]; then
95-
echo -e "${YELLOW}[Warning]${NONE} ${WHEEL_NAME} directory exists. This is a deprecated packaging and distribution method."
96-
fi
98+
echo -e "${RED}[Error]${NONE} Neither modern nor legacy directory for gpu ops found in ${OPS_TMP_DIR}"
9799
fi
98100

99-
# Handle CPU ops directories (WHEEL_MODERN_CPU_NAME and WHEEL_CPU_NAME)
100-
if [ -d "./${OPS_TMP_DIR}/${WHEEL_MODERN_CPU_NAME}" ]; then
101+
# Handle CPU ops directory compatibility between modern and legacy naming
102+
if [ -d "${MODERN_PACKAGE_DIR_CPU}" ]; then
101103
echo -e "${GREEN}[Info]${NONE} Ready to copy ops from modern directory ${WHEEL_MODERN_CPU_NAME} to target directory"
102-
# Set WHEEL_CPU_NAME to empty string to ignore the directory path
103-
WHEEL_CPU_NAME=""
104+
TMP_PACKAGE_DIR_BASE="${OPS_TMP_DIR}"
105+
# If modern directory doesn't exist, check for legacy directory, this branch should be removed in the future
106+
elif [ -d "${LEGACY_PACKAGE_DIR_CPU}" ]; then
107+
echo -e "${YELLOW}[Warning]${NONE} ${EGG_CPU_NAME} directory exists. This is a legacy packaging and distribution method."
108+
TMP_PACKAGE_DIR_BASE="${LEGACY_PACKAGE_DIR_CPU}"
104109
else
105-
# If modern directory doesn't exist, check for deprecated directory
106-
if [ -d "./${OPS_TMP_DIR}/${WHEEL_CPU_NAME}" ]; then
107-
echo -e "${YELLOW}[Warning]${NONE} ${WHEEL_CPU_NAME} directory exists. This is a deprecated packaging and distribution method."
108-
fi
110+
echo -e "${YELLOW}[Warning]${NONE} Neither modern nor legacy directory for cpu ops found in ${OPS_TMP_DIR}"
109111
fi
110112
is_rocm=`$python -c "import paddle; print(paddle.is_compiled_with_rocm())"`
111113
if [ "$is_rocm" = "True" ]; then
112114
DEVICE_TYPE="rocm"
113-
cp -r ./${OPS_TMP_DIR}/${WHEEL_NAME}/* ../fastdeploy/model_executor/ops/gpu
115+
cp -r ${TMP_PACKAGE_DIR}/* ../fastdeploy/model_executor/ops/gpu
114116
echo -e "ROCM ops have been copy to fastdeploy"
115117
return
116118
fi
117119
is_cuda=`$python -c "import paddle; print(paddle.is_compiled_with_cuda())"`
118120
if [ "$is_cuda" = "True" ]; then
119121
DEVICE_TYPE="gpu"
120-
cp -r ./${OPS_TMP_DIR}/${WHEEL_NAME}/* ../fastdeploy/model_executor/ops/gpu
122+
cp -r ${TMP_PACKAGE_DIR}/* ../fastdeploy/model_executor/ops/gpu
121123
echo -e "CUDA ops have been copy to fastdeploy"
122124
return
123125
fi
124126

125127
is_xpu=`$python -c "import paddle; print(paddle.is_compiled_with_xpu())"`
126128
if [ "$is_xpu" = "True" ]; then
127129
DEVICE_TYPE="xpu"
128-
cp -r ./${OPS_TMP_DIR}/${WHEEL_NAME}/* ../fastdeploy/model_executor/ops/xpu
130+
cp -r ${TMP_PACKAGE_DIR}/* ../fastdeploy/model_executor/ops/xpu
129131
echo -e "xpu ops have been copy to fastdeploy"
130132
return
131133
fi
132134

133135
is_npu=`$python -c "import paddle; print(paddle.is_compiled_with_custom_device('npu'))"`
134136
if [ "$is_npu" = "True" ]; then
135137
DEVICE_TYPE="npu"
136-
cp -r ${OPS_TMP_DIR}/${WHEEL_NAME}/* ../fastdeploy/model_executor/ops/npu
138+
cp -r ${TMP_PACKAGE_DIR}/* ../fastdeploy/model_executor/ops/npu
137139
echo -e "npu ops have been copy to fastdeploy"
138140
return
139141
fi
140142

141143
if_corex=`$python -c "import paddle; print(paddle.is_compiled_with_custom_device(\"iluvatar_gpu\"))"`
142144
if [ "$if_corex" = "True" ]; then
143145
DEVICE_TYPE="iluvatar-gpu"
144-
cp -r ./${OPS_TMP_DIR}/${WHEEL_NAME}/* ../fastdeploy/model_executor/ops/iluvatar
146+
cp -r ${TMP_PACKAGE_DIR}/* ../fastdeploy/model_executor/ops/iluvatar
145147
echo -e "Iluvatar ops have been copy to fastdeploy"
146148
return
147149
fi
148150

149151
is_gcu=`$python -c "import paddle; print(paddle.is_compiled_with_custom_device('gcu'))"`
150152
if [ "$is_gcu" = "True" ]; then
151153
DEVICE_TYPE="gcu"
152-
cp -r ${OPS_TMP_DIR}/${WHEEL_NAME}/* ../fastdeploy/model_executor/ops/gcu
154+
cp -r ${TMP_PACKAGE_DIR}/* ../fastdeploy/model_executor/ops/gcu
153155
echo -e "gcu ops have been copy to fastdeploy"
154156
return
155157
fi
@@ -158,8 +160,8 @@ function copy_ops(){
158160
if [ "$is_maca" = "True" ]; then
159161
DEVICE_TYPE="metax_gpu"
160162
mkdir -p ../fastdeploy/model_executor/ops/base
161-
cp -r ./${OPS_TMP_DIR_BASE}/${WHEEL_BASE_NAME}/* ../fastdeploy/model_executor/ops/base
162-
cp -r ./${OPS_TMP_DIR}/${WHEEL_NAME}/* ../fastdeploy/model_executor/ops/gpu
163+
cp -r ${OPS_TMP_DIR_BASE}/${WHEEL_BASE_NAME}/* ../fastdeploy/model_executor/ops/base
164+
cp -r ${TMP_PACKAGE_DIR}/* ../fastdeploy/model_executor/ops/gpu
163165
echo -e "MACA ops have been copy to fastdeploy"
164166
return
165167
fi
@@ -249,8 +251,14 @@ function extract_ops_from_precompiled_wheel() {
249251
echo -e "${BLUE}[precompiled]${NONE} Copying GPU precompiled contents..."
250252
mkdir -p "$DST_DIR"
251253
cp -r "$SRC_DIR/deep_gemm" "$DST_DIR/" 2>/dev/null || true
252-
cp -r "$SRC_DIR/fastdeploy_ops.py" "$DST_DIR/" 2>/dev/null || true
253-
cp -f "$SRC_DIR/"fastdeploy_ops_*.so "$DST_DIR/" 2>/dev/null || true
254+
# Check for modern Python packaging approach (fastdeploy_ops directory)
255+
# If exists, copy the entire directory; otherwise, fall back to legacy method (individual files)
256+
if [ -d "$SRC_DIR/fastdeploy_ops" ]; then
257+
cp -r "$SRC_DIR/fastdeploy_ops" "$DST_DIR/" 2>/dev/null || true
258+
else
259+
cp -r "$SRC_DIR/fastdeploy_ops.py" "$DST_DIR/" 2>/dev/null || true
260+
cp -f "$SRC_DIR/"fastdeploy_ops_*.so "$DST_DIR/" 2>/dev/null || true
261+
fi
254262
cp -f "$SRC_DIR/version.txt" "$DST_DIR/" 2>/dev/null || true
255263

256264
echo -e "${GREEN}[SUCCESS]${NONE} Installed FastDeploy using precompiled wheel."

custom_ops/xpu_ops/build.sh

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,39 @@ PY_SUB_VERSION=`${python} -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $2}'`
2424
PY_VERSION="py${PY_MAIN_VERSION}.${PY_SUB_VERSION}"
2525
SYSTEM_VERSION=`${python} -c "import platform; print(platform.system().lower())"`
2626
PROCESSOR_VERSION=`${python} -c "import platform; print(platform.processor())"`
27-
WHEEL_NAME="fastdeploy_ops-${OPS_VERSION}-${PY_VERSION}-${SYSTEM_VERSION}-${PROCESSOR_VERSION}.egg"
27+
EGG_NAME="fastdeploy_ops-${OPS_VERSION}-${PY_VERSION}-${SYSTEM_VERSION}-${PROCESSOR_VERSION}.egg"
2828

2929
# Add compatibility for modern python packaging methods
30-
WHEEL_MODERN_NAME="fastdeploy_ops"
30+
LEGACY_PACKAGE_DIR="${OPS_TMP_DIR}/${EGG_NAME}"
31+
MODERN_PACKAGE_DIR="${OPS_TMP_DIR}/fastdeploy_ops"
32+
33+
# Check if OPS_TMP_DIR exists, create it if it doesn't
34+
if [ ! -d "${OPS_TMP_DIR}" ]; then
35+
echo -e "${GREEN}[Info]${NONE} Creating directory ${OPS_TMP_DIR}"
36+
mkdir -p "${OPS_TMP_DIR}"
37+
fi
3138

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

3441
# Handle directory compatibility between modern and legacy naming
35-
if [ -d "./${OPS_TMP_DIR}/${WHEEL_MODERN_NAME}" ]; then
36-
echo -e "${GREEN}[Info]${NONE} Ready to use ops from modern directory ${WHEEL_MODERN_NAME}"
42+
if [ -d "${MODERN_PACKAGE_DIR}" ]; then
43+
echo -e "${GREEN}[Info]${NONE} Ready to use ops from modern directory ${MODERN_PACKAGE_DIR}"
3744
# Use modern directory name
38-
TARGET_DIR="${OPS_TMP_DIR}/${WHEEL_MODERN_NAME}"
39-
else
40-
# If modern directory doesn't exist, check for legacy directory
41-
if [ -d "./${OPS_TMP_DIR}/${WHEEL_NAME}" ]; then
42-
echo -e "${YELLOW}[Warning]${NONE} ${WHEEL_NAME} directory exists. This is a deprecated packaging and distribution method."
43-
else
44-
echo -e "${RED}[Error]${NONE} Neither modern nor legacy directory found in ${OPS_TMP_DIR}"
45-
fi
45+
TMP_PACKAGE_DIR="${OPS_TMP_DIR}"
46+
CUSTOM_OP_DLL_RPATH='$ORIGIN/../libs'
47+
CUSTOM_OP_DLL_PATH="${MODERN_PACKAGE_DIR}/fastdeploy_ops_pd_.so"
48+
# If modern directory doesn't exist, check for legacy directory, this branch should be removed in the future
49+
elif [ -d "${LEGACY_PACKAGE_DIR}" ]; then
50+
echo -e "${YELLOW}[Warning]${NONE} ${LEGACY_PACKAGE_DIR} directory exists. This is a deprecated packaging and distribution method."
4651
# Use legacy directory name
47-
TARGET_DIR="${OPS_TMP_DIR}/${WHEEL_NAME}"
52+
TMP_PACKAGE_DIR="${LEGACY_PACKAGE_DIR}"
53+
CUSTOM_OP_DLL_RPATH='$ORIGIN/libs'
54+
CUSTOM_OP_DLL_PATH="${TMP_PACKAGE_DIR}/fastdeploy_ops_pd_.so"
55+
else
56+
echo -e "${RED}[Error]${NONE} Neither modern nor legacy directory for xpu ops found in ${OPS_TMP_DIR}"
4857
fi
4958

50-
mkdir -p ${TARGET_DIR}/libs
51-
cp ${XVLLM_PATH}/xft_blocks/so/libxft_blocks.so ${TARGET_DIR}/libs/
52-
cp ${XVLLM_PATH}/infer_ops/so/libapiinfer.so ${TARGET_DIR}/libs/
53-
patchelf --set-rpath '$ORIGIN/libs' ${TARGET_DIR}/fastdeploy_ops_pd_.so
59+
mkdir -p ${TMP_PACKAGE_DIR}/libs
60+
cp ${XVLLM_PATH}/xft_blocks/so/libxft_blocks.so ${TMP_PACKAGE_DIR}/libs/
61+
cp ${XVLLM_PATH}/infer_ops/so/libapiinfer.so ${TMP_PACKAGE_DIR}/libs/
62+
patchelf --set-rpath ${CUSTOM_OP_DLL_RPATH} ${CUSTOM_OP_DLL_PATH}

scripts/run_ci_xpu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ echo "uninstall org"
4242
python -m pip uninstall paddlepaddle-xpu -y
4343
python -m pip uninstall fastdeploy-xpu -y
4444

45-
python -m pip install https://paddle-whl.bj.bcebos.com/nightly/xpu-p800/paddlepaddle-xpu/paddlepaddle_xpu-3.3.0.dev20251118-cp310-cp310-linux_x86_64.whl
45+
python -m pip install paddlepaddle-xpu -i https://www.paddlepaddle.org.cn/packages/nightly/xpu-p800/
4646

4747
echo "build whl"
4848
bash custom_ops/xpu_ops/download_dependencies.sh develop

0 commit comments

Comments
 (0)