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

创建并运行训练项目

安装 SDK 0.2.0、配置项目、检查计划并训练本地模型。

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

创建并运行项目

使用本地制品前,先检查计划和评估结果。
  1. 安装 Python 环境
  2. 配置 模型、数据和评估标准
  3. 计划 兼容性和预算
  4. 训练 本地优化
  5. 检查 评估结果和制品

安装: Python 环境. 配置: 模型、数据和评估标准. 计划: 兼容性和预算. 训练: 本地优化. 检查: 评估结果和制品

准备运行环境

请在专用虚拟环境中使用 Python 3.10 或更高版本。安装 training extra 和与运行环境兼容的 PyTorch 构建。TrainingProject 使用现有的 Transformers 因果语言模型适配器,并检查其对 SFT、LoRA 或 QLoRA 的支持。您需要账户 API 密钥、用于教师操作的有效付费参考模型访问权限、兼容的本地模型、获准的数据和充足的存储空间。选择运行环境不会自动配置硬件。

  • 基础软件包提供 TrainingClient 和项目 API;train extra 安装本地模型训练依赖。
  • 将 API 密钥保存在运行环境的密钥环境变量中,不要写入项目文件或命令参数。
  • QLoRA 需要兼容的 CUDA 运行环境和量化依赖。
示例 · bash
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
# Install the GPU-compatible PyTorch build for your runtime first.
python -m pip install 'fusionpointai-training[train] @ https://fusionpointai.com/downloads/fusionpointai-training.zip'
# API-only use without local training dependencies:
# python -m pip install 'fusionpointai-training @ https://fusionpointai.com/downloads/fusionpointai-training.zip'

配置并检查项目

创建项目目录,准备训练、验证和最终测试 JSONL 文件,然后编辑 training.json 和 rubric.json。设置本地学生模型路径、provider 和方案中包含的 reference_model_id。计划会验证配置、模型兼容性、数据指纹、共享政策、预算和输出,不会更改权重或调用教师模型。

  • 使用 schema_version 1.0;这是配置 schema 版本,不是软件包版本。
  • 使用解析结果位于项目根目录内的相对路径。
  • 每次运行都需要新的输出目录;resume 是单独操作,并会严格检查指纹。
示例 · bash
# Enter the key using a secure runtime secret facility or this history-safe prompt.
read -rs -p 'FusionPointAI API key: ' FUSIONPOINTAI_API_KEY
export FUSIONPOINTAI_API_KEY
printf '\n'
python --version
fpai-training --version
# After the project run, clear the shell value: unset FUSIONPOINTAI_API_KEY
示例 · 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"}
}
示例 · python
import os
from fusionpointai_training import TrainingProject

project = TrainingProject.from_file(
    "./support-project/training.json",
    api_key=os.environ["FUSIONPOINTAI_API_KEY"],
)
plan = project.plan(dry_run=True)
print("Topics:", plan["topics"], "Budgets:", plan["budgets"])
result = project.run()
print("Run:", result["run_id"], result["status"], result["stop_reason"])
evaluation = project.evaluate(split="test")
print("Accepted:", evaluation["accepted"], evaluation["report_path"])
artifact = project.export(format="safetensors")
print("Artifact:", artifact["artifact_path"], artifact["sha256"])

检查评估结果和本地制品

训练会在本地留出数据上运行未经修改模型的基线评估和最终评估。报告记录实测标准、回归、指纹、预算和未满足的要求。导出会验证本地 safetensors 模型或适配器包并写入清单。适配器仍需与之完全匹配且已固定版本的基础模型和 tokenizer。运行成功不代表任务质量超出 rubric 实测范围。

  • 基线和最终留出文件应与训练数据及教师输入分开保存。
  • 使用输出前请检查 evaluation-report.json 和 artifact-manifest.json。
  • 导出不会上传模型,也不会部署生产推理服务。
示例 · bash
cat ./support-project/runs/support-001/training-report.json
cat ./support-project/runs/support-001/evaluation-report.json
cat ./support-project/runs/support-001/artifact-manifest.json
sha256sum ./support-project/runs/support-001/exports/safetensors/artifact-manifest.json
# Compare the digest with the value returned by project.export().
# Adapter exports also require the matching base model and tokenizer.