isagellm-core 0.2.2.6__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.
- isagellm_core-0.2.2.6/MANIFEST.in +8 -0
- isagellm_core-0.2.2.6/PKG-INFO +340 -0
- isagellm_core-0.2.2.6/README.md +314 -0
- isagellm_core-0.2.2.6/pyproject.toml +58 -0
- isagellm_core-0.2.2.6/setup.cfg +4 -0
- isagellm_core-0.2.2.6/setup.py +9 -0
- isagellm_core-0.2.2.6/src/isagellm_core.egg-info/PKG-INFO +340 -0
- isagellm_core-0.2.2.6/src/isagellm_core.egg-info/SOURCES.txt +60 -0
- isagellm_core-0.2.2.6/src/isagellm_core.egg-info/dependency_links.txt +1 -0
- isagellm_core-0.2.2.6/src/isagellm_core.egg-info/entry_points.txt +3 -0
- isagellm_core-0.2.2.6/src/isagellm_core.egg-info/requires.txt +13 -0
- isagellm_core-0.2.2.6/src/isagellm_core.egg-info/top_level.txt +1 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__init__.py +114 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__init__.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__main__.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__pycache__/__init__.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__pycache__/base_engine.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__pycache__/config.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__pycache__/demo.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__pycache__/engine.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__pycache__/engine_factory.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__pycache__/factory.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__pycache__/health.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__pycache__/mock_engine.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__pycache__/plugins.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__pycache__/runner.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/__pycache__/workload.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/config.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/demo.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engine.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engine_factory.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/__init__.py +33 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/__init__.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/__pycache__/__init__.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/__pycache__/cpu.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/__pycache__/embedding.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/__pycache__/hf_cuda.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/__pycache__/mock.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/__pycache__/pytorch.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/__pycache__/pytorch_engine.cpython-311.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/cpu.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/embedding.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/hf_cuda.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/pytorch.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/engines/pytorch_engine.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/factory.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/health.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/plugins.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/py.typed +2 -0
- isagellm_core-0.2.2.6/src/sagellm_core/runner.pyc +0 -0
- isagellm_core-0.2.2.6/src/sagellm_core/workload.pyc +0 -0
- isagellm_core-0.2.2.6/tests/test_ci_smoke.py +191 -0
- isagellm_core-0.2.2.6/tests/test_config.py +151 -0
- isagellm_core-0.2.2.6/tests/test_cpu_engine_contract.py +277 -0
- isagellm_core-0.2.2.6/tests/test_cpu_engine_error_handling.py +230 -0
- isagellm_core-0.2.2.6/tests/test_e2e_cpu_integration.py +234 -0
- isagellm_core-0.2.2.6/tests/test_engine.py +289 -0
- isagellm_core-0.2.2.6/tests/test_engine_behavior_parity.py +154 -0
- isagellm_core-0.2.2.6/tests/test_engine_contract.py +361 -0
- isagellm_core-0.2.2.6/tests/test_engine_contract_simplified.py +73 -0
- isagellm_core-0.2.2.6/tests/test_pytorch_engine.py +81 -0
- isagellm_core-0.2.2.6/tests/test_task0_10_workload.py +148 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: isagellm-core
|
|
3
|
+
Version: 0.2.2.6
|
|
4
|
+
Summary: sageLLM core runtime (config/observability/registries), plugin-ready
|
|
5
|
+
Author: IntelliStream Team
|
|
6
|
+
License: Proprietary - IntelliStream
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Requires-Python: ==3.11.*
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: pydantic>=2.0.0
|
|
15
|
+
Requires-Dist: pyyaml>=6.0.0
|
|
16
|
+
Requires-Dist: isagellm-protocol<0.2.0,>=0.1.0
|
|
17
|
+
Requires-Dist: isagellm-backend<0.3.0,>=0.2.0.0
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
20
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest-timeout>=2.0.0; extra == "dev"
|
|
22
|
+
Requires-Dist: ruff>=0.8.0; extra == "dev"
|
|
23
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
24
|
+
Requires-Dist: types-PyYAML>=6.0.0; extra == "dev"
|
|
25
|
+
Requires-Dist: pre-commit>=3.0.0; extra == "dev"
|
|
26
|
+
|
|
27
|
+
# sagellm-core
|
|
28
|
+
|
|
29
|
+
## Protocol Compliance (Mandatory)
|
|
30
|
+
|
|
31
|
+
- MUST follow Protocol v0.1: https://github.com/intellistream/sagellm-docs/blob/main/docs/specs/protocol_v0.1.md
|
|
32
|
+
- Any globally shared definitions (fields, error codes, metrics, IDs, schemas) MUST be added to Protocol first.
|
|
33
|
+
|
|
34
|
+
[](https://github.com/intellistream/sagellm-core/actions/workflows/ci.yml)
|
|
35
|
+
[](https://pypi.org/project/isagellm-core/)
|
|
36
|
+
[](https://pypi.org/project/isagellm-core/)
|
|
37
|
+
[](https://github.com/intellistream/sagellm-core/blob/main/LICENSE)
|
|
38
|
+
[](https://github.com/astral-sh/ruff)
|
|
39
|
+
|
|
40
|
+
sageLLM Core - 引擎协调层与运行时系统
|
|
41
|
+
|
|
42
|
+
## 架构定位
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
46
|
+
│ sagellm-core (引擎协调层) ← 本仓库 │
|
|
47
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
48
|
+
│ │ Engine Abstraction (BaseEngine, EngineFactory) │ │
|
|
49
|
+
│ │ • CPUEngine, HFCudaEngine │ │
|
|
50
|
+
│ │ • 自描述架构 (is_available, priority) │ │
|
|
51
|
+
│ │ • 引擎自动发现与注册 │ │
|
|
52
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
53
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
54
|
+
│ │ Configuration System (config.py) │ │
|
|
55
|
+
│ │ • YAML/JSON 配置解析 │ │
|
|
56
|
+
│ │ • Pydantic v2 类型验证 │ │
|
|
57
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
58
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
59
|
+
│ │ Demo Runner (runner.py) │ │
|
|
60
|
+
│ │ • 协调 backend + engine + workload │ │
|
|
61
|
+
│ │ • M1 Demo Contract 验证 │ │
|
|
62
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
63
|
+
├─────────────────────────────────────────────────────────────┤
|
|
64
|
+
│ sagellm-backend (硬件抽象层) │
|
|
65
|
+
│ • BackendProvider (CPU/CUDA/Ascend) │
|
|
66
|
+
│ • Stream/Event/KVBlock 管理 │
|
|
67
|
+
└─────────────────────────────────────────────────────────────┘
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**职责分离**:
|
|
71
|
+
- ❌ **Backend 不再包含**:BaseEngine, EngineFactory(已移至 core)
|
|
72
|
+
- ✅ **Core 负责**:引擎接口、工厂、运行时、配置、协调
|
|
73
|
+
- ✅ **Backend 负责**:硬件抽象、设备管理、内存原语
|
|
74
|
+
|
|
75
|
+
## Features
|
|
76
|
+
|
|
77
|
+
- 🔧 引擎抽象层与自描述架构
|
|
78
|
+
- 🏭 EngineFactory - 支持自动发现与优先级选择
|
|
79
|
+
- 🎯 内置引擎实现(CPU/CUDA/Embedding)
|
|
80
|
+
- 🔌 插件系统 - 扩展引擎与后端
|
|
81
|
+
- 📊 Demo Runner - M1 验证框架
|
|
82
|
+
- ⚙️ 配置系统 - YAML/JSON + Pydantic v2
|
|
83
|
+
- ✅ CPU-First - 无 GPU 测试支持
|
|
84
|
+
|
|
85
|
+
## 安装
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# 从 PyPI 安装(自动安装 protocol + backend 依赖)
|
|
89
|
+
pip install isagellm-core
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 🚀 开发者快速开始
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
git clone git@github.com:intellistream/sagellm-core.git
|
|
96
|
+
cd sagellm-core
|
|
97
|
+
./quickstart.sh # 一键安装开发环境(含依赖)
|
|
98
|
+
|
|
99
|
+
# 或手动安装
|
|
100
|
+
pip install -e ".[dev]"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
运行测试:
|
|
104
|
+
```bash
|
|
105
|
+
pytest tests/ -v
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
运行 Demo(CPU 模式):
|
|
109
|
+
```bash
|
|
110
|
+
python -m sagellm_core.demo --segments short
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
> 💡 **提示**:`isagellm-protocol` 和 `isagellm-backend` 会自动从 PyPI 安装。
|
|
114
|
+
> 如需本地联调:
|
|
115
|
+
> ```bash
|
|
116
|
+
> pip install -e ../sagellm-protocol
|
|
117
|
+
> pip install -e ../sagellm-backend
|
|
118
|
+
> ```
|
|
119
|
+
|
|
120
|
+
## Configuration System
|
|
121
|
+
|
|
122
|
+
### 使用方法
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from sagellm_core import load_config, create_backend, create_engine
|
|
126
|
+
|
|
127
|
+
# 从 YAML/JSON 加载配置
|
|
128
|
+
config = load_config("config.yaml")
|
|
129
|
+
|
|
130
|
+
# 创建 backend 和 engine(通过插件发现)
|
|
131
|
+
backend = create_backend(config.backend)
|
|
132
|
+
engine = create_engine(config.engine, backend)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Configuration Structure
|
|
136
|
+
|
|
137
|
+
Main configuration components:
|
|
138
|
+
- `BackendConfig`: Device and backend settings
|
|
139
|
+
- `EngineConfig`: Inference engine configuration
|
|
140
|
+
- `WorkloadConfig`: Workload parameters
|
|
141
|
+
- `OutputConfig`: Output paths and logging
|
|
142
|
+
- `DemoConfig`: Top-level demo configuration
|
|
143
|
+
|
|
144
|
+
### 配置示例
|
|
145
|
+
|
|
146
|
+
#### 快速开始
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# CPU 模式(无需 GPU)
|
|
150
|
+
python -m sagellm.demo --config examples/config_cpu.yaml
|
|
151
|
+
|
|
152
|
+
# CUDA 生产模式
|
|
153
|
+
python -m sagellm.demo --config examples/config_cuda.yaml
|
|
154
|
+
|
|
155
|
+
# 昇腾生产模式
|
|
156
|
+
python -m sagellm.demo --config examples/config_ascend.yaml
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### 示例配置文件
|
|
160
|
+
|
|
161
|
+
- [config_cpu.yaml](examples/config_cpu.yaml) - CPU 模式(CI/开发)
|
|
162
|
+
- [config_cuda.yaml](examples/config_cuda.yaml) - CUDA 生产模式
|
|
163
|
+
- [config_ascend.yaml](examples/config_ascend.yaml) - 昇腾生产模式
|
|
164
|
+
- [config_minimal.json](examples/config_minimal.json) - 最小 JSON 配置
|
|
165
|
+
|
|
166
|
+
更多信息参见 [examples/README.md](examples/README.md)
|
|
167
|
+
|
|
168
|
+
### 配置格式
|
|
169
|
+
|
|
170
|
+
支持 YAML(推荐)和 JSON 格式:
|
|
171
|
+
|
|
172
|
+
```yaml
|
|
173
|
+
backend:
|
|
174
|
+
kind: cpu
|
|
175
|
+
engine:
|
|
176
|
+
kind: cpu
|
|
177
|
+
model: sshleifer/tiny-gpt2
|
|
178
|
+
workload:
|
|
179
|
+
segments: [short, long, stress]
|
|
180
|
+
concurrency: 4
|
|
181
|
+
output:
|
|
182
|
+
metrics_path: ./metrics.json
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### 插件解析
|
|
186
|
+
|
|
187
|
+
当配置指定的 backend/engine kind 未安装时,会抛出 `PluginResolutionError`:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from sagellm_core import create_backend, BackendConfig, PluginResolutionError
|
|
191
|
+
|
|
192
|
+
try:
|
|
193
|
+
backend = create_backend(BackendConfig(kind="ascend_cann", device="npu:0"))
|
|
194
|
+
except PluginResolutionError as e:
|
|
195
|
+
print(f"错误: {e}")
|
|
196
|
+
# 输出: No implementation found for sagellm.backends kind='ascend_cann'.
|
|
197
|
+
# Install hint: pip install isagellm-backend-ascend_cann
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Demo Runner CLI (Task0.08)
|
|
201
|
+
|
|
202
|
+
sagellm-core 提供了 Demo Runner CLI,用于执行 M1 Demo Contract 验证:
|
|
203
|
+
|
|
204
|
+
### 用法
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# 使用配置文件运行
|
|
208
|
+
python -m sagellm_core.demo --config examples/demo_config.yaml
|
|
209
|
+
|
|
210
|
+
# 强制使用 CPU 模式(覆盖配置文件)
|
|
211
|
+
python -m sagellm_core.demo --config config.yaml --backend cpu
|
|
212
|
+
|
|
213
|
+
# 覆盖 workload 段选择
|
|
214
|
+
python -m sagellm_core.demo --config config.yaml --segments short,long
|
|
215
|
+
|
|
216
|
+
# 覆盖输出路径
|
|
217
|
+
python -m sagellm_core.demo --config config.yaml --output /tmp/metrics.json
|
|
218
|
+
|
|
219
|
+
# 启用 streaming 模式和详细日志
|
|
220
|
+
python -m sagellm_core.demo --config config.yaml --stream --verbose
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### 示例配置
|
|
224
|
+
|
|
225
|
+
参见 [examples/demo_config.yaml](examples/demo_config.yaml):
|
|
226
|
+
|
|
227
|
+
```yaml
|
|
228
|
+
backend:
|
|
229
|
+
kind: cpu
|
|
230
|
+
device: cpu
|
|
231
|
+
|
|
232
|
+
engine:
|
|
233
|
+
kind: cpu
|
|
234
|
+
model: sshleifer/tiny-gpt2
|
|
235
|
+
|
|
236
|
+
workload:
|
|
237
|
+
segments: [short, long, stress]
|
|
238
|
+
concurrency: 4
|
|
239
|
+
kv_budget_tokens: 8192
|
|
240
|
+
|
|
241
|
+
output:
|
|
242
|
+
metrics_path: ./output/metrics.json
|
|
243
|
+
report_path: ./output/report.md
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Development Guide
|
|
247
|
+
|
|
248
|
+
### 快速开始
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
# 克隆仓库
|
|
252
|
+
git clone https://github.com/intellistream/sagellm-core.git
|
|
253
|
+
cd sagellm-core
|
|
254
|
+
|
|
255
|
+
# 安装开发依赖
|
|
256
|
+
pip install -e ".[dev]"
|
|
257
|
+
|
|
258
|
+
# 安装 pre-commit hooks
|
|
259
|
+
pre-commit install
|
|
260
|
+
|
|
261
|
+
# 验证环境
|
|
262
|
+
pytest tests/ -v
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Testing and Quality
|
|
266
|
+
|
|
267
|
+
#### Pre-commit Hooks
|
|
268
|
+
|
|
269
|
+
安装后,每次 `git commit` 会自动运行:
|
|
270
|
+
- **Ruff**: 代码格式化 + Lint 检查
|
|
271
|
+
- **Mypy**: 静态类型检查
|
|
272
|
+
- **YAML/JSON**: 配置文件验证
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
# 手动运行所有 hooks
|
|
276
|
+
pre-commit run --all-files
|
|
277
|
+
|
|
278
|
+
# 绕过 hooks(紧急情况)
|
|
279
|
+
git commit --no-verify
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
#### Running Tests
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
# Run all tests
|
|
286
|
+
pytest tests/ -v
|
|
287
|
+
|
|
288
|
+
# Run specific test module
|
|
289
|
+
pytest tests/unit/test_demo.py -v
|
|
290
|
+
|
|
291
|
+
# Generate coverage report
|
|
292
|
+
pytest tests/ --cov=sagellm_core --cov-report=html
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
#### Continuous Integration
|
|
296
|
+
|
|
297
|
+
GitHub Actions automatically runs on each PR:
|
|
298
|
+
- Code linting and formatting checks
|
|
299
|
+
- Tests across Python 3.10, 3.11, 3.12
|
|
300
|
+
- Package build verification
|
|
301
|
+
|
|
302
|
+
### Code Style
|
|
303
|
+
|
|
304
|
+
This project uses:
|
|
305
|
+
- **Ruff** for formatting and linting
|
|
306
|
+
- **Mypy** for type checking
|
|
307
|
+
- **Type hints** are required for all functions
|
|
308
|
+
|
|
309
|
+
For detailed guidelines, see [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
310
|
+
|
|
311
|
+
### 代码检查
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
# 格式化代码
|
|
315
|
+
ruff format .
|
|
316
|
+
|
|
317
|
+
# Lint 检查
|
|
318
|
+
ruff check .
|
|
319
|
+
|
|
320
|
+
# 类型检查
|
|
321
|
+
mypy src/sagellm_core
|
|
322
|
+
|
|
323
|
+
# 一键检查所有
|
|
324
|
+
pre-commit run --all-files
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
## 依赖
|
|
328
|
+
|
|
329
|
+
- `pydantic>=2.0.0`: 配置校验
|
|
330
|
+
- `pyyaml>=6.0.0`: YAML 配置支持
|
|
331
|
+
- `isagellm-protocol>=0.1.0,<0.2.0`: 协议定义(Level 0)
|
|
332
|
+
- `isagellm-backend>=0.1.0,<0.2.0`: 后端抽象(Level 1)
|
|
333
|
+
|
|
334
|
+
## Related Packages
|
|
335
|
+
|
|
336
|
+
- `isagellm-protocol` - Protocol definitions
|
|
337
|
+
- `isagellm-backend` - Backend abstraction layer
|
|
338
|
+
- `isagellm` - Main package with CLI
|
|
339
|
+
|
|
340
|
+
For more packages, see the [sageLLM ecosystem](https://github.com/intellistream/sagellm)
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
# sagellm-core
|
|
2
|
+
|
|
3
|
+
## Protocol Compliance (Mandatory)
|
|
4
|
+
|
|
5
|
+
- MUST follow Protocol v0.1: https://github.com/intellistream/sagellm-docs/blob/main/docs/specs/protocol_v0.1.md
|
|
6
|
+
- Any globally shared definitions (fields, error codes, metrics, IDs, schemas) MUST be added to Protocol first.
|
|
7
|
+
|
|
8
|
+
[](https://github.com/intellistream/sagellm-core/actions/workflows/ci.yml)
|
|
9
|
+
[](https://pypi.org/project/isagellm-core/)
|
|
10
|
+
[](https://pypi.org/project/isagellm-core/)
|
|
11
|
+
[](https://github.com/intellistream/sagellm-core/blob/main/LICENSE)
|
|
12
|
+
[](https://github.com/astral-sh/ruff)
|
|
13
|
+
|
|
14
|
+
sageLLM Core - 引擎协调层与运行时系统
|
|
15
|
+
|
|
16
|
+
## 架构定位
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
20
|
+
│ sagellm-core (引擎协调层) ← 本仓库 │
|
|
21
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
22
|
+
│ │ Engine Abstraction (BaseEngine, EngineFactory) │ │
|
|
23
|
+
│ │ • CPUEngine, HFCudaEngine │ │
|
|
24
|
+
│ │ • 自描述架构 (is_available, priority) │ │
|
|
25
|
+
│ │ • 引擎自动发现与注册 │ │
|
|
26
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
27
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
28
|
+
│ │ Configuration System (config.py) │ │
|
|
29
|
+
│ │ • YAML/JSON 配置解析 │ │
|
|
30
|
+
│ │ • Pydantic v2 类型验证 │ │
|
|
31
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
32
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
33
|
+
│ │ Demo Runner (runner.py) │ │
|
|
34
|
+
│ │ • 协调 backend + engine + workload │ │
|
|
35
|
+
│ │ • M1 Demo Contract 验证 │ │
|
|
36
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
37
|
+
├─────────────────────────────────────────────────────────────┤
|
|
38
|
+
│ sagellm-backend (硬件抽象层) │
|
|
39
|
+
│ • BackendProvider (CPU/CUDA/Ascend) │
|
|
40
|
+
│ • Stream/Event/KVBlock 管理 │
|
|
41
|
+
└─────────────────────────────────────────────────────────────┘
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**职责分离**:
|
|
45
|
+
- ❌ **Backend 不再包含**:BaseEngine, EngineFactory(已移至 core)
|
|
46
|
+
- ✅ **Core 负责**:引擎接口、工厂、运行时、配置、协调
|
|
47
|
+
- ✅ **Backend 负责**:硬件抽象、设备管理、内存原语
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- 🔧 引擎抽象层与自描述架构
|
|
52
|
+
- 🏭 EngineFactory - 支持自动发现与优先级选择
|
|
53
|
+
- 🎯 内置引擎实现(CPU/CUDA/Embedding)
|
|
54
|
+
- 🔌 插件系统 - 扩展引擎与后端
|
|
55
|
+
- 📊 Demo Runner - M1 验证框架
|
|
56
|
+
- ⚙️ 配置系统 - YAML/JSON + Pydantic v2
|
|
57
|
+
- ✅ CPU-First - 无 GPU 测试支持
|
|
58
|
+
|
|
59
|
+
## 安装
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# 从 PyPI 安装(自动安装 protocol + backend 依赖)
|
|
63
|
+
pip install isagellm-core
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 🚀 开发者快速开始
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
git clone git@github.com:intellistream/sagellm-core.git
|
|
70
|
+
cd sagellm-core
|
|
71
|
+
./quickstart.sh # 一键安装开发环境(含依赖)
|
|
72
|
+
|
|
73
|
+
# 或手动安装
|
|
74
|
+
pip install -e ".[dev]"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
运行测试:
|
|
78
|
+
```bash
|
|
79
|
+
pytest tests/ -v
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
运行 Demo(CPU 模式):
|
|
83
|
+
```bash
|
|
84
|
+
python -m sagellm_core.demo --segments short
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
> 💡 **提示**:`isagellm-protocol` 和 `isagellm-backend` 会自动从 PyPI 安装。
|
|
88
|
+
> 如需本地联调:
|
|
89
|
+
> ```bash
|
|
90
|
+
> pip install -e ../sagellm-protocol
|
|
91
|
+
> pip install -e ../sagellm-backend
|
|
92
|
+
> ```
|
|
93
|
+
|
|
94
|
+
## Configuration System
|
|
95
|
+
|
|
96
|
+
### 使用方法
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from sagellm_core import load_config, create_backend, create_engine
|
|
100
|
+
|
|
101
|
+
# 从 YAML/JSON 加载配置
|
|
102
|
+
config = load_config("config.yaml")
|
|
103
|
+
|
|
104
|
+
# 创建 backend 和 engine(通过插件发现)
|
|
105
|
+
backend = create_backend(config.backend)
|
|
106
|
+
engine = create_engine(config.engine, backend)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Configuration Structure
|
|
110
|
+
|
|
111
|
+
Main configuration components:
|
|
112
|
+
- `BackendConfig`: Device and backend settings
|
|
113
|
+
- `EngineConfig`: Inference engine configuration
|
|
114
|
+
- `WorkloadConfig`: Workload parameters
|
|
115
|
+
- `OutputConfig`: Output paths and logging
|
|
116
|
+
- `DemoConfig`: Top-level demo configuration
|
|
117
|
+
|
|
118
|
+
### 配置示例
|
|
119
|
+
|
|
120
|
+
#### 快速开始
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# CPU 模式(无需 GPU)
|
|
124
|
+
python -m sagellm.demo --config examples/config_cpu.yaml
|
|
125
|
+
|
|
126
|
+
# CUDA 生产模式
|
|
127
|
+
python -m sagellm.demo --config examples/config_cuda.yaml
|
|
128
|
+
|
|
129
|
+
# 昇腾生产模式
|
|
130
|
+
python -m sagellm.demo --config examples/config_ascend.yaml
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### 示例配置文件
|
|
134
|
+
|
|
135
|
+
- [config_cpu.yaml](examples/config_cpu.yaml) - CPU 模式(CI/开发)
|
|
136
|
+
- [config_cuda.yaml](examples/config_cuda.yaml) - CUDA 生产模式
|
|
137
|
+
- [config_ascend.yaml](examples/config_ascend.yaml) - 昇腾生产模式
|
|
138
|
+
- [config_minimal.json](examples/config_minimal.json) - 最小 JSON 配置
|
|
139
|
+
|
|
140
|
+
更多信息参见 [examples/README.md](examples/README.md)
|
|
141
|
+
|
|
142
|
+
### 配置格式
|
|
143
|
+
|
|
144
|
+
支持 YAML(推荐)和 JSON 格式:
|
|
145
|
+
|
|
146
|
+
```yaml
|
|
147
|
+
backend:
|
|
148
|
+
kind: cpu
|
|
149
|
+
engine:
|
|
150
|
+
kind: cpu
|
|
151
|
+
model: sshleifer/tiny-gpt2
|
|
152
|
+
workload:
|
|
153
|
+
segments: [short, long, stress]
|
|
154
|
+
concurrency: 4
|
|
155
|
+
output:
|
|
156
|
+
metrics_path: ./metrics.json
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### 插件解析
|
|
160
|
+
|
|
161
|
+
当配置指定的 backend/engine kind 未安装时,会抛出 `PluginResolutionError`:
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
from sagellm_core import create_backend, BackendConfig, PluginResolutionError
|
|
165
|
+
|
|
166
|
+
try:
|
|
167
|
+
backend = create_backend(BackendConfig(kind="ascend_cann", device="npu:0"))
|
|
168
|
+
except PluginResolutionError as e:
|
|
169
|
+
print(f"错误: {e}")
|
|
170
|
+
# 输出: No implementation found for sagellm.backends kind='ascend_cann'.
|
|
171
|
+
# Install hint: pip install isagellm-backend-ascend_cann
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Demo Runner CLI (Task0.08)
|
|
175
|
+
|
|
176
|
+
sagellm-core 提供了 Demo Runner CLI,用于执行 M1 Demo Contract 验证:
|
|
177
|
+
|
|
178
|
+
### 用法
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# 使用配置文件运行
|
|
182
|
+
python -m sagellm_core.demo --config examples/demo_config.yaml
|
|
183
|
+
|
|
184
|
+
# 强制使用 CPU 模式(覆盖配置文件)
|
|
185
|
+
python -m sagellm_core.demo --config config.yaml --backend cpu
|
|
186
|
+
|
|
187
|
+
# 覆盖 workload 段选择
|
|
188
|
+
python -m sagellm_core.demo --config config.yaml --segments short,long
|
|
189
|
+
|
|
190
|
+
# 覆盖输出路径
|
|
191
|
+
python -m sagellm_core.demo --config config.yaml --output /tmp/metrics.json
|
|
192
|
+
|
|
193
|
+
# 启用 streaming 模式和详细日志
|
|
194
|
+
python -m sagellm_core.demo --config config.yaml --stream --verbose
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### 示例配置
|
|
198
|
+
|
|
199
|
+
参见 [examples/demo_config.yaml](examples/demo_config.yaml):
|
|
200
|
+
|
|
201
|
+
```yaml
|
|
202
|
+
backend:
|
|
203
|
+
kind: cpu
|
|
204
|
+
device: cpu
|
|
205
|
+
|
|
206
|
+
engine:
|
|
207
|
+
kind: cpu
|
|
208
|
+
model: sshleifer/tiny-gpt2
|
|
209
|
+
|
|
210
|
+
workload:
|
|
211
|
+
segments: [short, long, stress]
|
|
212
|
+
concurrency: 4
|
|
213
|
+
kv_budget_tokens: 8192
|
|
214
|
+
|
|
215
|
+
output:
|
|
216
|
+
metrics_path: ./output/metrics.json
|
|
217
|
+
report_path: ./output/report.md
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Development Guide
|
|
221
|
+
|
|
222
|
+
### 快速开始
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# 克隆仓库
|
|
226
|
+
git clone https://github.com/intellistream/sagellm-core.git
|
|
227
|
+
cd sagellm-core
|
|
228
|
+
|
|
229
|
+
# 安装开发依赖
|
|
230
|
+
pip install -e ".[dev]"
|
|
231
|
+
|
|
232
|
+
# 安装 pre-commit hooks
|
|
233
|
+
pre-commit install
|
|
234
|
+
|
|
235
|
+
# 验证环境
|
|
236
|
+
pytest tests/ -v
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Testing and Quality
|
|
240
|
+
|
|
241
|
+
#### Pre-commit Hooks
|
|
242
|
+
|
|
243
|
+
安装后,每次 `git commit` 会自动运行:
|
|
244
|
+
- **Ruff**: 代码格式化 + Lint 检查
|
|
245
|
+
- **Mypy**: 静态类型检查
|
|
246
|
+
- **YAML/JSON**: 配置文件验证
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
# 手动运行所有 hooks
|
|
250
|
+
pre-commit run --all-files
|
|
251
|
+
|
|
252
|
+
# 绕过 hooks(紧急情况)
|
|
253
|
+
git commit --no-verify
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
#### Running Tests
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
# Run all tests
|
|
260
|
+
pytest tests/ -v
|
|
261
|
+
|
|
262
|
+
# Run specific test module
|
|
263
|
+
pytest tests/unit/test_demo.py -v
|
|
264
|
+
|
|
265
|
+
# Generate coverage report
|
|
266
|
+
pytest tests/ --cov=sagellm_core --cov-report=html
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### Continuous Integration
|
|
270
|
+
|
|
271
|
+
GitHub Actions automatically runs on each PR:
|
|
272
|
+
- Code linting and formatting checks
|
|
273
|
+
- Tests across Python 3.10, 3.11, 3.12
|
|
274
|
+
- Package build verification
|
|
275
|
+
|
|
276
|
+
### Code Style
|
|
277
|
+
|
|
278
|
+
This project uses:
|
|
279
|
+
- **Ruff** for formatting and linting
|
|
280
|
+
- **Mypy** for type checking
|
|
281
|
+
- **Type hints** are required for all functions
|
|
282
|
+
|
|
283
|
+
For detailed guidelines, see [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
284
|
+
|
|
285
|
+
### 代码检查
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
# 格式化代码
|
|
289
|
+
ruff format .
|
|
290
|
+
|
|
291
|
+
# Lint 检查
|
|
292
|
+
ruff check .
|
|
293
|
+
|
|
294
|
+
# 类型检查
|
|
295
|
+
mypy src/sagellm_core
|
|
296
|
+
|
|
297
|
+
# 一键检查所有
|
|
298
|
+
pre-commit run --all-files
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## 依赖
|
|
302
|
+
|
|
303
|
+
- `pydantic>=2.0.0`: 配置校验
|
|
304
|
+
- `pyyaml>=6.0.0`: YAML 配置支持
|
|
305
|
+
- `isagellm-protocol>=0.1.0,<0.2.0`: 协议定义(Level 0)
|
|
306
|
+
- `isagellm-backend>=0.1.0,<0.2.0`: 后端抽象(Level 1)
|
|
307
|
+
|
|
308
|
+
## Related Packages
|
|
309
|
+
|
|
310
|
+
- `isagellm-protocol` - Protocol definitions
|
|
311
|
+
- `isagellm-backend` - Backend abstraction layer
|
|
312
|
+
- `isagellm` - Main package with CLI
|
|
313
|
+
|
|
314
|
+
For more packages, see the [sageLLM ecosystem](https://github.com/intellistream/sagellm)
|