-
Notifications
You must be signed in to change notification settings - Fork 25.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[M2M100] fix positional embeddings #10590
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
34781ba
fix tests
patil-suraj b12c956
emb should be a parameter
patil-suraj 001400f
fix positional embeddings
patil-suraj 63358e7
fix make_weights
patil-suraj fe1d024
don't save pos embeds
patil-suraj b4ee406
add comment to describe the clamping
patil-suraj File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,13 +96,19 @@ def __init__( | |
|
||
def prepare_config_and_inputs(self): | ||
input_ids = ids_tensor([self.batch_size, self.seq_length], self.vocab_size) | ||
input_ids = ids_tensor([self.batch_size, self.seq_length], self.vocab_size).clamp( | ||
3, | ||
) | ||
input_ids[:, -1] = self.eos_token_id # Eos Token | ||
|
||
decoder_input_ids = ids_tensor([self.batch_size, self.seq_length], self.vocab_size) | ||
|
||
# we need to clamp the input ids here to avoid having pad token in between | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great! Thank for the very in-detail explanation! |
||
# this is because for M2M100 the position_ids are prepared such that | ||
# all pad tokens have pos id = 2 and rest are between 2..seq_length | ||
# and the seq_length here is seq_length - num_pad_tokens | ||
# but when using past, there is no way of knowing if the past input ids had | ||
# pad tokens in them, which results in incorrect seq_lenth and which in turn results in | ||
# position_ids being off by num_pad_tokens in past input | ||
input_ids = input_ids.clamp(self.pad_token_id + 1) | ||
decoder_input_ids = decoder_input_ids.clamp(self.pad_token_id + 1) | ||
|
||
config = M2M100Config( | ||
vocab_size=self.vocab_size, | ||
d_model=self.hidden_size, | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since
M2M100
uses sinusoidal positional embeddings, we don't need to save the pos embed weights.