5ab4bef80e
交付:
· 产物按变体命名:CPU -> dist/ocr-server/,GPU -> dist/ocr-server-gpu/。
变体由构建环境实际装的 paddle 自动判断,不需要人工声明
· GPU 包额外加 --collect-binaries nvidia。漏收的后果实测是最难查的那种:
引擎能正常加载、设备也识别成 GPU,但第一次推理才报
cudnn64_9.dll error 126
· --copy-metadata 的发行包名随变体变化(paddlepaddle / paddlepaddle-gpu),
改由 scripts/paddle_env.py 动态取;写死任何一个在另一种环境下都打不出包
· 新增 scripts/prepare_release_config.py 按变体覆盖发布配置(用 Python 改写
以保持 UTF-8,PowerShell 的 Set-Content 会把中文注释写坏)
环境:
· paddle 从 pyproject 依赖里移除,改用 scripts/install_paddle.py 安装。
它没法写死:CPU/GPU 互斥,GPU 还得按显卡选 CUDA 通道(RTX 50 系必须 cu129)。
钉死 CPU 版时,uv sync / uv run / PyCharm 自动同步都会把装好的
paddlepaddle-gpu 静默挤掉、服务悄悄退回 CPU(实测踩过三次)
· 新增 scripts/switch_env.py:.venv(CPU)与 .venv-gpu(GPU)两套环境共存,
切换零成本;所有 uv run 补 --no-sync,打包改用 uv sync --inexact
· 预置模型扩到 8 套(v4/v5 × 服务端/移动端 × 检测/识别,约 398MB)
其它:
· scripts/start.* 先找发布包再退回源码环境;入口脚本名固定是 ocr-server
· benchmark_ocr.py 输出 segments 与 chars,换设备/模型时可直接比对召回
· .gitignore 覆盖 .venv-gpu/ 与 dist*/
Co-Authored-By: Claude Code <noreply@anthropic.com>
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
"""报告当前构建环境里的 paddlepaddle 变体,供打包脚本选择 CPU/GPU 产物。
|
||
|
||
用法(打包脚本内部调用):
|
||
python scripts/paddle_env.py variant -> cpu / gpu / missing
|
||
python scripts/paddle_env.py distribution -> paddlepaddle / paddlepaddle-gpu
|
||
|
||
`distribution` 用于 --copy-metadata:PyPI 上 CPU 版发行包叫 paddlepaddle,
|
||
GPU 版叫 paddlepaddle-gpu,写死任何一个在另一种环境下都会打包失败。
|
||
"""
|
||
|
||
import importlib.metadata
|
||
import importlib.util
|
||
import sys
|
||
|
||
CPU_DISTRIBUTION = "paddlepaddle"
|
||
GPU_DISTRIBUTION = "paddlepaddle-gpu"
|
||
|
||
|
||
def detect_variant() -> str:
|
||
if importlib.util.find_spec("paddle") is None:
|
||
return "missing"
|
||
import paddle
|
||
|
||
return "gpu" if paddle.device.is_compiled_with_cuda() else "cpu"
|
||
|
||
|
||
def detect_distribution() -> str:
|
||
"""返回实际安装的发行包名。"""
|
||
for name in (CPU_DISTRIBUTION, GPU_DISTRIBUTION):
|
||
try:
|
||
importlib.metadata.version(name)
|
||
except importlib.metadata.PackageNotFoundError:
|
||
continue
|
||
return name
|
||
return ""
|
||
|
||
|
||
def main() -> int:
|
||
if len(sys.argv) != 2 or sys.argv[1] not in {"variant", "distribution"}:
|
||
print(__doc__.strip(), file=sys.stderr)
|
||
return 2
|
||
if sys.argv[1] == "variant":
|
||
print(detect_variant())
|
||
return 0
|
||
distribution = detect_distribution()
|
||
if not distribution:
|
||
print("未找到已安装的 paddlepaddle / paddlepaddle-gpu", file=sys.stderr)
|
||
return 1
|
||
print(distribution)
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
raise SystemExit(main())
|