Skip to main content

OPD Distillation Training Overview

Bailian OPD Distillation Training (OPD) training overview — basic concepts, training method selection, end-to-end flow, environment preparation, and job submission

This article helps you understand the basic concepts, applicable scenarios, and end-to-end workflow of Model Studio OPD distillation training. It provides an overview and key notes; for detailed step-by-step instructions for each stage, see the corresponding documents:

Docs

Content

Model OPD development

Pure distillation and Reward function development, data format, function testing

Agentic OPD development

Custom Rollout (passing the tools parameter to produce structured tool_call), Agentic Reward development

Training Configuration

Submission Method, teacher model configuration, hyperparameters, environment variables, tuning tips and pitfalls

Observability configuration

Tracing integration, custom metrics, metric dictionary, effect evaluation, troubleshooting decision tree

OPD distillation training is a training method where a stronger teacher model supervises a student model token by token. The teacher model provides a probability distribution for every token of the student model's output, and the student model generates the output itself, receiving a guidance signal at every step. The goal is to transfer a large model's capabilities on a specific task to a smaller model of the same family, reducing inference costs while maintaining performance.ImplementationEach step of OPD training:
  1. Student generation: the student model generates a segment of output
  2. Teacher provides distribution: the teacher model provides a probability distribution for every token position of the output (that is, how likely the teacher considers each token to appear at that position)
  3. Compute divergence: the student model compares its own probability distribution with the teacher's distribution and computes the divergence at every token position (KL divergence, a metric that measures the difference between two probability distributions)
  4. Update toward the teacher: the parameters are updated using this as the loss, so that every token moves closer to the teacher model
The teacher model only provides probability distributions; it does not generate text or participate in conversations or tool calls. Every token position receives a guidance signal, rather than a single overall score given only after the entire output is complete.Differences between OPD and fine-tuning / traditional model distillation

dimension

Fine-tuning (SFT)

Traditional model distillation

OPD distillation training

Training Data

Manual Annotation

Teacher model pre-generated output

Student model generation

Guidance method

Fixed labels

Complete teacher model output

Teacher model per-token probability distribution

Student model participates in generation

No

No

Yes

Error correction

None

None

Per-token correction

End-to-End Overview

OPD training involves 5 steps, from environment preparation to model deployment:
  1. Environment preparation — Install the SDK, obtain an API Key, and complete authorization
  2. Prepare data and code — JSONL data; pure distillation requires no function code
  3. Submit the training task — Pass teacher_model to trigger distillation; pure distillation is zero-code
  4. Monitor training status — Check the distillation loss, whether the teacher model signal is healthy, and validation set metrics
  5. Publish and deploy the model — The final Checkpoint is published automatically; after deployment, call the model via API

How It Works

The data flow of each training round is as follows:
训练数据(用户问题 + 参考答案)
            │
            ▼
学生模型生成:学生模型按当前策略生成候选输出
            │
            ▼
教师模型前向:教师模型对学生模型输出逐 token 给概率分布
            │
            ▼
蒸馏更新:学生模型最小化自身分布与教师模型分布差异(KL 散度)
            │
            ▼
(可选)Reward 评分:启用 Reward 时叠加任务奖励信号
            │
            ▼
循环迭代:用更新后的模型重新采样,逐轮向教师模型靠拢
The teacher model only provides probability distributions; it does not generate text or participate in conversations or tool calls. In pure distillation, the student model is guided only by the teacher model token by token; when rewards (Reward) are also enabled, the teacher model distribution and task rewards jointly drive the student model.

Models and Training Units

The teacher model must be a model activated in Model Studio, and its capability must be stronger than that of the student model.
  • China (Beijing)
  • Singapore

Teacher model

Student model

Beta status

Recommended training units

qwen3.5-122b-a10b

qwen3.5-27b

Beta

Type IV (MTU4) × 28

qwen3.5-397b-a17b

qwen3.5-27b

Beta

Type IV (MTU4) × 28

qwen3.5-122b-a10b

qwen3.5-2b

Beta

Type IV (MTU4) × 11

qwen3.5-27b

qwen3.5-2b

