Repository navigation
Conversation
d755681 to
1132699
Compare
1132699 to
2c283a0
Compare
|
All three are fixed in 2c283a0. SDPO skips EMA adapter pre-registration (high). SDPO omits new distillation config wiring (medium). DoRA magnitude vector (medium). The QLoRA cast in both trainers now iterates
One gap worth stating: the DoRA exclusion has no test, because it needs a quantized model, which the experimental suite does not build. The change is a line-for-line match with the main trainers instead. |
- `distillation_kl_clip` caps the summed per-token divergence before averaging. - `distillation_topk_support` lets `topk_logits` project onto the teacher's top-k, with `use_teacher_server=True` aligning the field to `"teacher"`. - `teacher_chat_template_kwargs` forwards extra `apply_chat_template` kwargs to the teacher prompt, and the teacher is scored on the untruncated prompt so generation and teacher logits agree. - `quantization_config` accepts a `BitsAndBytesConfig` for QLoRA, casting trainable adapter weights to bf16 while skipping DoRA's magnitude vector. - The EMA `"teacher"` adapter is registered in `__init__`, before accelerate or DeepSpeed wraps the model, and the callback no longer re-adds it. - Unsupported `parallelism_config` values are rejected at construction. - `generation_kwargs` and `chat_template_kwargs` are valid dict CLI fields. SDFT and SDPO receive the same changes; the trainers are self-contained by design, so the code is duplicated rather than shared.
2c283a0 to
c88e7c9
Compare
The combined branch: DOPD advantage-gap routing, the distillation plumbing (kl_clip, teacher top-k support, teacher chat-template kwargs with untruncated teacher tokenization, QLoRA, EMA teacher adapter pre-registration, parallelism rejection), and the cross-rank metric averaging fix, with the config validation and tests for each. Split into huggingface#7654 (metric), huggingface#7655 (plumbing), and huggingface#7656 (DOPD) for review. The PEFT + ZeRO-3 guard that this branch also carried was dropped: it rejected a combination that is known to work, and huggingface#6829 owns that fix.
|
@ucalyptus, #6829 is now updated at This overlaps the Trainer-side EMA pre-registration blocks here. I propose landing the callback initialization and synchronization repair through #6829, while keeping your config, loss, teacher-server and QLoRA changes in #7655. Rebasing on that fix would let you remove the overlapping Trainer-side initialization calls without losing those independent changes. Both official Trainer paths pass two-rank ZeRO-3 training with checkpointing off and on, including exact teacher/student equality after two steps at update rate 1. Could you align the overlapping initialization changes with #6829 so we avoid introducing two initialization paths for the same adapter? |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1a92fbe. Configure here.
The QLoRA bf16 cast ran before the EMA `teacher` adapter was registered, so that adapter kept the fp32 dtype PEFT gives it in `add_adapter` (`autocast_adapter_dtype`), while the student adapter was bf16. Move the cast below the registration and match LoRA parameters by name, since the teacher adapter is frozen by then.

Split out of #6237, which grew to cover several unrelated changes. This is the second piece, after #7654 (metric averaging); the two do not overlap.
Fixes and small features in the SDFT/SDPO distillation path. They are separate concerns that happen to touch the same config and loss plumbing, so they are grouped here rather than in one PR each. Happy to split further if you want them apart.
distillation_kl_clipcaps the summed per-token divergence before averaging, so outlier tokens cannot dominate the signal. Supported forfull_logitsandtopk_logits.distillation_topk_supportletstopk_logitsproject onto the teacher's top-k logits. Withuse_teacher_server=Truethe field is aligned to"teacher", because the vLLM server only returns the teacher's top-k.teacher_chat_template_kwargsforwards extraapply_chat_templatekwargs when the teacher prompt is built, for cases like a thinking teacher paired with a non-thinking student. The teacher is also scored on the untruncated prompt now, since the problem leads the teacher template and left-truncation would drop it. Generation used the truncated prompt before, so teacher logits and completions could disagree.quantization_configaccepts aBitsAndBytesConfigfor QLoRA, and trainable adapter weights are cast to bf16 per the QLoRA paper (paragraph 3 of https://huggingface.co/papers/2305.14314)."teacher"adapter is registered in__init__instead of at the firsttrain()step, so it exists before accelerate or DeepSpeed wraps the model. ZeRO-3 registers each module once at initialization and cannot adopt later additions.PEFTAdapterEMACallbackno longer re-adds an adapter that is already registered; PEFT rejects a duplicate name.parallelism_configvalues that the trainer cannot support (context or sequence parallel) are rejected at construction.generation_kwargsandchat_template_kwargsare listed as valid dict CLI fields, and both may be passed as a string.SDFT and SDPO receive the same changes. The two trainers are self-contained by design, so the code is duplicated rather than shared.
Tests
tests/experimental/test_distillation_plumbing.pyis new: eleven CPU-only tests. Six cover the loss plumbing on hand-built logits (topk_supportpicks different token sets for student and teacher support and rejects an invalid value;kl_clipbounds the summed divergence,Nonedisables it, and it is rejected for modes without a full logit distribution; teacher-server alignment). Five more cover the config and init paths: SDPO parity for both new fields, and an EMA pre-registration test per trainer that asserts the"teacher"adapter exists straight after construction, withouttrain().CPU,
trl-internal-testing/tiny-Qwen2ForCausalLM-2.5, one file at a time:The new config fields are also exercised by the behavior test's trainer construction, which now passes
distillation_topk_supportanddistillation_kl_clip.Not covered by a test: the QLoRA cast's DoRA exclusion, which needs a quantized model.
Note
Medium Risk
Changes affect core distillation loss math, teacher prompt tokenization, and PEFT/DeepSpeed initialization order; training dynamics can shift when new options are used, though defaults largely preserve prior behavior.
Overview
This PR extends SDFT and SDPO distillation plumbing with configurable top-k support, optional KL capping, and several trainer/init fixes mirrored in both code paths.
Loss and config:
distillation_topk_supportchooses whether top-k logit distillation uses the student or teacher vocabulary support (default"student"); withuse_teacher_serverandtopk_logits, config is auto-aligned to"teacher".distillation_kl_clipcaps the summed per-position divergence (after vocab sum) forfull_logitsandtopk_logits, and is rejected forsampled_token. Sharedloss_utilsin both packages wire these throughcompute_divergenceand the top-k/full logit objectives.SDFT-specific:
teacher_chat_template_kwargsand untruncated teacher prompt tokenization keep teacher scoring/generation consistent when the problem must not be left-truncated away.Trainer init: Optional
quantization_configfor QLoRA; trainable LoRA weights cast to bf16 on quantized models (DoRA magnitude excluded). EMA"teacher"PEFT adapter is registered and zeroed in__init__for ZeRO-3 compatibility;PEFTAdapterEMACallbackskips re-adding an existing adapter. Unsupported context/sequenceparallelism_configis rejected at config time. Dict CLI fields expanded for generation/chat template kwargs (including string forms).Tests: New
test_distillation_plumbing.py(CPU, hand-built logits) plus behavior test defaults updated for the new config fields.Reviewed by Cursor Bugbot for commit a4335d3. Bugbot is set up for automated code reviews on this repo. Configure here.