Add dynamic loss balancing for distillation feature and logit losses#4220
Open
ajkv-google wants to merge 1 commit into
Open
Add dynamic loss balancing for distillation feature and logit losses#4220ajkv-google wants to merge 1 commit into
ajkv-google wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Description
Description
This PR updates the distillation loss computation in MaxText by introducing dynamic weighting for the feature loss and knowledge distillation terms.
In
src/maxtext/trainers/post_train/distillation/distillation_utils.py, we implemented a dynamic scale to match the raw feature loss magnitude to the softened logit loss (soft_loss_mean), and then scale the combinedkd_lossto match the target task loss (hard_loss_mean).This dynamic loss balancing strategy is the approach used by the PIE team, and it helps stabilize multi-task objectives by making sure that different loss components maintain proportional gradient updates throughout training.
Specific Implementation Details:
feature_mag_scale, which is computed as the ratio ofsoft_loss_meantoraw_feature_loss(both with stop-gradients applied to matchdetach()).kd_lossis scaled usingkd_mag_scale, computed as the ratio ofhard_loss_meantokd_loss.total_loss = hard_loss_mean + (alpha * balanced_kd_loss).Tests
Ran training job with this new dynamic loss weighting strategy.
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.