Add optional norm for lm head vectors#808
Open
klei22 wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an optional normalization step for LM head vectors (applied to lm_head.weight before computing logits) to enable experimentation with logit-space stability and geometry, plus introduces a capped hypersphere normalization variant.
Changes:
- Add
CappedHyperSphereNormand register it in the normalization variant dictionary. - Introduce CLI/config plumbing for
norm_variant_lm_headand associated hypersphere-style parameters (norm_lm_head_*), and route LM-head logits through a helper that can normalize the head weight. - Add an exploration YAML to compare LM-head norm variants (none / hypersphere / RMS / capped hypersphere).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| variations/norm_variations.py | Adds CappedHyperSphereNorm and exposes it via norm_dictionary. |
| train_args.py | Adds CLI options for LM-head norm selection/params and includes the new norm variant in choices; also changes default --device. |
| model.py | Adds LM-head weight normalization path and uses it when computing logits. |
| gpt_conf.py | Extends GPTConfig with LM-head norm configuration fields. |
| explorations/default_inf_lm_head_norm_comparison.yaml | Provides an experiment matrix to compare LM-head norm variants under default_inf-like settings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if self.config.norm_variant_abs is not None: | ||
| self.transformer['post_abs_norm'] = self.build_norm_from_variant(config, "norm_variant_abs", "norm_abs") | ||
| if self.config.norm_variant_lm_head is not None: | ||
| self.transformer['lm_head_norm'] = self.build_norm_from_variant(config, "norm_variant_lm_head", "norm_lm_head") |
Comment on lines
+253
to
+254
| return self.transformer.lm_head_norm(lm_head_weight) | ||
|
|
|
|
||
| # System args | ||
| training_group.add_argument('--device', default='cuda', type=str) | ||
| training_group.add_argument('--device', default='cuda:0', type=str) |
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.
No description provided.