feat: support frozen embeddings#2
Open
000alen wants to merge 5 commits into
Open
Conversation
…oading of pretrained embeddings in Trainer class. Enhance model initialization to support freezing embeddings and ensure dimensional consistency when loading embeddings.
…nedModel instead of AutoModel for improved compatibility with GPT-2 architecture. Ensure consistent handling of input embeddings during initialization.
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for loading and optionally freezing pretrained embeddings from Hugging Face models. The implementation allows models to initialize with pretrained embeddings (like GPT-2) and freeze them during training to preserve learned representations.
- Adds embedding configuration options to TrainingConfig (freeze_embeddings, load_pretrained_embeddings, pretrained_model_name)
- Implements pretrained embedding loading with dimensional consistency checks in the Trainer class
- Reorders initialization sequence to load data first, ensuring correct vocab_size before model creation
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| train_launcher.py | Maps new embedding configuration parameters from config dict to TrainingConfig |
| secure_transformer/train.py | Implements embedding loading/freezing logic and reorders initialization sequence |
| secure_transformer/config.py | Adds new embedding-related configuration fields with defaults |
| configs/gpt2_frozen_config.yaml | Provides example configuration for using frozen GPT-2 embeddings |
Comments suppressed due to low confidence (1)
secure_transformer/train.py:76
- [nitpick] The variable name 'trainable_params' could be more descriptive. Consider renaming to 'trainable_parameters' for consistency with the logging message that mentions 'trainable params'.
trainable_params = [p for p in self.model.parameters() if p.requires_grad]
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Add embedding configuration options to TrainingConfig and implement loading of pretrained embeddings in Trainer class. Enhance model initialization to support freezing embeddings and ensure dimensional consistency when loading embeddings.