Beta

Type IV (MTU4) × 7

qwen3.5-35b-a3b

qwen3.5-2b

Beta

Type IV (MTU4) × 7

qwen3.5-397b-a17b

qwen3.5-2b

Beta

Type IV (MTU4) × 11

qwen3.5-122b-a10b

qwen3.5-35b-a3b

Beta by invitation

Type IV (MTU4) × 20

qwen3.5-397b-a17b

qwen3.5-35b-a3b

Beta by invitation

Type IV (MTU4) × 20

qwen3.5-122b-a10b

qwen3.5-4b

Beta by invitation

Type IV (MTU4) × 11

qwen3.5-27b

qwen3.5-4b

Beta by invitation

Type IV (MTU4) × 7

qwen3.5-35b-a3b

qwen3.5-4b

Beta by invitation

Type IV (MTU4) × 7

qwen3.5-397b-a17b

qwen3.5-4b

Beta by invitation

Type IV (MTU4) × 11

qwen3.5-122b-a10b

qwen3.5-9b

Beta by invitation

Type IV (MTU4) × 24

qwen3.5-27b

qwen3.5-9b

Beta by invitation

Type IV (MTU4) × 20

qwen3.5-35b-a3b

qwen3.5-9b

Beta by invitation

Type IV (MTU4) × 20

qwen3.5-397b-a17b

qwen3.5-9b

Beta by invitation

Type IV (MTU4) × 24

qwen3.8-flash

qwen3.5-9b

Beta by invitation

Type IV (MTU4) × 16

qwen3.8-max

qwen3.5-9b

Beta by invitation

Type IV (MTU4) × 72

QuickStart

Complete the full 5-step workflow with the pure-distillation basic sample—training can start with zero code. Pure distillation requires no functions to write; the teacher model simply guides the student model's training token by token. The OPD distillation training entry is now available as a training method in the console's Create Training Task page. Task submission, metric monitoring, and output management take place in the model fine-tuning console. The complete configuration and submission workflows in this section and the following ones are based on the DashScope SDK (the demo includes an OPD-capable wheel).

Environment preparation

Environment preparation covers the following items: API Key, service access authorization, SDK installation, workspace directory, and core environment variables. API Key: Obtain it from the Model Studio console API-KEY page and set it as the environment variable DASHSCOPE_API_KEY. Service access authorization: On first use, grant one-click authorization in the model fine-tuning console for three cloud services: ARMS (Application Real-Time Monitoring Service, which handles OpenTelemetry metric reporting), Function Compute (FC), and Log Service (SLS). OpenTelemetry is an open-source observability data standard; ARMS hosts and visualizes it. The three services are used respectively for metric reporting, function execution, and log collection. SDK: Install from the wheel file bundled in the sample directory (the version updates with the sample; currently 1.27.5):
# 安装示例目录附带的 dashscope SDK wheel 文件(版本随示例更新,当前 1.27.5)
# 该 wheel 同名相对路径需填入 FC_PYPI_LIB,供远端函数运行时安装
python -m pip install ./dashscope-*.whl
Download the sample code package — includes the wheel (a Python packaged install file), function code, data, dependencies, and the submission script. Extract it to obtain the workspace directory below.
Workspace directory is structured as follows. For the full implementation of the obtain and submission scripts, see Training Configuration:
workspace/
├── dashscope-*.whl          # SDK wheel:示例附带的 dashscope 安装包,本机与远端均按此版本安装
├── functions/               # Rollout/Reward 函数代码目录;纯蒸馏 functions=None 可留空
├── data/                    # JSONL 训练/验证数据;每行一个样本(messages + rollout_extra)
├── requirements.txt         # 函数依赖清单;FC_LAYER_USED=true 时注册阶段据此构建 layer,跳过冷启动 pip
└── submit_job.py            # 提交脚本:调用 AgenticRL().run() 完成注册→上传→提交三步
Three core environment variables:
  • DASHSCOPE_API_KEY (required): authentication.
  • FC_PYPI_LIB (required): the SDK package installed in the function runtime; set it to the wheel's relative path (resolved remotely—an absolute local path will not match). Pure distillation (functions=None) does not involve a function runtime, so you can skip this item.
  • FC_LAYER_USED (optional, defaults to true): when true, a layer is built from requirements.txt at registration, skipping pip installation during cold start; when false, the remote runtime installs it during cold start.
