Do not quantize the teacher by default in the distillation scripts - #6769
Open
behroozazarkhalili wants to merge 1 commit into
Open
Do not quantize the teacher by default in the distillation scripts#6769behroozazarkhalili wants to merge 1 commit into
behroozazarkhalili wants to merge 1 commit 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Closes #6720.
Both distillation scripts default the teacher's quantization config 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 in both scripts, 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.
Why no new config field
DistillationConfig.teacher_model_init_kwargsalready exists, and both scripts merge it over their defaults. A per-model quantization choice was therefore 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_FIELDS, so the JSON string form parses on the command line.Scope note
Both copies carried the same default, so both are updated to keep them consistent:
trl/scripts/distillation.pyis unreleased (added in aacb260, not contained in v1.9.0), so this is not a behavior change for any released version.examples/scripts/distillation.pyhas carried the coupling since c475b97 and has shipped in v1.1.0 through v1.9.2. Changing it here is a real default change for users of that script. Happy to drop that hunk and land only the CLI half if you would rather keep the released example as is.No test covers the scripts' quantization wiring and the docs do not mention it, so nothing else needed updating.
Checks
ruff checkandruff format --checkon both files, using the pinned v0.13.3: clean.doc-builder style --max_len 119on both files: no changes needed, verified against a deliberately over-long fixture that the same invocation rejects.Note
Low Risk
Script-only default changes for model loading; student quantization behavior is unchanged and teachers can still be quantized explicitly.
Overview
Stops coupling teacher quantization to the student in
examples/scripts/distillation.pyandtrl/scripts/distillation.py. When users pass student quantization flags (e.g.--load_in_4bit), the teacher no longer inherits the samequantization_configand loads in full precision by default.Comments document that quantizing the teacher can weaken the reference distribution for distillation, and that quantization can still be applied via
--teacher_model_init_kwargs '{"quantization_config": {...}}'. The student path is unchanged (the example script still passesquantization_configintomodel_init_kwargs; the CLI script still passes it toDistillationTrainer).Reviewed by Cursor Bugbot for commit 7e4aee0. Bugbot is set up for automated code reviews on this repo. Configure here.