[Doctest] Add configuration_vision_text_dual_encoder.py
Author: SD-13
Pull request: yes

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes part of issue https://github.com/huggingface/transformers/issues/19487.


## Before submitting
- [X] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [X] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [X] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [X] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] 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.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- albert, bert, xlm: @LysandreJik
- blenderbot, bart, marian, pegasus, encoderdecoder,  t5: @patrickvonplaten, @patil-suraj
- longformer, reformer, transfoxl, xlnet: @patrickvonplaten
- fsmt: @stas00
- funnel: @sgugger
- gpt2: @patrickvonplaten, @LysandreJik
- rag: @patrickvonplaten, @lhoestq
- tensorflow: @LysandreJik

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @n1t0, @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->


Comments:
_The documentation is not available anymore as the PR was closed or merged._

Hey @ydshieh , Please take a pass. Thanks,

Hi @SD-13 I left a comment. Also, does the doctest pass now (as you asked a question in another thread)

The checks on this PR page doesn't run doctest. So it's important for the contributors to run it 🙏 please.

> Hi @SD-13 I left a comment. Also, does the doctest pass now (as you asked a question in another thread)
> 
> The checks on this PR page doesn't run doctest. So it's important for the contributors to run it pray please.

Hey @ydshieh, That totally makes sense. I am still getting the error and I am giving the whole error log here. please help me to debug this. Thanks,


============================= test session starts ==============================
platform linux -- Python 3.10.6, pytest-7.1.3, pluggy-1.0.0 -- /home/pirate/Downloads/huggingFace/transformers/transformers/bin/python
cachedir: .pytest_cache
rootdir: /home/pirate/Downloads/huggingFace/transformers, configfile: setup.cfg
collected 1 item                                                               

src/transformers/models/vision_text_dual_encoder/configuration_vision_text_dual_encoder.py::transformers.models.vision_text_dual_encoder.configuration_vision_text_dual_encoder.VisionTextDualEncoderConfig FAILED

