Use CLIP model config to set some kwargs for components #16609
Merged
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.
What does this PR do?
In
CLIPModel
, setoutput_attentions
andoutput_hidden_states
usingCLIPModel.config
if these values are specified in the configuration + not specified in the arguments.(currently, these operations are done in its vision & text components separately, and cause a WIP CLIP PT/TF equivalence test failing - #16557)
Details
Currently,
CLIPModel
uses its 2 components' (vision_model
andtext_model
) configurations to perform things like(here self is
CLIPVisionTransformer
orCLIPTextTransformer
)If
output_attentions
/output_hidden_states
are not passed toCLIPModel.forward
at this linetransformers/src/transformers/models/clip/modeling_clip.py
Lines 966 to 967 in 9fd5e6b
but
CLIPModel.config
has these values set,CLIPModel.config.output_attentions
andCLIPModel.config.output_hidden_states
won't have any effect. This case happens heretransformers/tests/test_modeling_tf_common.py
Lines 544 to 547 in 9fd5e6b
Therefore, CLIP PT/TF equivalence test won't returns hidden_states/attentions for the PT model.
In TF,
transformers/src/transformers/modeling_tf_utils.py
Line 393 in b33ab4e
will use
config
to set the kwargs at theCLIPModel
level. These kwargs are passed to the 2 components, and CLIP PT/TF equivalence test returns hidden_states/attentions for the TF model.