跳到主要内容
训练指南章节 全部文档

TrainingProject:配置、训练与验收

SDK 0.2.0 项目配置、实际训练、评估、恢复和导出的完整工作流。

所有语言版本中的命令和代码均保持英文。请将大写占位符替换为您账户和付费作业中的实际值;请勿将真实密钥粘贴到共享笔记本或日志中。

TrainingProject 工作流

一份项目配置贯穿计划、训练、评估和导出。
  1. 项目 模型、目标和数据政策
  2. 计划 兼容性、课程和预算
  3. 执行 数据、训练和检查点
  4. 改进 有界的主题和回归评估
  5. 导出 经过验证的制品和可复现报告

项目: 模型、目标和数据政策. 计划: 兼容性、课程和预算. 执行: 数据、训练和检查点. 改进: 有界的主题和回归评估. 导出: 经过验证的制品和可复现报告

一个项目,一份可复现配置

项目配置绑定本地学生模型、付费教师参考模型、目标、数据政策、运行环境、课程和评估标准。Automatic 模式会解析兼容的默认设置;Advanced 模式提供受支持的明确选项。dry-run 计划会在训练前说明模型兼容性、主题、数据流、预算、指纹和预期制品。

  • Python 项目 API 与 fpai-training CLI 使用同一引擎。
  • 模型、数据集、评估器和配置路径都必须位于项目根目录内。
  • 固定自定义评估器版本,并保留运行清单。
示例 · json
{
  "schema_version": "1.0",
  "mode": "automatic",
  "objective": "Classify support messages as billing, account_access or technical_issue.",
  "model": {"path": "./models/student", "adapter": "transformers-causal-lm", "revision": null},
  "teacher": {"provider": "openai", "reference_model_id": 123},
  "data": {
    "sources": ["./data/train.jsonl"], "teacher_sharing": "none",
    "validation_path": "./data/validation.jsonl", "test_path": "./data/test.jsonl",
    "deduplicate": true, "seed": 42
  },
  "runtime": {"target": "customer_datacenter", "devices": "auto"},
  "training": {"method": "auto"},
  "curriculum": {"topics": ["intent", "ambiguous_requests", "class_balance"], "max_improvement_cycles": 3, "stop_on_regression": true},
  "budgets": {"max_training_minutes": 120, "max_teacher_requests": 1000, "max_storage_gib": 20},
  "checkpoints": {"keep_last": 3},
  "evaluation": {"rubric": "./rubric.json", "baseline_required": true},
  "output": {"directory": "./runs/german-001", "format": "safetensors"}
}
示例 · json
{
  "schema_version": "1.0",
  "mode": "advanced",
  "model": {"path": "./models/student", "adapter": "transformers-causal-lm", "revision": null},
  "teacher": {"provider": "openai", "reference_model_id": 123},
  "objective": "Classify support messages as billing, account_access or technical_issue.",
  "data": {"sources": ["./data/train.jsonl"], "teacher_sharing": "none", "validation_path": "./data/validation.jsonl", "test_path": "./data/test.jsonl"},
  "runtime": {"target": "customer_datacenter", "devices": [0, 1], "distributed": {"backend": "ddp", "nodes": 1}},
  "training": {
    "method": "LoRA",
    "epochs": 3,
    "learning_rate": 0.0002,
    "batch_size": 1,
    "gradient_accumulation_steps": 16,
    "max_sequence_length": 2048,
    "precision": "bf16",
    "lora": {"rank": 16, "alpha": 32, "dropout": 0.05}
  },
  "curriculum": {
    "topics": ["intent", "ambiguous_requests", "class_balance"],
    "max_improvement_cycles": 3,
    "stop_on_regression": true
  },
  "checkpoints": {"every_steps": 100, "keep_last": 3, "resume_validation": "strict"},
  "budgets": {"max_training_minutes": 120, "max_teacher_requests": 1000, "max_storage_gib": 20},
  "evaluation": {"rubric": "./rubric.json", "baseline_required": true},
  "output": {"directory": "./runs/german-advanced-001", "format": "safetensors"}
}
示例 · bash
fpai-training init --directory ./german-project
fpai-training doctor --config ./german-project/training.json
fpai-training plan --config ./german-project/training.json --dry-run
fpai-training run --config ./german-project/training.json
fpai-training status --run ./german-project/runs/german-001
fpai-training pause --run ./german-project/runs/german-001
fpai-training resume --run ./german-project/runs/german-001
fpai-training cancel --run ./german-project/runs/german-001
fpai-training evaluate --run ./german-project/runs/german-001 --split test
fpai-training export --run ./german-project/runs/german-001 --format safetensors
# init creates a project; doctor checks local compatibility; plan makes no teacher call.
# run requires current paid reference access, enforces budgets and trains locally.
# pause saves a checkpoint; resume verifies project fingerprints; cancel is terminal.
# evaluate reads local held-out rows; export validates the accepted local artifact.
示例 · python
import os
from fusionpointai_training import TrainingProject