=================================== FAILURES ===================================
_ [doctest] transformers.models.vision_text_dual_encoder.configuration_vision_text_dual_encoder.VisionTextDualEncoderConfig _
062 
063     >>> # Accessing the model configuration
064     >>> config_vision = model.config.vision_config
065     >>> config_text = model.config.text_config
066 
067     >>> # Saving the model, including its configuration
068     >>> model.save_pretrained("my-model")
069 
070     >>> # loading model and config from pretrained folder
071     >>> vision_text_config = VisionTextDualEncoderConfig.from_pretrained("vit-bert")
UNEXPECTED EXCEPTION: OSError("vit-bert is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'\nIf this is a private repository, make sure to pass a token having permission to this repo with `use_auth_token` or log in with `huggingface-cli login` and pass `use_auth_token=True`.")
Traceback (most recent call last):
  File "/home/pirate/Downloads/huggingFace/transformers/transformers/lib/python3.10/site-packages/huggingface_hub/utils/_errors.py", line 213, in hf_raise_for_status
    response.raise_for_status()
  File "/home/pirate/Downloads/huggingFace/transformers/transformers/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/vit-bert/resolve/main/config.json
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/home/pirate/Downloads/huggingFace/transformers/src/transformers/utils/hub.py", line 409, in cached_file
    resolved_file = hf_hub_download(
  File "/home/pirate/Downloads/huggingFace/transformers/transformers/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1053, in hf_hub_download
    metadata = get_hf_file_metadata(
  File "/home/pirate/Downloads/huggingFace/transformers/transformers/lib/python3.10/site-packages/huggingface_hub/file_download.py", line 1359, in get_hf_file_metadata
    hf_raise_for_status(r)
  File "/home/pirate/Downloads/huggingFace/transformers/transformers/lib/python3.10/site-packages/huggingface_hub/utils/_errors.py", line 242, in hf_raise_for_status
    raise RepositoryNotFoundError(message, response) from e
huggingface_hub.utils._errors.RepositoryNotFoundError: 401 Client Error. (Request ID: WiAMp3MzQkYIQuEIq-5Wj)

Repository Not Found for url: https://huggingface.co/vit-bert/resolve/main/config.json.
Please make sure you specified the correct `repo_id` and `repo_type`.
If the repo is private, make sure you are authenticated.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.10/doctest.py", line 1350, in __run
    exec(compile(example.source, filename, "single",
  File "<doctest transformers.models.vision_text_dual_encoder.configuration_vision_text_dual_encoder.VisionTextDualEncoderConfig[8]>", line 1, in <module>
  File "/home/pirate/Downloads/huggingFace/transformers/src/transformers/configuration_utils.py", line 531, in from_pretrained
    config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/home/pirate/Downloads/huggingFace/transformers/src/transformers/configuration_utils.py", line 558, in get_config_dict
    config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/home/pirate/Downloads/huggingFace/transformers/src/transformers/configuration_utils.py", line 613, in _get_config_dict
    resolved_config_file = cached_file(
  File "/home/pirate/Downloads/huggingFace/transformers/src/transformers/utils/hub.py", line 424, in cached_file
    raise EnvironmentError(
OSError: vit-bert is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'
If this is a private repository, make sure to pass a token having permission to this repo with `use_auth_token` or log in with `huggingface-cli login` and pass `use_auth_token=True`.
/home/pirate/Downloads/huggingFace/transformers/src/transformers/models/vision_text_dual_encoder/configuration_vision_text_dual_encoder.py:71: UnexpectedException
063     >>> # Accessing the model configuration
064     >>> config_vision = model.config.vision_config
065     >>> config_text = model.config.text_config
066 
067     >>> # Saving the model, including its configuration
068     >>> model.save_pretrained("my-model")
069 
070     >>> # loading model and config from pretrained folder
071     >>> vision_text_config = VisionTextDualEncoderConfig.from_pretrained("vit-bert")
072     >>> model = VisionTextDualEncoderModel.from_pretrained("vit-bert", config=vision_text_config)
UNEXPECTED EXCEPTION: NameError("name 'vision_text_config' is not defined")
Traceback (most recent call last):
  File "/usr/lib/python3.10/doctest.py", line 1350, in __run
    exec(compile(example.source, filename, "single",
  File "<doctest transformers.models.vision_text_dual_encoder.configuration_vision_text_dual_encoder.VisionTextDualEncoderConfig[9]>", line 1, in <module>
NameError: name 'vision_text_config' is not defined
/home/pirate/Downloads/huggingFace/transformers/src/transformers/models/vision_text_dual_encoder/configuration_vision_text_dual_encoder.py:72: UnexpectedException
=========================== short test summary info ============================
FAILED src/transformers/models/vision_text_dual_encoder/configuration_vision_text_dual_encoder.py::transformers.models.vision_text_dual_encoder.configuration_vision_text_dual_encoder.VisionTextDualEncoderConfig
============================== 1 failed in 5.48s ===============================


Hi! From the error message
```
071 >>> vision_text_config = VisionTextDualEncoderConfig.from_pretrained("vit-bert")
UNEXPECTED EXCEPTION: OSError("vit-bert is not a local folder and is not a valid model identifier listed on '[https://huggingface.co/models'\nIf](https://huggingface.co/models'%5CnIf) this is a private repository, make sure to pass a token having permission to this repo with use_auth_token or log in with huggingface-cli login and pass use_auth_token=True.")
```
It tells that "vit-bert" doesn't exist. And if you read the code a few lines above this line, you see
```
model.save_pretrained("my-model")
```
So the code save model in some name but try to load it with another name. Change it to
```
model.save_pretrained("vit-bert")
```
will work :-)

Yep it worked!!


=========================================================== test session starts ============================================================
platform linux -- Python 3.10.6, pytest-7.1.3, pluggy-1.0.0 -- /home/pirate/Downloads/huggingFace/transformers/transformers/bin/python
cachedir: .pytest_cache
rootdir: /home/pirate/Downloads/huggingFace/transformers, configfile: setup.cfg
collected 1 item                                                                                                                           

src/transformers/models/vision_text_dual_encoder/configuration_vision_text_dual_encoder.py::transformers.models.vision_text_dual_encoder.configuration_vision_text_dual_encoder.VisionTextDualEncoderConfig PASSED

============================================================ 1 passed in 10.89s ============================================================


Thanks for the explanation, I got your point.


Well, I need you push the necessary change in order to merge :-)