isagellm-core 0.1.0__cp311-none-any.whl

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.
@@ -0,0 +1,326 @@
1
+ Metadata-Version: 2.4
2
+ Name: isagellm-core
3
+ Version: 0.1.0
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.2.0,>=0.1.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
+ core 只依赖协议与抽象,不直接 import 硬件 SDK。
30
+
31
+ - 仓库名:`sagellm-core`
32
+ - PyPI 包名:`isagellm-core`
33
+ - import 名:`sagellm_core`
34
+
35
+ ## 架构层级
36
+
37
+ sagellm-core 位于 **Level 2**,依赖:
38
+ - **Level 0**: `isagellm-protocol` (协议定义)
39
+ - **Level 1**: `isagellm-backend` (后端抽象,包含 BackendProvider)
40
+
41
+ 为下游提供:
42
+ - 配置体系(config.py)
43
+ - Engine 抽象接口(engine.py)
44
+ - 插件发现机制(plugins.py)
45
+ - 工厂函数(factory.py)
46
+
47
+ ## 插件发现(entry points)
48
+
49
+ - backends:`sagellm.backends`(由 sagellm-backend 提供基础实现)
50
+ - engines:`sagellm.engines`(由各 engine 包提供实现)
51
+
52
+ core 在运行时扫描 entry points;当配置指定 kind 但未安装插件时必须 fail-fast,并给出安装提示。
53
+
54
+ ## 配置系统(Task0.02)
55
+
56
+ ### 使用方法
57
+
58
+ ```python
59
+ from sagellm_core import load_config, create_backend, create_engine
60
+
61
+ # 从 YAML/JSON 加载配置
62
+ config = load_config("config.yaml")
63
+
64
+ # 创建 backend 和 engine(通过插件发现)
65
+ backend = create_backend(config.backend)
66
+ engine = create_engine(config.engine, backend)
67
+ ```
68
+
69
+ ### 配置结构
70
+
71
+ 所有配置类均使用 pydantic v2 实现严格校验:
72
+ - 缺失必填字段立即抛出 `ValidationError`
73
+ - 未知字段被拒绝(`extra="forbid"`)
74
+ - 数值约束被强制执行
75
+
76
+ 主要配置类:
77
+ - `BackendConfig`: 后端设备配置(kind, device, device_ids)
78
+ - `EngineConfig`: 推理引擎配置(kind, model, model_path, 等)
79
+ - `WorkloadConfig`: 工作负载配置(segments, concurrency, kv_budget_tokens, 等)
80
+ - `OutputConfig`: 输出配置(metrics_path, report_path, log_path, log_level)
81
+ - `MockConfig`: 模拟模式配置(enable, fixed_latency_ms, jitter_ms, error_rate)
82
+ - `DemoConfig`: 顶层配置(包含以上所有配置 + 特性开关)
83
+
84
+ ### 配置示例
85
+
86
+ #### 快速开始
87
+
88
+ ```bash
89
+ # Mock 模式(无需 GPU)
90
+ python -m sagellm.demo --config examples/config_mock.yaml
91
+
92
+ # CUDA 生产模式
93
+ python -m sagellm.demo --config examples/config_cuda.yaml
94
+
95
+ # 昇腾生产模式
96
+ python -m sagellm.demo --config examples/config_ascend.yaml
97
+ ```
98
+
99
+ #### 示例配置文件
100
+
101
+ - [config_mock.yaml](examples/config_mock.yaml) - Mock 模式(CI/开发)
102
+ - [config_cuda.yaml](examples/config_cuda.yaml) - CUDA 生产模式
103
+ - [config_ascend.yaml](examples/config_ascend.yaml) - 昇腾生产模式
104
+ - [config_minimal.json](examples/config_minimal.json) - 最小 JSON 配置
105
+
106
+ 更多信息参见 [examples/README.md](examples/README.md)
107
+
108
+ ### 配置格式
109
+
110
+ 支持 YAML(推荐)和 JSON 格式:
111
+
112
+ ```yaml
113
+ backend:
114
+ kind: mock
115
+ engine:
116
+ kind: mock
117
+ model: mock-7b
118
+ workload:
119
+ segments: [short, long, stress]
120
+ concurrency: 4
121
+ output:
122
+ metrics_path: ./metrics.json
123
+ ```
124
+
125
+ ### 插件解析
126
+
127
+ 当配置指定的 backend/engine kind 未安装时,会抛出 `PluginResolutionError`:
128
+
129
+ ```python
130
+ from sagellm_core import create_backend, BackendConfig, PluginResolutionError
131
+
132
+ try:
133
+ backend = create_backend(BackendConfig(kind="ascend_cann", device="npu:0"))
134
+ except PluginResolutionError as e:
135
+ print(f"错误: {e}")
136
+ # 输出: No implementation found for sagellm.backends kind='ascend_cann'.
137
+ # Install hint: pip install isagellm-backend-ascend_cann
138
+ ```
139
+
140
+ ## Demo Runner CLI (Task0.08)
141
+
142
+ sagellm-core 提供了 Demo Runner CLI,用于执行 Year1 Demo Contract 验证:
143
+
144
+ ### 用法
145
+
146
+ ```bash
147
+ # 使用配置文件运行
148
+ python -m sagellm_core.demo --config examples/demo_config.yaml
149
+
150
+ # 强制使用 mock 模式(覆盖配置文件)
151
+ python -m sagellm_core.demo --config config.yaml --mock
152
+
153
+ # 覆盖 workload 段选择
154
+ python -m sagellm_core.demo --config config.yaml --segments short,long
155
+
156
+ # 覆盖输出路径
157
+ python -m sagellm_core.demo --config config.yaml --output /tmp/metrics.json
158
+
159
+ # 启用 streaming 模式和详细日志
160
+ python -m sagellm_core.demo --config config.yaml --stream --verbose
161
+ ```
162
+
163
+ ### 示例配置
164
+
165
+ 参见 [examples/demo_config.yaml](examples/demo_config.yaml):
166
+
167
+ ```yaml
168
+ backend:
169
+ kind: mock
170
+ device: null
171
+
172
+ engine:
173
+ kind: mock
174
+ model: mock-7b
175
+
176
+ workload:
177
+ segments: [short, long, stress]
178
+ concurrency: 4
179
+ kv_budget_tokens: 8192
180
+
181
+ output:
182
+ metrics_path: ./output/metrics.json
183
+ report_path: ./output/report.md
184
+ ```
185
+
186
+ ### 验收标准(Task0.08)
187
+
188
+ - [x] `python -m sagellm_core.demo --help` 输出帮助信息
189
+ - [x] `python -m sagellm_core.demo --config examples/demo_config.yaml --mock` 可运行
190
+ - [x] 缺少 --config 参数时报错
191
+ - [x] 配置文件不存在时报错
192
+ - [x] 无效的 segment 值时报错
193
+ - [x] `ruff check` 和 `mypy` 通过
194
+
195
+ **注意**:实际 workload 执行逻辑在 task0_10 实现,当前阶段运行会输出 `NotImplementedError`。
196
+
197
+ ## 开发指南
198
+
199
+ ### 快速开始
200
+
201
+ ```bash
202
+ # 克隆仓库
203
+ git clone https://github.com/intellistream/sagellm-core.git
204
+ cd sagellm-core
205
+
206
+ # 安装开发依赖
207
+ pip install -e ".[dev]"
208
+
209
+ # 安装 pre-commit hooks
210
+ pre-commit install
211
+
212
+ # 验证环境
213
+ pytest tests/ -v
214
+ ```
215
+
216
+ ### 质量保证体系
217
+
218
+ sageLLM 实施三层质量保证:
219
+
220
+ #### 1. Pre-commit Hooks(提交前自动检查)
221
+
222
+ 安装后,每次 `git commit` 会自动运行:
223
+ - **Ruff**: 代码格式化 + Lint 检查
224
+ - **Mypy**: 静态类型检查
225
+ - **YAML/JSON**: 配置文件验证
226
+
227
+ ```bash
228
+ # 手动运行所有 hooks
229
+ pre-commit run --all-files
230
+
231
+ # 绕过 hooks(紧急情况)
232
+ git commit --no-verify
233
+ ```
234
+
235
+ #### 2. 单元测试(本地验证)
236
+
237
+ ```bash
238
+ # 运行所有测试
239
+ pytest tests/ -v
240
+
241
+ # 运行特定模块测试
242
+ pytest tests/unit/test_demo.py -v
243
+ pytest tests/unit/test_config.py -v
244
+
245
+ # 生成覆盖率报告
246
+ pytest tests/ --cov=sagellm_core --cov-report=html
247
+ open htmlcov/index.html
248
+ ```
249
+
250
+ 测试要求:
251
+ - ✅ 新功能必须有对应单元测试
252
+ - ✅ 覆盖率不低于现有水平
253
+ - ✅ 所有测试必须支持 mock 模式(无需 GPU)
254
+
255
+ #### 3. CI/CD(自动化验证)
256
+
257
+ 每次 PR 触发 GitHub Actions 自动运行:
258
+ - **Lint Job**: Ruff + Mypy 检查
259
+ - **Test Job**: 多 Python 版本矩阵测试(3.10, 3.11, 3.12)
260
+ - **Protocol Job**: 验证与 Protocol v0.1 对齐
261
+ - **Build Job**: 验证包构建
262
+
263
+ 查看 CI 状态:`.github/workflows/ci.yml`
264
+
265
+ ### 代码规范
266
+
267
+ **核心原则**:
268
+ 1. **Protocol-first** - 修改接口前先升级 Protocol
269
+ 2. **Mock-first** - 所有模块支持 mock 模式
270
+ 3. **Fail-fast** - 禁止隐式默认值,配置错误立即报错
271
+ 4. **Type-safe** - 所有函数必须有类型注解
272
+
273
+ ```python
274
+ # ✅ 正确示例
275
+ def create_backend(config: BackendConfig) -> BaseBackend:
276
+ if config.kind == "mock":
277
+ return MockBackend(config)
278
+ raise PluginResolutionError(f"Unknown backend: {config.kind}")
279
+
280
+ # ❌ 错误示例
281
+ def create_backend(config): # 缺少类型注解
282
+ return MockBackend(config.get("kind", "mock")) # 隐式默认值
283
+ ```
284
+
285
+ 详细规范参见 [CONTRIBUTING.md](CONTRIBUTING.md)
286
+
287
+ ### 代码检查
288
+
289
+ ```bash
290
+ # 格式化代码
291
+ ruff format .
292
+
293
+ # Lint 检查
294
+ ruff check .
295
+
296
+ # 类型检查
297
+ mypy src/sagellm_core
298
+
299
+ # 一键检查所有
300
+ pre-commit run --all-files
301
+ ```
302
+
303
+ ## 依赖
304
+
305
+ - `pydantic>=2.0.0`: 配置校验
306
+ - `pyyaml>=6.0.0`: YAML 配置支持
307
+ - `isagellm-protocol>=0.1.0,<0.2.0`: 协议定义(Level 0)
308
+ - `isagellm-backend>=0.1.0,<0.2.0`: 后端抽象(Level 1)
309
+
310
+ ## 依赖层级说明
311
+
312
+ ```
313
+ Level 0: isagellm-protocol (最基础,无依赖)
314
+
315
+ Level 1: isagellm-backend (依赖 protocol)
316
+
317
+ Level 2: isagellm-core (依赖 protocol + backend) ← 当前包
318
+
319
+ Level 3: 功能模块(依赖 protocol + backend + core)
320
+ ├─ isagellm-kv-cache
321
+ ├─ isagellm-comm
322
+ └─ isagellm-compression
323
+
324
+ Level 4: isagellm-demo (依赖所有模块)
325
+ ```
326
+
@@ -0,0 +1,31 @@
1
+ sagellm_core/__init__.py,sha256=MWpaRuB3qnlJMWGEg-WRgcIilMTO8KYzuenfc95Gy2o,1427
2
+ sagellm_core/__init__.pyc,sha256=UmPe4uUGaK75yWKog9QSNWBRUoYvNN21iMTzucPznzM,1538
3
+ sagellm_core/__main__.pyc,sha256=48Ej1ycqV-z87qawGOTNBKNgY3EcbffUOOXrDecOR3g,384
4
+ sagellm_core/config.pyc,sha256=Reg92lld5VRC8FcV3qahAXaWmwar5RYfQMLysPw5UFQ,9617
5
+ sagellm_core/demo.pyc,sha256=hI3RKeIGhmoKt7N30r5QWJh07qrmf49cZlXjp48phz4,5728
6
+ sagellm_core/engine.pyc,sha256=4HFROkpRES11m5dQyOjyYRA0RbJFlYO2Dl7A5dMu9_w,3598
7
+ sagellm_core/factory.pyc,sha256=uLXID49VZ7TcNZqgLBbznInCXjwbRSXSpD0bc6WHDVs,2692
8
+ sagellm_core/mock_engine.pyc,sha256=wTAEID7SVpZGeMiujX98CumNksp4T78AfKIWeuCb2jI,532
9
+ sagellm_core/plugins.pyc,sha256=RwUFT48AJhKqah3q7YOigOYwqvnei6RNMqpZksX5VJ0,2618
10
+ sagellm_core/py.typed,sha256=ixa8YukDZ3kLo0WsFJRGohLMyHzbMur1ALmmASML2cs,64
11
+ sagellm_core/runner.pyc,sha256=1E0hkYDYxQFSXUrTxALP7kvwX8Z1-jsRfyzWumC2cKE,14479
12
+ sagellm_core/workload.pyc,sha256=92TRxjcnKLzAbcVZgOTPzwdR9dU1hqjO2j-olr1QCQ8,4118
13
+ sagellm_core/__pycache__/__init__.cpython-311.pyc,sha256=vEYsS7efRG35E0lrTNCLokWRUGaE8DINcT2LRqabs_s,1582
14
+ sagellm_core/__pycache__/config.cpython-311.pyc,sha256=bFTIjHE0DP304V_cvsFREkedx1b9TB4UTVDwExUvqXo,9661
15
+ sagellm_core/__pycache__/demo.cpython-311.pyc,sha256=dG2EDA_mTwWRgOWujyDXJvDAInQZWuNgJOBTMxtkxQc,5772
16
+ sagellm_core/__pycache__/engine.cpython-311.pyc,sha256=TCUxrAN856WYtEzi4D1tXNjgj177Cx6d2yp2LMMcC7I,3647
17
+ sagellm_core/__pycache__/factory.cpython-311.pyc,sha256=d3up_zYRL1q12mGYvBE_f6HpzaWlerXV_RZ9ys4VZtQ,2736
18
+ sagellm_core/__pycache__/mock_engine.cpython-311.pyc,sha256=zCHNncwIzEgqZ0lc7kiWkS-zOHf7CQ73UhCXztR6mFM,581
19
+ sagellm_core/__pycache__/plugins.cpython-311.pyc,sha256=__NNjLfUJXa1DqwdgVBJAkLp-nN2rcA5SXM0_Jd9MPU,2662
20
+ sagellm_core/__pycache__/runner.cpython-311.pyc,sha256=dCWo6RBDeeQFj3Igh0A6P6LKUH7r3w9sStqXChypXRo,14523
21
+ sagellm_core/__pycache__/workload.cpython-311.pyc,sha256=kOSkfzgj2-GozzyuTfTE7NST2_HblneakPUuj9MLP48,4162
22
+ sagellm_core/engines/__init__.py,sha256=X_zrzK96ZTwcqWJD6GcdZ_9cynsJnpN11KtV_GQTG4c,248
23
+ sagellm_core/engines/__init__.pyc,sha256=wvPx_2E1evtbKxyF7d1xdoK5l-XVLh7_vkFlKkf8KtI,458
24
+ sagellm_core/engines/mock.pyc,sha256=7V2PgGvtuEsAU8sW5D9ZEIj0NpcqnTy2ezSDQw_C_Q4,7917
25
+ sagellm_core/engines/__pycache__/__init__.cpython-311.pyc,sha256=5EYPxOv12AZEhUSw_v65GgVskdxzcJLcfdhJ5B05BHw,502
26
+ sagellm_core/engines/__pycache__/mock.cpython-311.pyc,sha256=YpY2M-rXF_vMg0GeWfPnrqo06KL-gHrbBAF-1nh3wUQ,7961
27
+ isagellm_core-0.1.0.dist-info/METADATA,sha256=5LT4nsoDr8tF4SriE5hBLtA9SigJSxuaQxwYDhSNIO0,8631
28
+ isagellm_core-0.1.0.dist-info/WHEEL,sha256=27snaH8EChr9VGIQt_981R5IOTPR-vQPuJNW-WzhNJA,93
29
+ isagellm_core-0.1.0.dist-info/entry_points.txt,sha256=dvRi6CIfghSFY6qmzpfG6nLg9yeQicW6lFBTNmdgEB8,70
30
+ isagellm_core-0.1.0.dist-info/top_level.txt,sha256=wcgdWrvkaoYYh_dWSFI5Toi8PZsHutVqfhTB2tb0K6g,13
31
+ isagellm_core-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: cp311-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [sagellm.engines]
2
+ mock = sagellm_core.engines.mock:create_mock_engine
@@ -0,0 +1 @@
1
+ sagellm_core
@@ -0,0 +1,61 @@
1
+ """sageLLM Core 运行时。
2
+
3
+ 本包提供 sageLLM 的核心运行时组件:
4
+ - 配置 schema 与校验
5
+ - Engine 抽象接口与实现
6
+ - Backend 与 Engine 工厂函数
7
+ - 插件系统
8
+ - Demo Runner
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from sagellm_core.config import (
14
+ BackendConfig,
15
+ DemoConfig,
16
+ EngineConfig,
17
+ MockConfig,
18
+ OutputConfig,
19
+ WorkloadConfig,
20
+ WorkloadSegment,
21
+ load_config,
22
+ )
23
+ from sagellm_core.demo import main as demo_main
24
+ from sagellm_core.engine import BaseEngine, HealthStatus
25
+ from sagellm_core.engines.mock import MockEngine, create_mock_engine
26
+ from sagellm_core.factory import create_backend, create_engine
27
+ from sagellm_core.plugins import PluginResolutionError, list_entry_points, resolve_kind
28
+ from sagellm_core.runner import DemoRunner, RunnerContext
29
+
30
+ __version__ = "0.1.0"
31
+
32
+ __all__ = [
33
+ # Version
34
+ "__version__",
35
+ # Configuration
36
+ "BackendConfig",
37
+ "DemoConfig",
38
+ "EngineConfig",
39
+ "MockConfig",
40
+ "OutputConfig",
41
+ "WorkloadConfig",
42
+ "WorkloadSegment",
43
+ "load_config",
44
+ # Engine abstraction
45
+ "BaseEngine",
46
+ "HealthStatus",
47
+ # Engine implementations
48
+ "MockEngine",
49
+ "create_mock_engine",
50
+ # Factory functions
51
+ "create_backend",
52
+ "create_engine",
53
+ # Plugin system
54
+ "PluginResolutionError",
55
+ "list_entry_points",
56
+ "resolve_kind",
57
+ # Demo runner
58
+ "demo_main",
59
+ "DemoRunner",
60
+ "RunnerContext",
61
+ ]
Binary file
Binary file
Binary file
sagellm_core/demo.pyc ADDED
Binary file
Binary file
@@ -0,0 +1,13 @@
1
+ """Engine implementations
2
+
3
+ 包含各种引擎实现(mock, adapters 等)。
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from sagellm_core.engines.mock import MockEngine, create_mock_engine
9
+
10
+ __all__ = [
11
+ "MockEngine",
12
+ "create_mock_engine",
13
+ ]
Binary file
Binary file
Binary file
Binary file
Binary file
sagellm_core/py.typed ADDED
@@ -0,0 +1,2 @@
1
+ # Marker file for PEP 561
2
+ # This package supports type checking
Binary file
Binary file