export DASHSCOPE_API_KEY="sk-your-api-key"                       # 鉴权密钥,从百炼控制台 API-KEY 页获取(必需)
export FC_PYPI_LIB=./dashscope-1.27.5-py3-none-any.whl          # 远端函数运行时安装的 SDK 包,填 wheel 相对路径;纯蒸馏可不设(必需,纯蒸馏除外)
export FC_LAYER_USED=true                                        # true:注册阶段按 requirements.txt 构建 layer,跳过冷启动 pip 安装;false:远端冷启动安装
Set FC_PYPI_LIB to the actual wheel file name (the version number updates with the sample). Before submission, the sample script verifies that the installed SDK's AgenticRL.run accepts the teacher_model parameter; if it does not, the script exits with an error directly. For other environment variables (control-plane endpoint, inference endpoint, log level, etc.), see Training Configuration.

Prepare data and code

Each line in a JSONL file is one sample containing the messages and rollout_extra fields. messages is the conversation input (ChatML format), and rollout_extra holds reference answers or other business data to be consumed when Reward/custom Rollout is enabled.
{
  "messages": [                          // 对话输入,ChatML 格式;每条 message 含 role 与 content
    {"role": "user", "content": "<您的业务问题>"}
  ],
  "rollout_extra": {"solution": "<参考答案或其他业务数据>"}  // 参考答案/业务数据,供 Reward 或自定义 Rollout 启用时消费;纯蒸馏仅透传不消费
}
A few dozen samples are enough for quick validation; for formal training, use hundreds to thousands of samples depending on task complexity. In pure distillation, rollout_extra is just passed through and not consumed.

Submit a training task

The entry point is AgenticRL().run(...): passing teacher_model triggers distillation. run() completes everything in one step: register functions to FC → upload training data → submit the training task. Pure distillation registers no functions.
The following is a minimal submission code example, with comments explaining each parameter. See submit_job.py in Training Configuration for the complete implementation. teacher_model is a placeholder; define it yourself.
import asyncio
from dashscope.finetune.agentic_rl import AgenticRL          # OPD 提交客户端
from dashscope.finetune.reinforcement import (
    TrainingDataset, ValidationDataset, DataSourceType,       # 训练/验证数据集及数据源类型
)

async def main():
    client = AgenticRL()
    result = await client.run(
        job_name="my-opd-job",                                # 任务名(控制台展示用)
        model="qwen3.5-9b",                       # 学生模型(基座模型,被蒸馏对象)
        teacher_model="your-teacher-model-id",     # 教师模型,OPD 唯一新增参数;传值即触发蒸馏
        training_datasets=[TrainingDataset(
            data_source_type=DataSourceType.FILE_ID,          # 以文件方式上传训练数据
            file_name="./data/train.jsonl")],
        validation_datasets=[ValidationDataset(
            data_source_type=DataSourceType.FILE_ID,          # 验证集同样以文件方式上传
            file_name="./data/validation.jsonl")],
        functions=None,                            # 纯蒸馏:不注册任何函数;Agentic OPD 在此传 Rollout/Reward 函数
        hyper_parameters={
            "n_epochs": 1, "n_rollouts": 8, "learning_rate": 1e-6,  # 蒸馏是微调模型已有能力,学习率起点 1e-6
            "eval_steps": 1, "ppo_mini_batch_size": 8,
            "lr_scheduler_type": "cosine",  # kl_loss_coef OPD 未启用,见训练配置
            # opd_teacher_* 部署参数见训练配置
        },
        resources={
            "charge_type": "mtu_postpaid",           # MTU 后付费计费
            "mtu_spec_code": "MTU4",                  # 训练单元规格
            "mtu_capacity": 24,                      # 容量(并发资源数)
        },
    )
    # HTTP 200 返回 job_id(查询训练状态的唯一标识);否则打印原始响应便于排查
    print(result.output.job_id if result.status_code == 200 else result)

