-
Notifications
You must be signed in to change notification settings - Fork 31.9k
TF - Fix interchangeable past/past_key_values and revert output variable name in GPT2 #16332
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
137a1d9
revert tf gpt2
gante a3fbcb0
remove unwanted change
gante d4c84e9
add test for unpack_inputs and fix test case
gante 203aa11
move import
gante 7538baa
re-revert gpt2
gante f894706
maybe like this?
gante f050d3e
add changes to vision encoder decoder
gante d746dc9
add more tests and fix another corner case
gante 1520ce1
simplify tests
gante 8e0b1ae
simplify change
gante c246b8d
revert use of set
gante File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -694,14 +694,17 @@ def prepare_inputs_for_generation( | |
| ): | ||
| decoder_inputs = self.decoder.prepare_inputs_for_generation(input_ids, past=past) | ||
| decoder_attention_mask = decoder_inputs["attention_mask"] if "attention_mask" in decoder_inputs else None | ||
| past_key_values = decoder_inputs.get("past_key_values") | ||
| if past_key_values is None: | ||
| past_key_values = decoder_inputs.get("past") # e.g. on TF GPT2 | ||
|
||
| input_dict = { | ||
| "input_ids": None, # needs to be passed to make Keras.layer.__call__ happy | ||
| "attention_mask": attention_mask, | ||
| "decoder_attention_mask": decoder_attention_mask, | ||
| "decoder_input_ids": decoder_inputs["input_ids"], | ||
| # TODO (joao): the `TFBaseModelOutput` wrapper should not be needed after the generate refactor is complete | ||
| "encoder_outputs": TFBaseModelOutput(last_hidden_state=encoder_outputs[0]), | ||
| "past_key_values": decoder_inputs["past_key_values"], | ||
| "past_key_values": past_key_values, | ||
| "use_cache": use_cache, | ||
| } | ||
| return input_dict | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -878,7 +878,7 @@ def prepare_inputs_for_generation(self, inputs, past=None, use_cache=None, use_x | |
| "input_ids": inputs, | ||
| "attention_mask": attention_mask, | ||
| "position_ids": position_ids, | ||
| "past_key_values": past, | ||
| "past": past, | ||
|
||
| "use_cache": use_cache, | ||
| } | ||
|
|
||
|
|
||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
This was the root cause for the problem in the decorator -- previously, this function was called inside
call, wherekwargscontained all keyword arguments (at the very least, with their default value).The decorator now calls this before
calland, because it does not have default values,kwargswas empty. This meant that thepast<>past_key_valuesmagic, needed for gpt2+encoder_decoder, was not happening when the decorator was applied on gpt2.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.
Makes sense!