guarftrain 0.2.0__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.
- guarftrain-0.2.0/LICENSE +21 -0
- guarftrain-0.2.0/MANIFEST.in +3 -0
- guarftrain-0.2.0/PKG-INFO +244 -0
- guarftrain-0.2.0/README.md +198 -0
- guarftrain-0.2.0/guardian/__init__.py +7 -0
- guarftrain-0.2.0/guardian/__main__.py +4 -0
- guarftrain-0.2.0/guardian/agent_advisor.py +810 -0
- guarftrain-0.2.0/guardian/checkpoint_analyzer.py +251 -0
- guarftrain-0.2.0/guardian/cli.py +1471 -0
- guarftrain-0.2.0/guardian/component_library.py +393 -0
- guarftrain-0.2.0/guardian/config.py +306 -0
- guarftrain-0.2.0/guardian/credentials.py +84 -0
- guarftrain-0.2.0/guardian/dashboard/__init__.py +13 -0
- guarftrain-0.2.0/guardian/dashboard/server.py +1265 -0
- guarftrain-0.2.0/guardian/dashboard/static/index.html +2113 -0
- guarftrain-0.2.0/guardian/experiment_query.py +644 -0
- guarftrain-0.2.0/guardian/gallery.py +483 -0
- guarftrain-0.2.0/guardian/inference.py +284 -0
- guarftrain-0.2.0/guardian/logging_config.py +97 -0
- guarftrain-0.2.0/guardian/mcp_server.py +2150 -0
- guarftrain-0.2.0/guardian/model_viz.py +819 -0
- guarftrain-0.2.0/guardian/monitor.py +577 -0
- guarftrain-0.2.0/guardian/notifier.py +125 -0
- guarftrain-0.2.0/guardian/project_context.py +487 -0
- guarftrain-0.2.0/guardian/resource_estimator.py +483 -0
- guarftrain-0.2.0/guardian/streamlit_app.py +141 -0
- guarftrain-0.2.0/guardian/summary.py +279 -0
- guarftrain-0.2.0/guardian/task_contract.py +514 -0
- guarftrain-0.2.0/guardian/watchdog.py +678 -0
- guarftrain-0.2.0/guarftrain.egg-info/PKG-INFO +244 -0
- guarftrain-0.2.0/guarftrain.egg-info/SOURCES.txt +44 -0
- guarftrain-0.2.0/guarftrain.egg-info/dependency_links.txt +1 -0
- guarftrain-0.2.0/guarftrain.egg-info/entry_points.txt +2 -0
- guarftrain-0.2.0/guarftrain.egg-info/requires.txt +30 -0
- guarftrain-0.2.0/guarftrain.egg-info/top_level.txt +1 -0
- guarftrain-0.2.0/pyproject.toml +93 -0
- guarftrain-0.2.0/setup.cfg +4 -0
- guarftrain-0.2.0/tests/test_agent_advisor.py +429 -0
- guarftrain-0.2.0/tests/test_config.py +190 -0
- guarftrain-0.2.0/tests/test_experiment_query.py +260 -0
- guarftrain-0.2.0/tests/test_gallery.py +189 -0
- guarftrain-0.2.0/tests/test_inference.py +104 -0
- guarftrain-0.2.0/tests/test_mcp_tools.py +329 -0
- guarftrain-0.2.0/tests/test_model_viz.py +196 -0
- guarftrain-0.2.0/tests/test_notifier.py +98 -0
- guarftrain-0.2.0/tests/test_project_context.py +129 -0
guarftrain-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Washington5533
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: guarftrain
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Training Guardian — sidecar training monitor with crash recovery, agent decisions, MCP & web dashboard
|
|
5
|
+
Author: Training Guardian Contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Washington5533/guarftrain
|
|
8
|
+
Project-URL: Documentation, https://github.com/Washington5533/guarftrain/blob/main/README.md
|
|
9
|
+
Project-URL: Repository, https://github.com/Washington5533/guarftrain
|
|
10
|
+
Project-URL: Issues, https://github.com/Washington5533/guarftrain/issues
|
|
11
|
+
Keywords: deep-learning,training,monitoring,mcp,mlops
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: pyyaml>=6.0
|
|
23
|
+
Requires-Dist: psutil>=5.9
|
|
24
|
+
Requires-Dist: GPUtil>=1.4
|
|
25
|
+
Requires-Dist: requests>=2.28
|
|
26
|
+
Requires-Dist: numpy>=1.24
|
|
27
|
+
Provides-Extra: agent
|
|
28
|
+
Requires-Dist: anthropic>=0.40; extra == "agent"
|
|
29
|
+
Provides-Extra: agent-openai
|
|
30
|
+
Requires-Dist: openai>=1.50; extra == "agent-openai"
|
|
31
|
+
Provides-Extra: mcp
|
|
32
|
+
Requires-Dist: mcp>=1.0; extra == "mcp"
|
|
33
|
+
Provides-Extra: dashboard
|
|
34
|
+
Requires-Dist: fastapi>=0.100; extra == "dashboard"
|
|
35
|
+
Requires-Dist: uvicorn[standard]>=0.23; extra == "dashboard"
|
|
36
|
+
Provides-Extra: viz
|
|
37
|
+
Requires-Dist: torch>=2.0; extra == "viz"
|
|
38
|
+
Requires-Dist: torchvision>=0.15; extra == "viz"
|
|
39
|
+
Provides-Extra: full
|
|
40
|
+
Requires-Dist: guarftrain[agent,dashboard,mcp,viz]; extra == "full"
|
|
41
|
+
Provides-Extra: dev
|
|
42
|
+
Requires-Dist: guarftrain[full]; extra == "dev"
|
|
43
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
44
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
45
|
+
Dynamic: license-file
|
|
46
|
+
|
|
47
|
+
# Training Guardian Agent · 训练守护智能体
|
|
48
|
+
|
|
49
|
+
[](https://github.com/Washington5533/guarftrain/actions/workflows/ci.yml)
|
|
50
|
+

|
|
51
|
+

|
|
52
|
+
|
|
53
|
+
> **一行命令,训练脚本零行改动,获得完整守护能力。**
|
|
54
|
+
>
|
|
55
|
+
> *One command. Zero changes to your training script. Full guardian capabilities.*
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
guarftrain init && guarftrain watch -- python train.py --epochs 20
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## What's New in v0.2.0
|
|
64
|
+
|
|
65
|
+
| Feature | Description |
|
|
66
|
+
|---------|-------------|
|
|
67
|
+
| `guarftrain` CLI | `pip install` 后全局可用,替换旧 `python run.py` |
|
|
68
|
+
| `guarftrain init` | 自动扫描训练脚本,生成 contract.yaml |
|
|
69
|
+
| `guarftrain check` | 环境自检:Python/GPU/依赖/项目结构 |
|
|
70
|
+
| Dashboard 远程配置 | 外部 Agent 通过 MCP 控制 Dashboard 图表/面板,用户操作受 dirty flag 保护 |
|
|
71
|
+
| Agent 图表推荐 | `chart_selection` 决策点:Agent 分析训练状态,推荐应关注的指标组 |
|
|
72
|
+
| MCP 委托模式 | 外部 Claude Code 连接时内置 Agent 进入 provisional 模式,决策可被覆盖 |
|
|
73
|
+
| 增量图表更新 | Dashboard 实时推送图表数据,不再全量重建 |
|
|
74
|
+
| 依赖瘦身 | 核心安装 ~2MB,torch/anthropic 按需安装 |
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## What does it do? · 它做什么?
|
|
79
|
+
|
|
80
|
+
| Phase · 阶段 | Capability · 能力 | How · 方式 |
|
|
81
|
+
|-------------|-------------------|------------|
|
|
82
|
+
| 训练前 Pre-flight | GPU 显存预估 + batch 推荐 | `guarftrain preflight` |
|
|
83
|
+
| 训练中 During | GPU+Loss 监控告警 / 崩溃自动恢复 / LLM 决策 | `guarftrain watch` |
|
|
84
|
+
| 训练后 Post | 摘要+AI 解读 / Checkpoint 分析 / 模型可视化 / 推理 | `guarftrain summarize` |
|
|
85
|
+
| 跨实验 Cross | 自然语言查询 / 实验对比 / 数据导入 | `guarftrain query "best lr?"` |
|
|
86
|
+
| 外部接入 External | MCP 32 工具 + Dashboard 远程配置 + Agent 图表推荐 | `guarftrain start` |
|
|
87
|
+
|
|
88
|
+
## Quick Start · 快速开始
|
|
89
|
+
|
|
90
|
+
### Install · 安装
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# 方式 1: pip 安装(推荐,轻量核心 ~2MB,torch 已有不重装)
|
|
94
|
+
pip install guarftrain
|
|
95
|
+
|
|
96
|
+
# 方式 2: 从源码安装
|
|
97
|
+
git clone https://github.com/Washington5533/guarftrain.git
|
|
98
|
+
cd guarftrain
|
|
99
|
+
pip install .
|
|
100
|
+
|
|
101
|
+
# 按需安装可选组件
|
|
102
|
+
pip install guarftrain[agent] # AI 决策层 (anthropic)
|
|
103
|
+
pip install guarftrain[mcp] # MCP 外部 Agent 接入
|
|
104
|
+
pip install guarftrain[dashboard] # Web 控制面板
|
|
105
|
+
pip install guarftrain[full] # 全部安装
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Three steps to guard · 三步守护
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# 1. 初始化项目(自动扫描训练脚本,生成配置)
|
|
112
|
+
cd /path/to/your-project
|
|
113
|
+
guarftrain init
|
|
114
|
+
|
|
115
|
+
# 2. 守护训练(纯规则,零外部依赖)
|
|
116
|
+
guarftrain watch -- python train.py --epochs 20
|
|
117
|
+
|
|
118
|
+
# 3. 或启用 AI + Dashboard + MCP
|
|
119
|
+
guarftrain watch --agent --with-dashboard --with-mcp -- python train.py --epochs 20
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### What does the training script need? · 训练脚本要满足什么?
|
|
123
|
+
|
|
124
|
+
Four contracts (just good training hygiene):
|
|
125
|
+
|
|
126
|
+
1. `--resume` / `--ckpt` flags for checkpoint resumption
|
|
127
|
+
2. `cp_{epoch}/model.pth` with `epoch/model_state_dict/optimizer_state_dict`
|
|
128
|
+
3. Structured logging: `epoch {n} loss {v} val_acc {v} lr {v}`
|
|
129
|
+
4. Importable: `train:build_model` / `train:get_dataloaders`
|
|
130
|
+
|
|
131
|
+
Missing any one? Only the corresponding capability is disabled — training still runs.
|
|
132
|
+
|
|
133
|
+
四项契约(写好训练脚本的基本功),缺任一项只关对应能力,不阻断训练。
|
|
134
|
+
|
|
135
|
+
## Architecture · 架构
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
┌─ Guardian Process (sidecar) ────────────────────────────────────┐
|
|
139
|
+
│ │
|
|
140
|
+
│ CLI (run.py) ──→ 14 subcommands │
|
|
141
|
+
│ ├─ watch ──→ Watchdog: Popen + crash recovery + CLI rewrite │
|
|
142
|
+
│ │ └─ Monitor: log tail + GPU poll + anomaly detect │
|
|
143
|
+
│ │ └─ AgentAdvisor: LLM decide → intervene │
|
|
144
|
+
│ ├─ serve ──→ MCP Server: 32 tools (22 read + 10 write) │
|
|
145
|
+
│ ├─ start ──→ Dashboard + MCP one-click │
|
|
146
|
+
│ └─ experiments / query / compare ──→ Cross-experiment analysis │
|
|
147
|
+
│ │
|
|
148
|
+
│ Decision Layers · 决策分层: │
|
|
149
|
+
│ ┌─ Contract (hard boundary, human-defined) │
|
|
150
|
+
│ ├─ Agent (LLM, optional, within action space) │
|
|
151
|
+
│ ├─ Rules (deterministic, always-on fallback) │
|
|
152
|
+
│ ├─ MCP (external agent access, dual-mode delegation) │
|
|
153
|
+
│ └─ Dashboard (remote config, dirty-flag user protection) │
|
|
154
|
+
│ │
|
|
155
|
+
│ Training Process: python train.py (0 changes required) │
|
|
156
|
+
└──────────────────────────────────────────────────────────────────┘
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## CLI Commands · 命令速查
|
|
160
|
+
|
|
161
|
+
| Command | Description |
|
|
162
|
+
|---------|-------------|
|
|
163
|
+
| `init` | Auto-detect project + generate contract.yaml |
|
|
164
|
+
| `check` | Environment readiness check (deps, GPU, config) |
|
|
165
|
+
| `watch` | Guard any training command |
|
|
166
|
+
| `start` | Dashboard + MCP one-click launch |
|
|
167
|
+
| `serve` | Standalone MCP server |
|
|
168
|
+
| `contract check` | Validate training script contract |
|
|
169
|
+
| `preflight` | GPU memory estimate + batch recommendation |
|
|
170
|
+
| `analyze` | Scan existing checkpoints |
|
|
171
|
+
| `experiments` | List all historical experiments |
|
|
172
|
+
| `query` | Natural language query ("best lr?") |
|
|
173
|
+
| `compare` | Compare two experiments |
|
|
174
|
+
| `visualize` | Model structure visualization (D3.js HTML) |
|
|
175
|
+
| `infer` | Run inference with checkpoint |
|
|
176
|
+
| `gallery` | Image filtering + selection |
|
|
177
|
+
| `dashboard` | Web control panel (standalone) |
|
|
178
|
+
| `project` | Project context management (init/show/scan/fill) |
|
|
179
|
+
|
|
180
|
+
## MCP Tools · MCP 工具
|
|
181
|
+
|
|
182
|
+
**24 read-only** (always available, no auth):
|
|
183
|
+
|
|
184
|
+
`get_training_status` · `get_metrics_history` · `list_checkpoints` · `compare_checkpoints` · `get_anomaly_history` · `get_recovery_history` · `get_summary` · `get_agent_decision_log` · `get_contract_status` · `list_contract_proposals` · `list_experiments` · `query_experiment` · `compare_experiments` · `get_model_structure` · `get_guardian_mode` · `get_gallery_config` · `get_import_format` · `inspect_source` · `get_training_log` · `get_post_training_checklist` · `get_pending_decisions` · `get_dashboard_config` · `recommend_charts` · `list_dashboard_templates`
|
|
185
|
+
|
|
186
|
+
**11 write** (token auth + training-phase gating):
|
|
187
|
+
|
|
188
|
+
`trigger_recovery` · `restart_with_params` · `stop_training` · `approve_contract_proposal` · `reject_contract_proposal` · `run_visualization` · `set_gallery_config` · `run_inference` · `submit_import` · `resolve_decision` · `set_dashboard_config`
|
|
189
|
+
|
|
190
|
+
→ Full API reference: [MCP_API_REFERENCE.md](MCP_API_REFERENCE.md)
|
|
191
|
+
|
|
192
|
+
## Configuration · 配置
|
|
193
|
+
|
|
194
|
+
Three layers, zero secrets in YAML:
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
DEFAULTS < guardian.yaml < GUARDIAN_* env vars < CLI flags
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
```yaml
|
|
201
|
+
# configs/guardian.yaml — only override what you need
|
|
202
|
+
watchdog:
|
|
203
|
+
max_retries: 3
|
|
204
|
+
monitor:
|
|
205
|
+
poll_interval: 5
|
|
206
|
+
mcp:
|
|
207
|
+
enable_write_tools: true
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
# Env override: GUARDIAN_ + section + __ + key
|
|
212
|
+
export GUARDIAN_WATCHDOG__MAX_RETRIES=5
|
|
213
|
+
export GUARDIAN_MCP_TOKEN=your-secret # write tool auth
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Project Status · 项目状态
|
|
217
|
+
|
|
218
|
+
| Metric | Value |
|
|
219
|
+
|--------|-------|
|
|
220
|
+
| Version | 0.2.0 |
|
|
221
|
+
| Modules | 16 (cp_1 ~ cp_16) |
|
|
222
|
+
| Production code | ~10,500 lines |
|
|
223
|
+
| Tests | 221 (CI on push) |
|
|
224
|
+
| MCP tools | 35 (24 read + 11 write) |
|
|
225
|
+
| CLI commands | 16 |
|
|
226
|
+
| Test coverage | ~13% (core paths: 100%) |
|
|
227
|
+
| Python | 3.10+ |
|
|
228
|
+
|
|
229
|
+
## Docs · 文档索引
|
|
230
|
+
|
|
231
|
+
| Document | Content |
|
|
232
|
+
|----------|---------|
|
|
233
|
+
| [ARCHITECTURE.md](ARCHITECTURE.md) | Architecture & workflow (ZH) |
|
|
234
|
+
| [DEPLOYMENT.md](DEPLOYMENT.md) | User manual (ZH) |
|
|
235
|
+
| [MCP.md](MCP.md) | MCP integration guide (ZH) |
|
|
236
|
+
| [MCP_API_REFERENCE.md](MCP_API_REFERENCE.md) | 35-tool API reference (ZH) |
|
|
237
|
+
| [MCP_QUICKSTART.md](MCP_QUICKSTART.md) | 5-minute MCP onboarding (ZH) |
|
|
238
|
+
| [IMPLEMENTATION_REPORT.md](IMPLEMENTATION_REPORT.md) | Per-module completion report (ZH) |
|
|
239
|
+
| [checkpoint/INDEX.md](checkpoint/INDEX.md) | Module index cp_1~cp_16 (ZH) |
|
|
240
|
+
| [checkpoint/cp_10.md](checkpoint/cp_10.md) | MCP layer design doc (ZH) |
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
MIT
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# Training Guardian Agent · 训练守护智能体
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Washington5533/guarftrain/actions/workflows/ci.yml)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
> **一行命令,训练脚本零行改动,获得完整守护能力。**
|
|
8
|
+
>
|
|
9
|
+
> *One command. Zero changes to your training script. Full guardian capabilities.*
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
guarftrain init && guarftrain watch -- python train.py --epochs 20
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## What's New in v0.2.0
|
|
18
|
+
|
|
19
|
+
| Feature | Description |
|
|
20
|
+
|---------|-------------|
|
|
21
|
+
| `guarftrain` CLI | `pip install` 后全局可用,替换旧 `python run.py` |
|
|
22
|
+
| `guarftrain init` | 自动扫描训练脚本,生成 contract.yaml |
|
|
23
|
+
| `guarftrain check` | 环境自检:Python/GPU/依赖/项目结构 |
|
|
24
|
+
| Dashboard 远程配置 | 外部 Agent 通过 MCP 控制 Dashboard 图表/面板,用户操作受 dirty flag 保护 |
|
|
25
|
+
| Agent 图表推荐 | `chart_selection` 决策点:Agent 分析训练状态,推荐应关注的指标组 |
|
|
26
|
+
| MCP 委托模式 | 外部 Claude Code 连接时内置 Agent 进入 provisional 模式,决策可被覆盖 |
|
|
27
|
+
| 增量图表更新 | Dashboard 实时推送图表数据,不再全量重建 |
|
|
28
|
+
| 依赖瘦身 | 核心安装 ~2MB,torch/anthropic 按需安装 |
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## What does it do? · 它做什么?
|
|
33
|
+
|
|
34
|
+
| Phase · 阶段 | Capability · 能力 | How · 方式 |
|
|
35
|
+
|-------------|-------------------|------------|
|
|
36
|
+
| 训练前 Pre-flight | GPU 显存预估 + batch 推荐 | `guarftrain preflight` |
|
|
37
|
+
| 训练中 During | GPU+Loss 监控告警 / 崩溃自动恢复 / LLM 决策 | `guarftrain watch` |
|
|
38
|
+
| 训练后 Post | 摘要+AI 解读 / Checkpoint 分析 / 模型可视化 / 推理 | `guarftrain summarize` |
|
|
39
|
+
| 跨实验 Cross | 自然语言查询 / 实验对比 / 数据导入 | `guarftrain query "best lr?"` |
|
|
40
|
+
| 外部接入 External | MCP 32 工具 + Dashboard 远程配置 + Agent 图表推荐 | `guarftrain start` |
|
|
41
|
+
|
|
42
|
+
## Quick Start · 快速开始
|
|
43
|
+
|
|
44
|
+
### Install · 安装
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# 方式 1: pip 安装(推荐,轻量核心 ~2MB,torch 已有不重装)
|
|
48
|
+
pip install guarftrain
|
|
49
|
+
|
|
50
|
+
# 方式 2: 从源码安装
|
|
51
|
+
git clone https://github.com/Washington5533/guarftrain.git
|
|
52
|
+
cd guarftrain
|
|
53
|
+
pip install .
|
|
54
|
+
|
|
55
|
+
# 按需安装可选组件
|
|
56
|
+
pip install guarftrain[agent] # AI 决策层 (anthropic)
|
|
57
|
+
pip install guarftrain[mcp] # MCP 外部 Agent 接入
|
|
58
|
+
pip install guarftrain[dashboard] # Web 控制面板
|
|
59
|
+
pip install guarftrain[full] # 全部安装
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Three steps to guard · 三步守护
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# 1. 初始化项目(自动扫描训练脚本,生成配置)
|
|
66
|
+
cd /path/to/your-project
|
|
67
|
+
guarftrain init
|
|
68
|
+
|
|
69
|
+
# 2. 守护训练(纯规则,零外部依赖)
|
|
70
|
+
guarftrain watch -- python train.py --epochs 20
|
|
71
|
+
|
|
72
|
+
# 3. 或启用 AI + Dashboard + MCP
|
|
73
|
+
guarftrain watch --agent --with-dashboard --with-mcp -- python train.py --epochs 20
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### What does the training script need? · 训练脚本要满足什么?
|
|
77
|
+
|
|
78
|
+
Four contracts (just good training hygiene):
|
|
79
|
+
|
|
80
|
+
1. `--resume` / `--ckpt` flags for checkpoint resumption
|
|
81
|
+
2. `cp_{epoch}/model.pth` with `epoch/model_state_dict/optimizer_state_dict`
|
|
82
|
+
3. Structured logging: `epoch {n} loss {v} val_acc {v} lr {v}`
|
|
83
|
+
4. Importable: `train:build_model` / `train:get_dataloaders`
|
|
84
|
+
|
|
85
|
+
Missing any one? Only the corresponding capability is disabled — training still runs.
|
|
86
|
+
|
|
87
|
+
四项契约(写好训练脚本的基本功),缺任一项只关对应能力,不阻断训练。
|
|
88
|
+
|
|
89
|
+
## Architecture · 架构
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
┌─ Guardian Process (sidecar) ────────────────────────────────────┐
|
|
93
|
+
│ │
|
|
94
|
+
│ CLI (run.py) ──→ 14 subcommands │
|
|
95
|
+
│ ├─ watch ──→ Watchdog: Popen + crash recovery + CLI rewrite │
|
|
96
|
+
│ │ └─ Monitor: log tail + GPU poll + anomaly detect │
|
|
97
|
+
│ │ └─ AgentAdvisor: LLM decide → intervene │
|
|
98
|
+
│ ├─ serve ──→ MCP Server: 32 tools (22 read + 10 write) │
|
|
99
|
+
│ ├─ start ──→ Dashboard + MCP one-click │
|
|
100
|
+
│ └─ experiments / query / compare ──→ Cross-experiment analysis │
|
|
101
|
+
│ │
|
|
102
|
+
│ Decision Layers · 决策分层: │
|
|
103
|
+
│ ┌─ Contract (hard boundary, human-defined) │
|
|
104
|
+
│ ├─ Agent (LLM, optional, within action space) │
|
|
105
|
+
│ ├─ Rules (deterministic, always-on fallback) │
|
|
106
|
+
│ ├─ MCP (external agent access, dual-mode delegation) │
|
|
107
|
+
│ └─ Dashboard (remote config, dirty-flag user protection) │
|
|
108
|
+
│ │
|
|
109
|
+
│ Training Process: python train.py (0 changes required) │
|
|
110
|
+
└──────────────────────────────────────────────────────────────────┘
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## CLI Commands · 命令速查
|
|
114
|
+
|
|
115
|
+
| Command | Description |
|
|
116
|
+
|---------|-------------|
|
|
117
|
+
| `init` | Auto-detect project + generate contract.yaml |
|
|
118
|
+
| `check` | Environment readiness check (deps, GPU, config) |
|
|
119
|
+
| `watch` | Guard any training command |
|
|
120
|
+
| `start` | Dashboard + MCP one-click launch |
|
|
121
|
+
| `serve` | Standalone MCP server |
|
|
122
|
+
| `contract check` | Validate training script contract |
|
|
123
|
+
| `preflight` | GPU memory estimate + batch recommendation |
|
|
124
|
+
| `analyze` | Scan existing checkpoints |
|
|
125
|
+
| `experiments` | List all historical experiments |
|
|
126
|
+
| `query` | Natural language query ("best lr?") |
|
|
127
|
+
| `compare` | Compare two experiments |
|
|
128
|
+
| `visualize` | Model structure visualization (D3.js HTML) |
|
|
129
|
+
| `infer` | Run inference with checkpoint |
|
|
130
|
+
| `gallery` | Image filtering + selection |
|
|
131
|
+
| `dashboard` | Web control panel (standalone) |
|
|
132
|
+
| `project` | Project context management (init/show/scan/fill) |
|
|
133
|
+
|
|
134
|
+
## MCP Tools · MCP 工具
|
|
135
|
+
|
|
136
|
+
**24 read-only** (always available, no auth):
|
|
137
|
+
|
|
138
|
+
`get_training_status` · `get_metrics_history` · `list_checkpoints` · `compare_checkpoints` · `get_anomaly_history` · `get_recovery_history` · `get_summary` · `get_agent_decision_log` · `get_contract_status` · `list_contract_proposals` · `list_experiments` · `query_experiment` · `compare_experiments` · `get_model_structure` · `get_guardian_mode` · `get_gallery_config` · `get_import_format` · `inspect_source` · `get_training_log` · `get_post_training_checklist` · `get_pending_decisions` · `get_dashboard_config` · `recommend_charts` · `list_dashboard_templates`
|
|
139
|
+
|
|
140
|
+
**11 write** (token auth + training-phase gating):
|
|
141
|
+
|
|
142
|
+
`trigger_recovery` · `restart_with_params` · `stop_training` · `approve_contract_proposal` · `reject_contract_proposal` · `run_visualization` · `set_gallery_config` · `run_inference` · `submit_import` · `resolve_decision` · `set_dashboard_config`
|
|
143
|
+
|
|
144
|
+
→ Full API reference: [MCP_API_REFERENCE.md](MCP_API_REFERENCE.md)
|
|
145
|
+
|
|
146
|
+
## Configuration · 配置
|
|
147
|
+
|
|
148
|
+
Three layers, zero secrets in YAML:
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
DEFAULTS < guardian.yaml < GUARDIAN_* env vars < CLI flags
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
```yaml
|
|
155
|
+
# configs/guardian.yaml — only override what you need
|
|
156
|
+
watchdog:
|
|
157
|
+
max_retries: 3
|
|
158
|
+
monitor:
|
|
159
|
+
poll_interval: 5
|
|
160
|
+
mcp:
|
|
161
|
+
enable_write_tools: true
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
# Env override: GUARDIAN_ + section + __ + key
|
|
166
|
+
export GUARDIAN_WATCHDOG__MAX_RETRIES=5
|
|
167
|
+
export GUARDIAN_MCP_TOKEN=your-secret # write tool auth
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Project Status · 项目状态
|
|
171
|
+
|
|
172
|
+
| Metric | Value |
|
|
173
|
+
|--------|-------|
|
|
174
|
+
| Version | 0.2.0 |
|
|
175
|
+
| Modules | 16 (cp_1 ~ cp_16) |
|
|
176
|
+
| Production code | ~10,500 lines |
|
|
177
|
+
| Tests | 221 (CI on push) |
|
|
178
|
+
| MCP tools | 35 (24 read + 11 write) |
|
|
179
|
+
| CLI commands | 16 |
|
|
180
|
+
| Test coverage | ~13% (core paths: 100%) |
|
|
181
|
+
| Python | 3.10+ |
|
|
182
|
+
|
|
183
|
+
## Docs · 文档索引
|
|
184
|
+
|
|
185
|
+
| Document | Content |
|
|
186
|
+
|----------|---------|
|
|
187
|
+
| [ARCHITECTURE.md](ARCHITECTURE.md) | Architecture & workflow (ZH) |
|
|
188
|
+
| [DEPLOYMENT.md](DEPLOYMENT.md) | User manual (ZH) |
|
|
189
|
+
| [MCP.md](MCP.md) | MCP integration guide (ZH) |
|
|
190
|
+
| [MCP_API_REFERENCE.md](MCP_API_REFERENCE.md) | 35-tool API reference (ZH) |
|
|
191
|
+
| [MCP_QUICKSTART.md](MCP_QUICKSTART.md) | 5-minute MCP onboarding (ZH) |
|
|
192
|
+
| [IMPLEMENTATION_REPORT.md](IMPLEMENTATION_REPORT.md) | Per-module completion report (ZH) |
|
|
193
|
+
| [checkpoint/INDEX.md](checkpoint/INDEX.md) | Module index cp_1~cp_16 (ZH) |
|
|
194
|
+
| [checkpoint/cp_10.md](checkpoint/cp_10.md) | MCP layer design doc (ZH) |
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
MIT
|