feat: Add attention transfer and feature matching to DistillationTrainer #227
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.
Summary
Enhanced
DistillationTrainerwith advanced distillation strategies for more effective knowledge transfer from teacher to student models.New Features
1. Attention Transfer Distillation
2. Feature Matching Distillation
3. Automatic Dimension Matching
Files Changed
distillation_config.py_fn.pydistillation_trainer.pypooling.pyDISTILLATION_UPDATES.mdTotal: ~1,180 lines added
Technical Details
Masking Implementation
Both new loss functions properly handle variable-length sequences:
valid_tokens × num_headsvalid_tokens × hidden_dimfor parity with unmasked branchDesign Choices
output_hidden_states/output_attentionsUsage Example
Backward Compatibility
✅ Fully backward compatible
All new parameters default to
FalseorNone, so existing code continues to work without modification.Testing Recommendations
See
DISTILLATION_UPDATES.mdfor detailed testing procedures.References
Documentation
Full technical documentation available in
DISTILLATION_UPDATES.mdincluding: