-
Notifications
You must be signed in to change notification settings - Fork 31.6k
TF: Finalize unpack_inputs-related changes
#16499
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 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
558ee00
Add unpack_inputs to remaining models
gante 01c4539
tmp commit
gante 801fd1d
remove breakpoint
gante 821baa7
add unpack_inputs
gante 3e912f7
removed kwargs up to clip
gante a68901b
removed kwags up to longformer
gante 9bc6e76
remove unused kwargs in remaining models; inputs_processing is now pr…
gante 87b7ab5
forgot to pop empty kwargs
gante ac1f936
handle models without attention
gante 93c2a65
derp
gante df4da79
fix t5 tests
gante 364284c
Fix equivalence tests
gante 11e8ca4
Merge branch 'main' into encoder_decoder_unpack_inputs
gante a8d859d
PR comments
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -312,9 +312,10 @@ def booleans_processing(config, **kwargs): | |
|
|
||
| if tf.executing_eagerly(): | ||
| # Pure conv models (such as ConvNext) do not have `output_attentions` | ||
| final_booleans["output_attentions"] = kwargs.get("output_attentions", None) | ||
| if final_booleans["output_attentions"] is None: | ||
| final_booleans["output_attentions"] = config.output_attentions | ||
| if "output_attentions" in kwargs: | ||
| final_booleans["output_attentions"] = ( | ||
| kwargs["output_attentions"] if kwargs["output_attentions"] is not None else config.output_attentions | ||
| ) | ||
| final_booleans["output_hidden_states"] = ( | ||
| kwargs["output_hidden_states"] | ||
| if kwargs["output_hidden_states"] is not None | ||
|
|
@@ -329,7 +330,9 @@ def booleans_processing(config, **kwargs): | |
| kwargs["use_cache"] if kwargs["use_cache"] is not None else getattr(config, "use_cache", None) | ||
| ) | ||
| else: | ||
| final_booleans["output_attentions"] = config.output_attentions | ||
| # Pure conv models (such as ConvNext) do not have `output_attentions` | ||
| if "output_attentions" in kwargs: | ||
| final_booleans["output_attentions"] = config.output_attentions | ||
| final_booleans["output_hidden_states"] = config.output_hidden_states | ||
|
|
||
| if kwargs.get("return_dict", None) not in (None, True): | ||
|
|
@@ -373,7 +376,7 @@ def run_call_with_unpacked_inputs(self, *args, **kwargs): | |
| # process the inputs and call the wrapped function | ||
| main_input_name = getattr(self, "main_input_name", func.__code__.co_varnames[1]) | ||
| main_input = fn_args_and_kwargs.pop(main_input_name, None) | ||
| unpacked_inputs = input_processing(func, self.config, main_input, **fn_args_and_kwargs) | ||
| unpacked_inputs = _input_processing(func, self.config, main_input, **fn_args_and_kwargs) | ||
| return func(self, **unpacked_inputs) | ||
|
|
||
| # Keras enforces the first layer argument to be passed, and checks it through `inspect.getfullargspec()`. This | ||
|
|
@@ -384,7 +387,7 @@ def run_call_with_unpacked_inputs(self, *args, **kwargs): | |
| return run_call_with_unpacked_inputs | ||
|
|
||
|
|
||
| def input_processing(func, config, input_ids, **kwargs): | ||
| def _input_processing(func, config, input_ids, **kwargs): | ||
gante marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| Process the input of each TensorFlow model including the booleans. In case of a list of symbolic inputs, each input | ||
| has to be named accordingly to the parameters name, i.e. `input_ids = tf.keras.Input(shape=(128,), dtype='int32', | ||
|
|
@@ -402,7 +405,7 @@ def input_processing(func, config, input_ids, **kwargs): | |
| Two lists, one for the missing layers, and another one for the unexpected layers. | ||
| """ | ||
| signature = dict(inspect.signature(func).parameters) | ||
| signature.pop("kwargs", None) | ||
| has_kwargs = bool(signature.pop("kwargs", None)) | ||
| signature.pop("self", None) | ||
| parameter_names = list(signature.keys()) | ||
| output = {} | ||
|
|
@@ -432,12 +435,14 @@ def input_processing(func, config, input_ids, **kwargs): | |
| elif "past_key_values" in kwargs["kwargs_call"] and "past" in parameter_names: | ||
| kwargs["past"] = kwargs["kwargs_call"].pop("past_key_values") | ||
|
|
||
| if len(kwargs["kwargs_call"]) > 0: | ||
| raise ValueError( | ||
| f"The following keyword arguments are not supported by this model: {list(kwargs['kwargs_call'].keys())}." | ||
| ) | ||
|
|
||
| kwargs.pop("kwargs_call") | ||
| if has_kwargs: | ||
| output["kwargs"] = kwargs.pop("kwargs_call", {}) | ||
| else: | ||
| if len(kwargs["kwargs_call"]) > 0: | ||
| raise ValueError( | ||
| f"The following keyword arguments are not supported by this model: {list(kwargs['kwargs_call'].keys())}." | ||
| ) | ||
| kwargs.pop("kwargs_call") | ||
|
Comment on lines
+440
to
+447
Contributor
Author
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.
|
||
|
|
||
| for k, v in kwargs.items(): | ||
| if isinstance(v, allowed_types) or v is None: | ||
|
|
||
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
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
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
Oops, something went wrong.
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.
The previous version was passing down
final_booleans["output_attentions"]=Falsein pure conv models, which would set theoutput_attentionsargument toFalse. The new version results in no argument, which is the desired behavior.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.
Can you add a comment that
"output_attentions"will be inkwargs, with a value ofNoneif unset? That change made me pause for a couple of minutes.