feat: P0 训练闭环核心功能实现

P0-1 模型路径治理:
- 新增 003_model_path_governance.sql 迁移,models 表增加 can_train 字段
- create_model/update_model 自动计算 can_train(非API+有路径=可训练)
- _compute_job_payload_from_task_node 拒绝 API 模型和无可训练路径模型
- 平台诊断规则增加 API 模型/路径缺失检测

P0-2 数据集格式校验:
- 新增 dataset_format.py,支持 Alpaca/ShareGPT/DPO/CPT 格式校验
- 训练预检时自动根据 train_type 匹配格式并校验内容字段
- llama_dataset_info 增加 DPO/CPT 格式列映射

P0-3 训练完成产物入库:
- _ensure_trained_model 使用 compute 节点返回的真实 artifacts
- 注册 per-file artifact 记录(含 size_bytes/checksum_sha256)
- trained_models 表增加 artifact_dir 字段

P0-4 失败日志拉取:
- poll_compute_jobs_once 检测到 failed/stopped 时强制拉取最后 200 行日志
- apply_compute_job 持久化失败日志片段到任务 payload

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
wuyongtao
2026-07-28 13:10:53 +08:00
parent 525fc55cef
commit a9ab130d43
5 changed files with 320 additions and 24 deletions

View File

@@ -48,6 +48,21 @@ def _training_diagnostics(errors: list[str], warnings: list[str] | None = None,
text = "\n".join(source_items).lower()
diagnostics: list[dict[str, str]] = []
rules = [
(
["api 模型", "api模型", "api model"],
"API 模型不能用于本地训练",
"当前选择的基座模型为 API 类型LLaMA-Factory 需要本地可访问的模型路径。请在模型管理中创建或选择模型来源为「本地」且配置了算力节点路径的模型。",
),
(
["未配置算力节点", "未配置.*路径", "模型.*路径"],
"模型缺少算力节点路径",
"请在模型管理中编辑该模型,设置模型路径为算力节点可访问的本地目录。",
),
(
["不支持本地训练", "not trainable"],
"模型不可用于训练",
"当前选择的模型不支持作为 LLaMA-Factory 训练基座。请确认模型来源为本地、路径已配置且模型目录在算力节点上存在。",
),
(
["dataset columns missing", "keyerror", "history", "instruction", "input", "output", "messages"],
"训练数据字段不匹配",