You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/distillation_trainer.md
+1-20Lines changed: 1 addition & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,34 +54,15 @@ trainer.save_model()
54
54
55
55
## Usage tips
56
56
57
-
The [`experimental.distillation.DistillationTrainer`] needs three key parameters set via [`experimental.distillation.DistillationConfig`]:
57
+
The [`experimental.distillation.DistillationTrainer`] needs two key parameters set via [`experimental.distillation.DistillationConfig`]:
58
58
59
59
*`lmbda`: controls the student data fraction, i.e., the proportion of on-policy student-generated outputs. When `lmbda=0.0`, training is fully off-policy (dataset completions only). When `lmbda=1.0`, training is fully on-policy (student generates all completions). For values in between, each gradient accumulation slice is randomly assigned as on- or off-policy based on `lmbda`.
60
60
*`beta`: controls the interpolation in the Generalized Jensen-Shannon Divergence. When `beta=0.0` the loss approximates forward KL divergence, while `beta=1.0` approximates reverse KL divergence. Values in between interpolate.
61
-
*`distillation_objective`: selects the training objective. Use `"jsd"` for the generalized JSD/KL objective, or `"iw_opd"` for Importance-Weighted On-Policy Distillation, which reweights sampled-token reverse-KL policy-gradient updates by prefix teacher-student agreement. IW-OPD requires `lmbda=1.0`.
62
-
*`loss_top_k`: number of top tokens to use for the KL/JSD loss. Set to `0` for exact full-vocabulary computation (local teacher only), or `> 0` for a top-k approximation. See more about top-k with external teacher server below.
63
61
64
62
### On-policy vs. off-policy
65
63
66
64
Setting `lmbda=1.0` (fully on-policy) generally outperforms off-policy distillation because the student learns from its own mistakes rather than imitating trajectories it may never produce. The generation buffer ensures on-policy training stays efficient: prompts across gradient accumulation steps are batched into a single vLLM call.
67
65
68
-
### Importance-Weighted On-Policy Distillation
69
-
70
-
Set `distillation_objective="iw_opd"` to use Importance-Weighted On-Policy Distillation from [On the Position Bias of On-Policy Distillation](https://huggingface.co/papers/2606.22600). IW-OPD computes a sampled-token OPD advantage from teacher and student log-probabilities, then upweights earlier tokens and downweights later tokens according to accumulated teacher-student drift.
71
-
72
-
```python
73
-
config = DistillationConfig(
74
-
output_dir="distilled-model",
75
-
distillation_objective="iw_opd",
76
-
iw_opd_gamma=0.5,
77
-
lmbda=1.0,
78
-
)
79
-
```
80
-
81
-
IW-OPD is only available for fully on-policy training. It is incompatible with `use_liger_kernel=True`; when
82
-
`use_vllm=True`, set `vllm_sync_frequency=1`. The vLLM path requests sampled-token rollout log-probabilities and
83
-
uses them as the detached IW-OPD rollout policy log-probs.
84
-
85
66
### Using an external teacher server
86
67
87
68
For teachers that do not fit on training GPUs (e.g., 100B+ parameters), host the teacher on a separate vLLM server and set `use_teacher_server=True` with `teacher_model_server_url`:
DPPO replaces PPO/GRPO's heuristic ratio-clipping with a principled trust region based on direct policy divergence estimates. PPO-style clipping masks tokens based on the probability ratio π/μ, which over-penalizes low-probability tokens and under-penalizes high-probability ones. DPPO instead masks based on direct approximations of policy divergence (TV or KL), ensuring updates stay within a theoretically grounded trust region. Four divergence approximations are supported: `binary_tv`, `binary_kl`, `topk_tv`, and `topk_kl`.
693
-
694
-
```python
695
-
from trl.experimental.dppo import DPPOConfig, DPPOTrainer
Introduces Generalized Knowledge Distillation (GKD), which addresses distribution mismatch in KD for auto-regressive models by training the student on its own generated outputs with teacher feedback, instead of a fixed set of sequences. GKD supports flexible loss functions (e.g. beyond KL when the student cannot match the teacher) and integrates with RL fine-tuning (RLHF). The paper reports results on summarization, translation, arithmetic reasoning, and instruction-tuning. Used in TRL via [`experimental.distillation.DistillationTrainer`] and [`experimental.gkd.GKDTrainer`]. To reproduce the paper's setting, use this configuration:
1637
+
Introduces Generalized Knowledge Distillation (GKD), which addresses distribution mismatch in KD for auto-regressive models by training the student on its own generated outputs with teacher feedback, instead of a fixed set of sequences. GKD supports flexible loss functions (e.g. beyond KL when the student cannot match the teacher) and integrates with RL fine-tuning (RLHF). The paper reports results on summarization, translation, arithmetic reasoning, and instruction-tuning. Used in TRL via [`experimental.gkd.GKDTrainer`], which exposes the paper's on/off-policy mixing (`lmbda`). [`experimental.distillation.DistillationTrainer`] implements the same generalized-JSD objective for the always-on-policy case. To reproduce the paper's setting, use this configuration:
1669
1638
1670
1639
```python
1671
-
from trl.experimental.distillationimportDistillationConfig
1640
+
from trl.experimental.gkdimportGKDConfig
1672
1641
1673
1642
# XSum summarization task (Table A.1 of the paper)
1674
-
training_args =DistillationConfig(
1643
+
training_args =GKDConfig(
1675
1644
lmbda=0.5, # λ student data fraction (Section 3 of the paper)
1676
1645
beta=0.5, # β Generalized JSD interpolation, 0=KL, 1=reverse KL (Section 3 of the paper)
1677
1646
temperature=1.0, # student training temperature (Appendix A of the paper)
1678
1647
max_steps=40000, # training steps (Table A.1 of the paper)
1679
1648
learning_rate=3e-4, # learning rate (Table A.1 of the paper)
1680
1649
per_device_train_batch_size=32, # batch size (Table A.1 of the paper)
1681
1650
warmup_steps=2000, # warm-up steps (Table A.1 of the paper)
1682
-
max_completion_length=64, # max output tokens (Table A.1 of the paper)
1651
+
max_new_tokens=64, # max output tokens (Table A.1 of the paper)
1683
1652
)
1684
1653
```
1685
1654
1686
1655
### On the Position Bias of On-Policy Distillation
Introduces Importance-Weighted On-Policy Distillation (IW-OPD), which addresses the position bias in OPD by reweighting sampled-token distillation updates according to accumulated teacher-student prefix discrepancy. Early tokens keep larger weights, while later tokens after high drift are downweighted. Used in TRL via [`experimental.distillation.DistillationTrainer`] with `distillation_objective="iw_opd"`.
1659
+
Introduces Importance-Weighted On-Policy Distillation (IW-OPD), which addresses the position bias in OPD by reweighting sampled-token distillation updates according to accumulated teacher-student prefix discrepancy. Early tokens keep larger weights, while later tokens after high drift are downweighted. Used in TRL via [`experimental.iw_opd.IWOPDTrainer`] with `distillation_objective="iw_opd"`.
1691
1660
1692
-
The paper reports its main experiments with a verl PPO trainer and vLLM rollouts. `DistillationTrainer` exposes the matching distillation and rollout settings below; PPO-specific settings from the paper such as clipping range `0.2`, dual-clip constant `3.0`, PPO epochs, entropy coefficient, KL reward penalty, auxiliary KL, and rollout importance correction are not `DistillationConfig` parameters.
1661
+
The paper optimizes IW-OPD with a clipped policy-gradient setup (verl) and vLLM rollouts. `IWOPDTrainer` exposes the matching distillation and rollout settings below; policy-optimization settings from the paper such as clipping range `0.2`, dual-clip constant `3.0`, inner PPO epochs, entropy coefficient, KL reward penalty, auxiliary KL, and rollout importance correction are not `IWOPDConfig` parameters.
1693
1662
1694
1663
```python
1695
-
from trl.experimental.distillationimportDistillationConfig
1664
+
from trl.experimental.iw_opdimportIWOPDConfig
1696
1665
1697
-
# Table 6 and Algorithm 1 of the paper, mapped to DistillationConfig where available.
1698
-
training_args =DistillationConfig(
1666
+
# Table 6 and Algorithm 1 of the paper, mapped to IWOPDConfig where available.
1667
+
training_args =IWOPDConfig(
1699
1668
distillation_objective="iw_opd",
1700
1669
iw_opd_gamma=0.5, # γ amplification, Algorithm 1 and Appendix C.3
Copy file name to clipboardExpand all lines: docs/source/vllm_integration.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
This document will guide you through the process of using vLLM with TRL for faster generation in online methods like GRPO and Online DPO. We first summarize a tl;dr on how to use vLLM with TRL, and then we will go into the details of how it works under the hood.
4
4
5
5
> [!WARNING]
6
-
> TRL currently only supports vLLM versions from `0.16.0` to `0.24.0`. Please ensure you have a version in this range installed to avoid compatibility issues.
6
+
> TRL currently only supports vLLM versions from `0.17.0` to `0.25.1`. Please ensure you have a version in this range installed to avoid compatibility issues.
7
7
8
8
> [!TIP]
9
9
> The following trainers currently support generation with vLLM:
0 commit comments