ls-algorithm-plugin-sdk 0.2.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ls_algorithm_plugin_sdk-0.2.5/PKG-INFO +87 -0
- ls_algorithm_plugin_sdk-0.2.5/README.md +72 -0
- ls_algorithm_plugin_sdk-0.2.5/pyproject.toml +37 -0
- ls_algorithm_plugin_sdk-0.2.5/setup.cfg +4 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/__init__.py +52 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/algorithm.py +33 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/cli.py +542 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/context.py +307 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/deployment.py +317 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/errors.py +27 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/examples/__init__.py +1 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/examples/example_algorithm.py +119 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/examples/simulated_algorithm.py +92 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/loader.py +71 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/models.py +322 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/registration.py +282 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/release.py +171 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/runner.py +114 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/service.py +664 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/webui/__init__.py +1 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/webui/app.css +49 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/webui/app.js +197 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/webui/index.html +62 -0
- ls_algorithm_plugin_sdk-0.2.5/src/algorithm_plugin_sdk/webui_app.py +43 -0
- ls_algorithm_plugin_sdk-0.2.5/src/ls_algorithm_plugin_sdk.egg-info/PKG-INFO +87 -0
- ls_algorithm_plugin_sdk-0.2.5/src/ls_algorithm_plugin_sdk.egg-info/SOURCES.txt +35 -0
- ls_algorithm_plugin_sdk-0.2.5/src/ls_algorithm_plugin_sdk.egg-info/dependency_links.txt +1 -0
- ls_algorithm_plugin_sdk-0.2.5/src/ls_algorithm_plugin_sdk.egg-info/entry_points.txt +2 -0
- ls_algorithm_plugin_sdk-0.2.5/src/ls_algorithm_plugin_sdk.egg-info/requires.txt +8 -0
- ls_algorithm_plugin_sdk-0.2.5/src/ls_algorithm_plugin_sdk.egg-info/top_level.txt +1 -0
- ls_algorithm_plugin_sdk-0.2.5/tests/test_deployment.py +90 -0
- ls_algorithm_plugin_sdk-0.2.5/tests/test_models.py +97 -0
- ls_algorithm_plugin_sdk-0.2.5/tests/test_registration.py +72 -0
- ls_algorithm_plugin_sdk-0.2.5/tests/test_release.py +60 -0
- ls_algorithm_plugin_sdk-0.2.5/tests/test_runner.py +254 -0
- ls_algorithm_plugin_sdk-0.2.5/tests/test_sdk_automation.py +50 -0
- ls_algorithm_plugin_sdk-0.2.5/tests/test_service.py +300 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ls-algorithm-plugin-sdk
|
|
3
|
+
Version: 0.2.5
|
|
4
|
+
Summary: Protocol-independent runtime SDK for dataset algorithms
|
|
5
|
+
Author: Ling Robotics
|
|
6
|
+
License: Proprietary
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Provides-Extra: service
|
|
10
|
+
Requires-Dist: fastapi<1,>=0.110; extra == "service"
|
|
11
|
+
Requires-Dist: pydantic<3,>=2.0; extra == "service"
|
|
12
|
+
Requires-Dist: uvicorn[standard]<1,>=0.29; extra == "service"
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
15
|
+
|
|
16
|
+
# Algorithm Plugin SDK
|
|
17
|
+
|
|
18
|
+
算法仓库只实现一个 `Algorithm` 类并声明 entry point。SDK
|
|
19
|
+
统一提供单次运行、WebUI、HTTP service、release manifest、compute 注册、心跳以及裸机进程管理。
|
|
20
|
+
算法仓库不需要 Dockerfile、Web 框架代码或 service 启停脚本。
|
|
21
|
+
|
|
22
|
+
## 算法侧最小接口
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from algorithm_plugin_sdk import Algorithm
|
|
26
|
+
|
|
27
|
+
class MyAlgorithm(Algorithm):
|
|
28
|
+
@classmethod
|
|
29
|
+
def metadata(cls): ...
|
|
30
|
+
def execute(self, request, context): ...
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
算法包声明 `algorithm_plugin_sdk.algorithms` entry point,并在仓库根目录发布只读的
|
|
34
|
+
`release-manifest.json`。同一个 `execute()` 会被所有运行方式复用。
|
|
35
|
+
|
|
36
|
+
## 单次运行
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
algorithm-plugin run camera-space-mano \
|
|
40
|
+
--input '{"dataset":"/data/input"}' \
|
|
41
|
+
--output-dir /data/output
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 一次生成、一次启动、一次停止
|
|
45
|
+
|
|
46
|
+
在算法仓库根目录执行:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
algorithm-plugin config \
|
|
50
|
+
--compute-url http://compute:5180 \
|
|
51
|
+
--api-key "$LDP_INTERNAL_API_KEY" \
|
|
52
|
+
--public-url http://10.0.0.4:9000 \
|
|
53
|
+
--input-root /data/jobs/input \
|
|
54
|
+
--workspace-root /data/jobs/workspace \
|
|
55
|
+
--cluster production \
|
|
56
|
+
--namespace camera-space-mano \
|
|
57
|
+
--node-name 10.0.0.4 \
|
|
58
|
+
--gpu-ids 0
|
|
59
|
+
|
|
60
|
+
algorithm-plugin start
|
|
61
|
+
algorithm-plugin stop
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`gpu_ids` 属于部署配置,不由 `/v1/executions` 请求提供。SDK 启动服务后会将配置的
|
|
65
|
+
GPU IDs 自动注入每个 `AlgorithmRequest`。
|
|
66
|
+
|
|
67
|
+
`config` 自动发现当前仓库和唯一 Algorithm entry point,并从 `release-manifest.json`
|
|
68
|
+
补齐 algorithm type、version、implementation digest、build revision、schema、启动入口、
|
|
69
|
+
PID 和日志路径。生成的 `algorithm-plugin.json` 权限为 `0600`。开发环境可使用
|
|
70
|
+
`algorithm-plugin config --local` 跳过 compute 注册。
|
|
71
|
+
|
|
72
|
+
`start` 默认在后台启动 `0.0.0.0:9000`,同时提供 `/ui/` 和 `/v1/*`,自动注册并每
|
|
73
|
+
5 秒心跳。日志写到 `.algorithm-plugin/service.log`。`stop` 只终止 PID、启动时间和命令行
|
|
74
|
+
均匹配当前配置的 SDK 进程,避免误杀复用 PID 的其他进程。
|
|
75
|
+
|
|
76
|
+
需要前台运行(例如 systemd)时仍可使用:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
algorithm-plugin serve camera-space-mano --port 9000 --webui
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 安装与测试
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
python -m pip install '.[service]'
|
|
86
|
+
python -m unittest discover -s tests -v
|
|
87
|
+
```
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Algorithm Plugin SDK
|
|
2
|
+
|
|
3
|
+
算法仓库只实现一个 `Algorithm` 类并声明 entry point。SDK
|
|
4
|
+
统一提供单次运行、WebUI、HTTP service、release manifest、compute 注册、心跳以及裸机进程管理。
|
|
5
|
+
算法仓库不需要 Dockerfile、Web 框架代码或 service 启停脚本。
|
|
6
|
+
|
|
7
|
+
## 算法侧最小接口
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from algorithm_plugin_sdk import Algorithm
|
|
11
|
+
|
|
12
|
+
class MyAlgorithm(Algorithm):
|
|
13
|
+
@classmethod
|
|
14
|
+
def metadata(cls): ...
|
|
15
|
+
def execute(self, request, context): ...
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
算法包声明 `algorithm_plugin_sdk.algorithms` entry point,并在仓库根目录发布只读的
|
|
19
|
+
`release-manifest.json`。同一个 `execute()` 会被所有运行方式复用。
|
|
20
|
+
|
|
21
|
+
## 单次运行
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
algorithm-plugin run camera-space-mano \
|
|
25
|
+
--input '{"dataset":"/data/input"}' \
|
|
26
|
+
--output-dir /data/output
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 一次生成、一次启动、一次停止
|
|
30
|
+
|
|
31
|
+
在算法仓库根目录执行:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
algorithm-plugin config \
|
|
35
|
+
--compute-url http://compute:5180 \
|
|
36
|
+
--api-key "$LDP_INTERNAL_API_KEY" \
|
|
37
|
+
--public-url http://10.0.0.4:9000 \
|
|
38
|
+
--input-root /data/jobs/input \
|
|
39
|
+
--workspace-root /data/jobs/workspace \
|
|
40
|
+
--cluster production \
|
|
41
|
+
--namespace camera-space-mano \
|
|
42
|
+
--node-name 10.0.0.4 \
|
|
43
|
+
--gpu-ids 0
|
|
44
|
+
|
|
45
|
+
algorithm-plugin start
|
|
46
|
+
algorithm-plugin stop
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`gpu_ids` 属于部署配置,不由 `/v1/executions` 请求提供。SDK 启动服务后会将配置的
|
|
50
|
+
GPU IDs 自动注入每个 `AlgorithmRequest`。
|
|
51
|
+
|
|
52
|
+
`config` 自动发现当前仓库和唯一 Algorithm entry point,并从 `release-manifest.json`
|
|
53
|
+
补齐 algorithm type、version、implementation digest、build revision、schema、启动入口、
|
|
54
|
+
PID 和日志路径。生成的 `algorithm-plugin.json` 权限为 `0600`。开发环境可使用
|
|
55
|
+
`algorithm-plugin config --local` 跳过 compute 注册。
|
|
56
|
+
|
|
57
|
+
`start` 默认在后台启动 `0.0.0.0:9000`,同时提供 `/ui/` 和 `/v1/*`,自动注册并每
|
|
58
|
+
5 秒心跳。日志写到 `.algorithm-plugin/service.log`。`stop` 只终止 PID、启动时间和命令行
|
|
59
|
+
均匹配当前配置的 SDK 进程,避免误杀复用 PID 的其他进程。
|
|
60
|
+
|
|
61
|
+
需要前台运行(例如 systemd)时仍可使用:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
algorithm-plugin serve camera-space-mano --port 9000 --webui
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 安装与测试
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
python -m pip install '.[service]'
|
|
71
|
+
python -m unittest discover -s tests -v
|
|
72
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ls-algorithm-plugin-sdk"
|
|
7
|
+
version = "0.2.5"
|
|
8
|
+
description = "Protocol-independent runtime SDK for dataset algorithms"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {text = "Proprietary"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Ling Robotics"},
|
|
14
|
+
]
|
|
15
|
+
dependencies = []
|
|
16
|
+
|
|
17
|
+
[project.optional-dependencies]
|
|
18
|
+
service = [
|
|
19
|
+
"fastapi>=0.110,<1",
|
|
20
|
+
"pydantic>=2.0,<3",
|
|
21
|
+
"uvicorn[standard]>=0.29,<1",
|
|
22
|
+
]
|
|
23
|
+
dev = [
|
|
24
|
+
"build>=1.2",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
algorithm-plugin = "algorithm_plugin_sdk.cli:main"
|
|
29
|
+
|
|
30
|
+
[tool.setuptools]
|
|
31
|
+
package-dir = {"" = "src"}
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.packages.find]
|
|
34
|
+
where = ["src"]
|
|
35
|
+
|
|
36
|
+
[tool.setuptools.package-data]
|
|
37
|
+
"algorithm_plugin_sdk.webui" = ["*.html", "*.css", "*.js"]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from .algorithm import Algorithm
|
|
2
|
+
from .context import (
|
|
3
|
+
DatasetProgress,
|
|
4
|
+
EpisodeProgress,
|
|
5
|
+
ExecutionContext,
|
|
6
|
+
ProgressSnapshot
|
|
7
|
+
)
|
|
8
|
+
from .deployment import DeploymentConfig
|
|
9
|
+
from .errors import (
|
|
10
|
+
AlgorithmLoadError,
|
|
11
|
+
AlgorithmPluginError,
|
|
12
|
+
ExecutionCancelled,
|
|
13
|
+
InvalidAlgorithmResult,
|
|
14
|
+
InvalidRequest
|
|
15
|
+
)
|
|
16
|
+
from .loader import load_algorithm
|
|
17
|
+
from .models import (
|
|
18
|
+
AlgorithmInput,
|
|
19
|
+
AlgorithmMetadata,
|
|
20
|
+
AlgorithmRequest,
|
|
21
|
+
AlgorithmResult,
|
|
22
|
+
DatasetResult
|
|
23
|
+
)
|
|
24
|
+
from .registration import PluginRegistrationAgent, RegistrationSettings
|
|
25
|
+
from .release import ReleaseManifest
|
|
26
|
+
from .runner import AlgorithmRunner
|
|
27
|
+
from .service import ExecutionManager
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"Algorithm",
|
|
31
|
+
"AlgorithmInput",
|
|
32
|
+
"AlgorithmLoadError",
|
|
33
|
+
"AlgorithmMetadata",
|
|
34
|
+
"AlgorithmPluginError",
|
|
35
|
+
"AlgorithmRequest",
|
|
36
|
+
"AlgorithmResult",
|
|
37
|
+
"AlgorithmRunner",
|
|
38
|
+
"DeploymentConfig",
|
|
39
|
+
"DatasetProgress",
|
|
40
|
+
"DatasetResult",
|
|
41
|
+
"EpisodeProgress",
|
|
42
|
+
"ExecutionCancelled",
|
|
43
|
+
"ExecutionContext",
|
|
44
|
+
"ExecutionManager",
|
|
45
|
+
"InvalidAlgorithmResult",
|
|
46
|
+
"InvalidRequest",
|
|
47
|
+
"PluginRegistrationAgent",
|
|
48
|
+
"ProgressSnapshot",
|
|
49
|
+
"RegistrationSettings",
|
|
50
|
+
"ReleaseManifest",
|
|
51
|
+
"load_algorithm",
|
|
52
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
|
|
5
|
+
from .context import ExecutionContext
|
|
6
|
+
from .models import AlgorithmMetadata, AlgorithmRequest, AlgorithmResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Algorithm(ABC):
|
|
10
|
+
"""The only runtime contract an algorithm package must implement."""
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
@abstractmethod
|
|
14
|
+
def metadata(cls) -> AlgorithmMetadata:
|
|
15
|
+
"""Describe the algorithm without loading models or datasets."""
|
|
16
|
+
|
|
17
|
+
def startup(self) -> None:
|
|
18
|
+
"""Initialize process-level resources before the first execution."""
|
|
19
|
+
|
|
20
|
+
@abstractmethod
|
|
21
|
+
def execute(
|
|
22
|
+
self,
|
|
23
|
+
request: AlgorithmRequest,
|
|
24
|
+
context: ExecutionContext,
|
|
25
|
+
) -> AlgorithmResult:
|
|
26
|
+
"""Run all datasets and return their final results.
|
|
27
|
+
|
|
28
|
+
Algorithms own dataset/GPU scheduling and optional merging. Concurrent
|
|
29
|
+
workers report live progress through ``context.report_progress()``.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def shutdown(self) -> None:
|
|
33
|
+
"""Release process-level resources during service shutdown."""
|