project = TrainingProject.from_file(
    "./german-project/training.json",
    api_key=os.environ["FUSIONPOINTAI_API_KEY"],
)
plan = project.plan(dry_run=True)
result = project.run()
evaluation = project.evaluate(split="test")
artifact = project.export(format="safetensors")
# Related controls: project.status(), project.pause(), project.resume(), project.cancel().

训练与评估行为

Transformers 因果语言模型适配器会对兼容的模型和运行环境执行真实的 SFT、LoRA 或 QLoRA 优化。项目会协调付费教师访问、本地数据集、主题评估、回归检查和有界改进。不支持的架构、硬件或导出组合会在兼容性检查中失败。

  • 停止原因包括 accepted、budget_exhausted、no_progress、regression、cancelled 和 failed。
  • 原生检查点和运行状态保存在私有且由运行拥有的存储中。
  • 教师共享遵循项目政策;验证集和最终测试集保留在本地。
示例 · json
{
  "schema_version": "1.0",
  "name": "support-category-evaluation",
  "scale": {"minimum": 0.0, "maximum": 1.0},
  "criteria": [
    {"id": "support_category", "description": "Match the expected support category.", "metric": "macro_f1", "minimum_score": 0.85}
  ],
  "regression": {"maximum_score_drop": 0.02},
  "final_test": {"path": "./data/test.jsonl", "allow_training_use": false}
}
示例 · text
SDK 0.2.0 CLI AND PROJECT CONTRACT
Configuration/rubric values above are examples, not achieved scores or guarantees.
doctor must reject incompatible architecture, precision, hardware and export settings.
plan --dry-run validates and estimates; it must not update weights or start paid work.
run uses the declared data-sharing policy and enforces all configured budgets.
pause saves a valid atomic checkpoint before stopping owned training workers.
resume validates the checkpoint's model/config/data/evaluator fingerprints.
cancel requests termination of this run's workers; preserve useful logs and artifacts.
evaluate --split test must never feed test examples into training.
export validates files and manifests; never include credentials or unrelated cache files.

Project API:
TrainingProject.from_file(path, *, api_key) -> TrainingProject
plan(*, dry_run=True) -> dict
run() -> dict
status() -> dict
pause() -> dict
resume() -> dict
cancel() -> dict
evaluate(*, split="test") -> dict
export(*, format="safetensors") -> dict

Exit codes:
0 accepted/success; 2 invalid configuration; 3 incompatible runtime/model;
4 authentication/access; 5 budget exhausted; 6 acceptance not met;
7 execution failed; 130 interrupted.
Reports must record stop_reason and unmet criteria, not just an exit code.

检查报告与制品

项目运行会记录未经修改的基线、实测标准、回归、预算和未满足的要求。导出会验证本地模型或适配器文件并写入清单。SDK 行为取决于兼容的软件和硬件;示例不代表硬件基准或推理结果。

  • 仅凭训练不能声称模型等同于教师模型。
  • 文档示例不会自动发起付费调用或训练。
  • 使用制品前请检查实际的本地报告和文件。
示例 · text
TrainingProject delivery files
model/                   validated model or adapter weights and tokenizer assets
exports/<format>/        accepted delivery files with a SHA-256 manifest
run-manifest.json        pinned model/data/config/runtime versions
baseline-report.json     untouched student model's measured criteria
evaluation-report.json   final criteria, measured scores and regressions
artifact-manifest.json   safe relative paths, bytes and SHA-256 per file
training-report.json     real steps, timings, budgets and stop reason

Never export credentials, environment files or private cache directories.