asyncio.run(main())                                  # 启动异步主函数
You can also submit via a configuration file or the CLI (dashscope rl run). For an item-by-item explanation of the three submission methods and their fields, see Training Configuration.

Getting started tips

  • Start with the examples: for plain text output tasks, start from the Model OPD examples; when output relies on API-level tool calls or multi-turn/custom interactions, start from the Agentic OPD examples.
  • Start with a small dataset: validate the pipeline with a few dozen samples + n_epochs=1 before switching to the full dataset, to avoid discovering configuration errors only after burning MTU on the full dataset.
  • Keep hyperparameters at defaults: start learning_rate at 1e-6 (distillation fine-tunes existing model capabilities rather than rebuilding them, and an overly large learning rate easily breaks the output format) and use cosine for lr_scheduler_type; when tuning, change only one variable at a time and train at least eval_steps × 3 steps before judging the trend.
  • On FAILED, check logs first: task failed → check the error at the end in the Logs tab, or call AgenticRL.logs(job_id="ft-xxx", lines=100) from the SDK.

Post-training workflow

Observing and evaluating results

The job_id returned by run() is the unique identifier for querying training status. Open the task detail page in the model fine-tuning console, which has four tabs: metrics, trajectories, output, and logs. Key metrics to watch:
  • trace/distillation/valid_token_rate close to 1.0 (the teacher model signal is complete).
  • actor/distillation/loss decreasing or stabilizing (the student model is converging toward the teacher model).
  • When Reward is enabled, also check that validation/data/reward/mean@1 and each dimension of trace/reward_metrics rise relative to the baseline.
Post-training evaluation should keep a pre-training baseline and maintain consistent evaluation conditions (the same evaluation set and decoding parameters). For full metric definitions, trajectory viewing, acceptance criteria, and a troubleshooting decision tree, see Observability Configuration.

Release and deployment

After training completes, the last Checkpoint is automatically published to My Models. To publish an intermediate Checkpoint, go to the output page of the model fine-tuning console and do it manually. Published models can be deployed on the My Models page, and once deployed they can be called via API.

Applicable Scenario

Applicable scenarios expand step by step with capability complexity: pure distillation is the basic capability, while Reward and custom Rollout are advanced capabilities layered on top as needed (introducing extra components and more complex training/generation pipelines).
  • Pure distillation (basic): teacher model + data only, no function components to write → Model OPD Development
  • +Reward (advanced): add a scoring function to layer task rewards on top of the teacher model's token-by-token guidance (scoring against reference answers or multi-dimensional metrics) → Model OPD Development
  • +Custom Rollout (advanced, Agentic OPD): customize the generation process when output relies on tool calls/multi-turn interactions; can be combined with Reward or used alone → Agentic OPD Development
The two advanced capabilities can be enabled independently and combined freely; when choosing, look at the generation path first: single-turn generation suffices → the first two levels (Model OPD); structured mechanisms (such as native tool calls) or custom interactions needed → the third level (Agentic OPD).

Next steps

  • Model OPD Development: full details of function development (Rollout/Reward functions, Tracing integration).
  • Agentic OPD Development: custom Rollout (passing the tools parameter, structured output) and Agentic Reward development.
  • Training Configuration: submission methods, item-by-item field explanations, hyperparameters and environment variables.
  • Observability Configuration: metric definitions, trajectory viewing, acceptance criteria, and a troubleshooting decision tree.

FAQ

When to choose OPD over SFT

If you need token-by-token error correction and the student model to learn from its own generations → OPD; if you only have fixed annotations, are budget-sensitive, and do not require online error correction → SFT.

Can training effectiveness be judged without a reward

Yes. Pure distillation relies on valid_token_rate approaching 1.0 and loss decreasing and stabilizing to judge whether the teacher model's signal has been absorbed; final effectiveness is judged by independent post-training evaluation (keep a baseline and compare under the same conditions). If you need to optimize online against the task objective during training, layer Reward on top (the advanced usage of Model OPD), at the cost of providing a computable Reward function.