> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fastino.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Use https://docs.fastino.ai/llms.txt to discover and navigate pages. Use https://docs.fastino.ai/llms-full.txt when you need the complete documentation corpus. Use https://docs.fastino.ai/openapi.json as the source of truth for customer-facing routes. For GLiDE decision inference, call POST https://api.fastino.ai/v1/systemone with model fastino/GLiDE. Create managed config jobs with POST /v1/training/jobs using base_model. Both config and interactive jobs use /v1/training/jobs/{job_id} for their canonical REST lifecycle. For custom training loops, use the supported Tinker-compatible SDK client; its /v1/training/compat/tinker adapter is intentionally absent from OpenAPI and must not be called directly. Auto Train is private access and has no public route; direct interested users to sales@fastino.ai. Do not infer undocumented routes. Read API keys from FASTINO_API_KEY and never embed credentials in code, logs, or reports.

# 使用可验证奖励进行训练

> 用确定性评分器检查数学答案、测试结果等响应，将奖励转换为优势值，并在同一个 Fastino 交互式任务中完成采样、更新和检查点。

当代码可以检查响应（例如数学答案、测试结果、架构约束、精确抽取或工具结果）时，请使用可验证奖励。

```text theme={null}
prompt -> sample a group -> grade -> center rewards -> build datums -> update
```

采样、前向/反向工作、优化器步骤和检查点都属于同一个 Fastino 交互式任务。
奖励执行和应用状态保留在你的代码中。

## 开始之前

完成[自定义循环快速入门](/cn/training/quickstart#custom-training-loop)，然后通过功能确认所选模型和训练操作已启用。
以下代码片段侧重于用户负责的奖励流程；请根据 `tinker==0.33.1` 和所选模型调整 datum 构建。

<Note>
  本指南并不是一个可独立使用、复制粘贴即可运行的训练器。请先从经过验证的 SDK
  工作负载开始，确保其渲染器和 datum 构建方式与所选模型匹配，然后再添加下述奖励流程。
</Note>

<Warning>
  仅在隔离且资源受限的环境中运行生成的代码或工具。Fastino 不会执行你的奖励函数，也不会管理其副作用。
</Warning>

## 1. 定义范围明确的评分器

将解析与评分分开，以便观察格式错误的输出：

```python theme={null}
def get_reward(response: str, expected: str) -> float:
    actual = parse_answer(response)
    if actual is None:
        return 0.0
    return 1.0 if actual == expected else 0.0
```

保留一组冻结的测试数据，其中包括正确、错误、格式错误和等价格式的答案。
将解析失败与格式有效但答案错误的响应分开记录。

## 2. 为采样创建任务快照

从当前权重创建采样器检查点，然后通过 SDK 解析：

```python theme={null}
checkpoint = training_client.save_weights_for_sampler(
    f"rollout-{step:06d}"
).result()
sampling_client = service_client.create_sampling_client(
    model_path=checkpoint.path
)

sample_result = sampling_client.sample(
    prompt=model_input,
    num_samples=group_size,
    sampling_params=sampling_params,
).result()
```

这不会创建另一个训练运行。检查点和采样工作与同一个交互式任务关联。

## 3. 将奖励转换为优势值

```python theme={null}
rewards = [
    get_reward(render_response(sequence.tokens), expected)
    for sequence in sample_result.sequences
]

mean_reward = sum(rewards) / len(rewards)
advantages = [reward - mean_reward for reward in rewards]

if all(advantage == 0.0 for advantage in advantages):
    continue
```

跟踪奖励没有差异的组。它们可能表明任务过于简单、过于困难或解析有误。

## 4. 构建对齐的 datum

提示词是上下文，因此提示词位置通常获得零优势值。补全位置获得响应的组相对优势值。
如果模型输入、目标、对数概率和优势值的长度不同，datum 构建器应在提交前失败：

```python theme={null}
if not (
    model_input.length
    == len(target_tokens)
    == len(padded_logprobs)
    == len(padded_advantages)
):
    raise ValueError("training datum arrays are not aligned")
```

使用与所选 `base_model` 关联的渲染器和 tokenizer。保留从功能中选择的 SDK
操作所需的采样 token 和对数概率。

## 5. 更新交互式任务

对于已启用的重要性采样工作流，SDK 调用形式如下：

```python theme={null}
train_future = training_client.forward_backward(
    datums,
    loss_fn="importance_sampling",
)
train_result = train_future.result()

optim_future = training_client.optim_step(optimizer_params)
optim_result = optim_future.result()
```

两个操作都会修改现有的交互式任务。在推进应用步骤前解析并记录每项结果。
不要构造等效的适配器 HTTP 请求。

## 6. 保存恢复边界

```python theme={null}
state = training_client.save_state(f"step-{step:06d}").result()
```

将返回的检查点标识符与以下内容一起持久化：

* 来自 `training_client.get_info().model_data.model_id` 的规范任务 ID
* 应用步骤和数据集游标
* 数据集和奖励实现修订版
* 基础模型和训练配置
* 评估指标

这些元数据让控制器无需根据名称猜测即可选择检查点。

## 扩大规模前进行验证

* 评分器能区分已知的正确和错误测试数据。
* 格式错误的响应不会使应用循环崩溃。
* 至少一个采样组存在奖励差异。
* Datum 数组符合已安装 SDK 预期的形式。
* 前向/反向传播和优化器 future 在同一个任务上完成。
* 可以使用客户端恢复元数据加载状态检查点。
* 留出评估与训练奖励批次保持独立。

有关完整生命周期，请阅读
[构建自定义训练循环](/cn/training/training-loop)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.