Fixes issue #38709 for CLIP and XCLIP
What does this PR do?
Fixes #38709 (at least for CLIP and XCLIP for now and is fully backward compatible and existing functionality remains unaffected).
Previously, get_<>_features function in CLIP and XCLIP always return the pooled_output. Now, if output_hidden_states is set, the function returns a dict. It is set to None by default, so the existing behavior will be unaffected.
Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] Did you read the contributor guideline, Pull Request section?
- [x ] Was this discussed/approved via a Github issue or the forum? Please add a link to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the documentation guidelines, and here are tips on formatting docstrings.
- [ ] Did you write any new necessary tests?
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR.
Hmmn, I was thinking maybe returning a dict with hidden states and pooler output as separate keys. cc @zucchini-nlp, do you know what this method is for, and why it accepts output_hidden_states as an argument but basically ignores it?
Hmm, seems like the helper used by researchers to obtain pooled features for single modality, since the forward call expects both modalities to be present. We use the same helper in Vision LLMs to return image_features after encoding+projection, reasy to be merged with text embeddings
I think it is not necessary to return hidden states and attention for these helper functions. If users want to obtain hidden states, they can load and call only the text/vision model (e.g. ClipTextModel)