-
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
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
| if "output_attentions" in kwargs: | ||
| final_booleans["output_attentions"] = ( | ||
| kwargs["output_attentions"] if kwargs["output_attentions"] is not None else config.output_attentions | ||
| ) |
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"]=False in pure conv models, which would set the output_attentions argument to False. 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 in kwargs, with a value of None if unset? That change made me pause for a couple of minutes.
| 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") |
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.
encoder_decoder models want the kwargs, all other models will discard them (and throw an error if they are not empty)
| @property | ||
| def dummy_inputs(self): | ||
| return {"input_ids": tf.constant(DUMMY_INPUTS)} | ||
|
|
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 class, TFT5EncoderModel, was inheriting the dummy_inputs that are used in all other TF T5 classes. However, contrarily to these other classes, the call() here does not accept decoder_xxx arguments, which are in the other dummy_inputs. Naturally, with stricter checking, it caused tests to fail (better yet -- the model failed at load time)
The changes here correct this. The serving function also had to be overwritten, for the same reasons.
| # This test is run in `TFT5EncoderOnlyModelTest`, where the main layer has the same inputs as the model | ||
| @unittest.skip(reason="The inputs of the Main Layer are different.") | ||
| def test_keras_save_load(self): | ||
| pass |
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.
Related to the dummy_inputs comment above. This test uses the TFT5MainLayer class, which has the same inputs as TFT5EncoderModel. All classes in this Tester use the other input format.
This test still happens below, in the Tester for TFT5EncoderModel.
| # Not all models accept "labels" in the forward pass (yet :) ) | ||
| return_labels=True if "labels" in inspect.signature(model_class.call).parameters.keys() else False, |
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.
Some models, like TFElectraForPreTraining, do not have a label argument, unlike their PT counterparts. There are 5 instances like this, all XXXForPretraining (not to be confused with XXXPreTrainedModel, the base models to be inherited).
Without this correction, those models would fail due to the inexisting label argument.
|
|
||
| for model_class in self.all_model_classes: | ||
| inputs_dict["output_attentions"] = True | ||
| inputs_dict["use_cache"] = False |
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.
Not being used at all
| # Not all models accept "labels" in the forward pass (yet :) ) | ||
| if "labels" in inspect.signature(model.call).parameters.keys(): |
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.
Reordered the tests so as to place all label-dependent tests under this if. Essentially the same label issue as above.
Rocketknight1
left a comment
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 is great! I'm a big fan of pushing input_processing into a protected class, and the kwargs changes make it much clearer what's going on in all of our models. Along with the other unpack_inputs changes, this makes all of our individual model files a lot less confusing for newcomers to the library.
sgugger
left a comment
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.
Thanks for cleaning all those kwargs up!
| if "output_attentions" in kwargs: | ||
| final_booleans["output_attentions"] = ( | ||
| kwargs["output_attentions"] if kwargs["output_attentions"] is not None else config.output_attentions | ||
| ) |
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 in kwargs, with a value of None if unset? That change made me pause for a couple of minutes.
* Add unpack_inputs to remaining models * removed kwargs to `call()` in TF models * fix TF T5 tests
* 📝 add image/vision classification and asr * 🖍 minor formatting fixes * Fixed a typo in legacy seq2seq_trainer.py (#16531) * Add ONNX export for BeiT (#16498) * Add beit onnx conversion support * Updated docs * Added cross reference to ViT ONNX config * call on_train_end when trial is pruned (#16536) * Type hints added (#16529) * Fix Bart type hints (#16297) * Add type hints to PLBart PyTorch * Remove pending merge conflicts * Fix PLBart Type Hints * Add changes from review * Add VisualBert type hints (#16544) * Adding missing type hints for mBART model (PyTorch) (#16429) * added type hints for mbart tensorflow tf implementation * Adding missing type hints for mBART model Tensorflow Implementation model added with missing type hints * Missing Type hints - correction For TF model * Code fixup using make quality tests * Hint types - typo error * make fix-copies and make fixup * type hints * updated files * type hints update * making dependent modesls coherent Co-authored-by: matt <[email protected]> * Remove MBart subclass of XLMRoberta in tokenzier docs (#16546) * Remove MBart subclass of XLMRoberta in tokenzier * Fix style * Copy docs from MBart50 tokenizer * Use random_attention_mask for TF tests (#16517) * use random_attention_mask for TF tests * Fix for TFCLIP test (for now). Co-authored-by: ydshieh <[email protected]> * Improve code example (#16450) Co-authored-by: Niels Rogge <[email protected]> * Pin tokenizers version <0.13 (#16539) * Pin tokenizers version <0.13 * Style * Add code samples for TF speech models (#16494) Co-authored-by: ydshieh <[email protected]> * [FlaxSpeechEncoderDecoder] Fix dtype bug (#16581) * [FlaxSpeechEncoderDecoder] Fix dtype bug * more fixes * Making the impossible to connect error actually report the right URL. (#16446) * Fix flax import in __init__.py: modeling_xglm -> modeling_flax_xglm (#16556) * Add utility to find model labels (#16526) * Add utility to find model labels * Use it in the Trainer * Update src/transformers/utils/generic.py Co-authored-by: Matt <[email protected]> * Quality Co-authored-by: Matt <[email protected]> * Enable doc in Spanish (#16518) * Reorganize doc for multilingual support * Fix style * Style * Toc trees * Adapt templates * Add use_auth to load_datasets for private datasets to PT and TF examples (#16521) * fix formatting and remove use_auth * Add use_auth_token to Flax examples * add a test checking the format of `convert_tokens_to_string`'s output (#16540) * add new tests * add comment to overridden tests * TF: Finalize `unpack_inputs`-related changes (#16499) * Add unpack_inputs to remaining models * removed kwargs to `call()` in TF models * fix TF T5 tests * [SpeechEncoderDecoderModel] Correct Encoder Last Hidden State Output (#16586) * initialize the default rank set on TrainerState (#16530) * initialize the default rank set on TrainerState * fix style * Trigger doc build * Fix CI: test_inference_for_pretraining in ViTMAEModelTest (#16591) Co-authored-by: ydshieh <[email protected]> * add a template to add missing tokenization test (#16553) * add a template to add missing tokenization test * add cookiecutter setting * improve doc * Update templates/adding_a_missing_tokenization_test/README.md Co-authored-by: Sylvain Gugger <[email protected]> Co-authored-by: Sylvain Gugger <[email protected]> * made _load_pretrained_model_low_mem static + bug fix (#16548) * handle torch_dtype in low cpu mem usage (#16580) * [Doctests] Correct filenaming (#16599) * [Doctests] Correct filenaming * improve quicktour * make style * Adding new train_step logic to make things less confusing for users (#15994) * Adding new train_step logic to make things less confusing for users * DO NOT ASK WHY WE NEED THAT SUBCLASS * Metrics now working, at least for single-output models with type annotations! * Updates and TODOs for the new train_step * Make fixup * Temporary test workaround until T5 has types * Temporary test workaround until T5 has types * I think this actually works! Needs a lot of tests though * MAke style/quality * Revert changes to T5 tests * Deleting the aforementioned unmentionable subclass * Deleting the aforementioned unmentionable subclass * Adding a Keras API test * Style fixes * Removing unneeded TODO and comments * Update test_step too * Stop trying to compute metrics with the dummy_loss, patch up test * Make style * make fixup * Docstring cleanup * make fixup * make fixup * Stop expanding 1D input tensors when using dummy loss * Adjust T5 test given the new compile() * make fixup * Skipping test for convnext * Removing old T5-specific Keras test now that we have a common one * make fixup * make fixup * Only skip convnext test on CPU * Update src/transformers/modeling_tf_utils.py Co-authored-by: Sylvain Gugger <[email protected]> * Update src/transformers/modeling_tf_utils.py Co-authored-by: Sylvain Gugger <[email protected]> * Avoiding TF import issues * make fixup * Update compile() to support TF 2.3 * Skipping model.fit() on template classes for now * Skipping model.fit() on template class tests for now * Replace ad-hoc solution with find_labels * make fixup Co-authored-by: Sylvain Gugger <[email protected]> * Adding missing type hints for BigBird model (#16555) * added type hints for mbart tensorflow tf implementation * Adding missing type hints for mBART model Tensorflow Implementation model added with missing type hints * Missing Type hints - correction For TF model * Code fixup using make quality tests * Hint types - typo error * make fix-copies and make fixup * type hints * updated files * type hints update * making dependent modesls coherent * Type hints for BigBird * removing typos Co-authored-by: matt <[email protected]> * [deepspeed] fix typo, adjust config name (#16597) * 🖍 apply feedback Co-authored-by: Cathy <[email protected]> Co-authored-by: Jim Rohrer <[email protected]> Co-authored-by: Ferdinand Schlatt <[email protected]> Co-authored-by: Dahlbomii <[email protected]> Co-authored-by: Gunjan Chhablani <[email protected]> Co-authored-by: Rishav Chandra Varma <[email protected]> Co-authored-by: matt <[email protected]> Co-authored-by: Yih-Dar <[email protected]> Co-authored-by: ydshieh <[email protected]> Co-authored-by: NielsRogge <[email protected]> Co-authored-by: Niels Rogge <[email protected]> Co-authored-by: Lysandre Debut <[email protected]> Co-authored-by: Patrick von Platen <[email protected]> Co-authored-by: Nicolas Patry <[email protected]> Co-authored-by: Daniel Stancl <[email protected]> Co-authored-by: Sylvain Gugger <[email protected]> Co-authored-by: Matt <[email protected]> Co-authored-by: Karim Foda <[email protected]> Co-authored-by: SaulLu <[email protected]> Co-authored-by: Joao Gante <[email protected]> Co-authored-by: Sanchit Gandhi <[email protected]> Co-authored-by: Andres Codas <[email protected]> Co-authored-by: Sylvain Gugger <[email protected]> Co-authored-by: Francesco Saverio Zuppichini <[email protected]> Co-authored-by: Suraj Patil <[email protected]> Co-authored-by: Stas Bekman <[email protected]>
What does this PR do?
Closes #16051
Please read this before diving into the changes :) This PR finalizes the changes related to the
unpack_inputsand is slightly more complex than the other PRs.Changes:
**kwargsfrom mostcallmethods in our TF models:input_processing, to handle some special cases (which are now handled inside the decorator);encoder_decodermodels (see below);input_processingby the decorator in theencoder_decodermodels:input_processingwas being used before theencoderand thedecoderwere called, which was redundant (theencoder/decodernow have the decorator, which also calls the function);use_cache), which is equivalent to adding the decorator on theencoder_decodermodel;encoder_decodermodels must use kwags, as theencoder/decodermight have a myriad of arguments, the decorator was updated so as to allow random kwargs on models that expect them. This brings us back to 1. -- no other models have kwags now.input_processingis now only used in the decorator, so I made the function protected :) This means we can start modernizing it without the fear of it being used in other places.