fix: filter weight decay for LayerNorm, biases, and special tokens#66
Open
fix: filter weight decay for LayerNorm, biases, and special tokens#66
Conversation
Problem:
- Weight decay was applied to ALL parameters including:
- 1D parameters (LayerNorm/RMSNorm weights, biases)
- Special learned tokens (probe, pos_embed, cls_token)
- This is suboptimal as these parameters don't benefit from shrinkage
Solution:
- Add build_adamw_param_groups() function following MAE/DeiT/OpenCLIP patterns
- Exclude from weight decay:
- Parameters with ndim < 2 (catches all 1D params like norm weights, biases)
- Parameters ending in '.bias'
- Special tokens: probe, pos_embed, cls_token, mask_token, query_tokens, latents
- Apply per-group weight decay instead of global optimizer-level decay
References:
- MAE: facebookresearch/mae/util/lr_decay.py
- OpenCLIP: excludes 'p.ndim < 2' and 'bn/ln/bias' from decay
- DeiT: timm-style no_weight_decay() returning {pos_embed, cls_token}
3b0d868 to
f7e7781
Compare
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.
Summary
Problem
The current training applies
weight_decay=0.05to ALL parameters, including:This is suboptimal because:
probe(shape 1,1,C) shouldn't be shrunk toward zeroSolution
Add
build_adamw_param_groups()function that:param.ndim < 2(catches all 1D params).biassuffixprobe, pos_embed, cls_token, mask_token, query_tokens, latentsEvidence from Major Repos
p.ndim == 1+no_weight_decay_listno_weight_decay()p.ndim < 2kernel(weight matrices)Files Changed
training/train.py- Add helper function and modify optimizer setupEdge Cases Handled
probein pooling head: shape (1, 1, C) with ndim=3, explicitly excluded by namebias=False, no issue