Do not quantize the teacher by default in the distillation and GOLD entry points - #6769
Do not quantize the teacher by default in the distillation and GOLD entry points#6769behroozazarkhalili wants to merge 3 commits into
Conversation
…ization config
Both distillation scripts put `get_quantization_config(model_args)` into the
teacher's init kwargs, so a `--load_in_4bit` intended for the student also
quantized the teacher. The teacher defines the reference distribution the
student is trained to match and receives no gradients, so quantizing it
degrades the training signal for a saving that matters less than on the
student. The literature consensus is to leave it in full precision.
`teacher_model_init_kwargs` already overrides these defaults, so a quantized
teacher stays available via
`--teacher_model_init_kwargs '{"quantization_config": {...}}'`.
Closes #6720
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
…ion in gkd and gold Both recipes copied `get_quantization_config(model_args)` (driven by `--load_in_4bit` / `--load_in_8bit`, which describe the student) into `teacher_model_init_kwargs`. Quantizing the teacher degrades the reference distribution the student is trained to match, so a user asking only for a quantized student silently got a degraded training signal. This is the same defect already fixed in the two distillation scripts; per AGENTS.md the duplicated block has to stay aligned across all copies. gkd.py additionally assigned over `training_args.teacher_model_init_kwargs` unconditionally, so any user-supplied `--teacher_model_init_kwargs` was discarded before it reached the trainer. It now merges the override on top of the defaults, matching gold.py and both distillation scripts, which also keeps the documented escape hatch usable for deliberately quantizing the teacher.
…cher-quantization # Conflicts: # examples/scripts/distillation.py # examples/scripts/gkd.py
|
Refreshed this branch against
The bug is unchanged in the relocated GOLD example: line 80 builds one Two things a reviewer should look at rather than take on trust. In The branch is now 0 commits behind |
What this does
Closes #6720.
The distillation and GOLD entry points default the teacher's quantization to the student's, so
--load_in_4bit(or any otherModelConfigquantization flag) quantizes the teacher as well. This dropsquantization_configfrom the teacher's default init kwargs, leaving the teacher in full precision unless the user asks otherwise.The rationale is the one @cmpatino gave in #6642 (comment): the consensus in the literature is to avoid quantizing the teacher. The teacher defines the reference distribution the student is trained to match, so degrading it degrades the training signal itself, and since it receives no gradients the memory saving buys less than the same quantization does on the student.
Files, after the examples reorganization
This PR originally targeted
examples/scripts/distillation.py,examples/scripts/gkd.pyandexamples/scripts/gold.py. #6820 reorganized examples into per-example folders and #6765 moved the distillation entry point, so those paths no longer exist. The branch has been merged withmainand now targets the two surviving call sites:trl/scripts/distillation.pyexamples/gold_chatbot_arena/gold_chatbot_arena.pygkd.pyhas no surviving equivalent that loads a teacher locally, so nothing replaces that hunk.In
trl/scripts/distillation.pythe change also drops one sentence from an existing comment, which said the teacher carries quantization throughteacher_model_init_kwargs. That described the coupled default this PR removes, so it is no longer accurate.Why no new config field
teacher_model_init_kwargsalready exists on both configs and both entry points merge it over their defaults, so a per-model quantization choice was already expressible; only the default coupled the two. Users who do want a quantized teacher can pass:--teacher_model_init_kwargs '{"quantization_config": {"load_in_4bit": true}}'from_pretrainedacceptsUnion[QuantizationConfigMixin, Dict]forquantization_config(checked against transformers 5.11.0), andteacher_model_init_kwargsis listed in_VALID_DICT_FIELDSon bothDistillationConfigandGOLDConfig(trl/experimental/gold/gold_config.py:172), so the JSON string form parses on the command line.Verification
ruff checkandruff format --checkat the CI-pinned 0.13.3, and the pinned doc-builder at--max-len 119, all pass on both files. Both files parse, and no reference to the two deleted scripts remains on the branch.This is an examples and entry-point change with no test coverage of its own; the behavior it alters is which kwargs reach
from_pretrainedfor the teacher.Note
Medium Risk
Changes default model loading for distillation entrypoints: teachers use more VRAM than before when students are quantized, which may surprise users or cause OOM on tight GPUs.
Overview
Stops applying the student’s
quantization_configto the teacher intrl/scripts/distillation.pyandexamples/gold_chatbot_arena/gold_chatbot_arena.py. With--load_in_4bit(or otherModelConfigquantization flags), only the student stays quantized; the teacher loads in full precision unless overridden.Comments in both scripts explain that quantizing the teacher weakens the reference distribution for distillation/GOLD, and document opting in via
--teacher_model_init_kwargs '{"quantization_config": {...}}'. The distillation CLI comment about student quantization is trimmed now that the teacher no longer carries the shared config by default.Reviewed by Cursor Bugbot for commit 2a5ef8a. Bugbot is set up for automated code reviews on this repo. Configure here.