Using `subfolder` with AutoTokenizer.from_pretrained doesn't work
Author: cakiki
Pull request: no

### System Info

- `transformers` version: 4.23.1
- Platform: Linux-5.4.0-131-generic-x86_64-with-glibc2.31
- Python version: 3.9.5
- Huggingface_hub version: 0.10.1
- PyTorch version (GPU?): 1.12.1+cu116 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: no
- Using distributed or parallel set-up in script?: no

### Who can help?

Not sure; tagging @lvwerra and @osanseviero 

### Information

- [ ] The official example scripts
- [x] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Using `subfolder` when loading a trained tokenizer seems to fail because it expects a `config.json` whereas saving a tokenizer results in a `tokenizer_config.json`.

`tok = AutoTokenizer.from_pretrained("cakiki/bytelevel-dropout-0.1-50K")` This loads **successfully**

but the following **fails** even though it's the same exact tokenizer files: `tok = AutoTokenizer.from_pretrained("bigcode/tokenizer", subfolder="bytelevel-dropout-0.1-50K")`

The latter results in the following trace:

```python
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
File /mnt/1da05489-3812-4f15-a6e5-c8d3c57df39e/env/lib/python3.9/site-packages/huggingface_hub/utils/_errors.py:213, in hf_raise_for_status(response, endpoint_name)
    212 try:
--> 213     response.raise_for_status()
    214 except HTTPError as e:

File /mnt/1da05489-3812-4f15-a6e5-c8d3c57df39e/env/lib/python3.9/site-packages/requests/models.py:1021, in Response.raise_for_status(self)
   1020 if http_error_msg:
-> 1021     raise HTTPError(http_error_msg, response=self)

HTTPError: 404 Client Error: Not Found for url: https://huggingface.co/bigcode/tokenizer/resolve/main/bytelevel-dropout-0.1-50K/config.json

The above exception was the direct cause of the following exception:

EntryNotFoundError                        Traceback (most recent call last)
File /mnt/1da05489-3812-4f15-a6e5-c8d3c57df39e/env/lib/python3.9/site-packages/transformers/utils/hub.py:409, in cached_file(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, use_auth_token, revision, local_files_only, subfolder, user_agent, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash)
    407 try:
    408     # Load from URL or cache if already cached
--> 409     resolved_file = hf_hub_download(
    410         path_or_repo_id,
    411         filename,
    412         subfolder=None if len(subfolder) == 0 else subfolder,
    413         revision=revision,
    414         cache_dir=cache_dir,
    415         user_agent=user_agent,
    416         force_download=force_download,
    417         proxies=proxies,
    418         resume_download=resume_download,
    419         use_auth_token=use_auth_token,
    420         local_files_only=local_files_only,
    421     )
    423 except RepositoryNotFoundError:

File /mnt/1da05489-3812-4f15-a6e5-c8d3c57df39e/env/lib/python3.9/site-packages/huggingface_hub/file_download.py:1053, in hf_hub_download(repo_id, filename, subfolder, repo_type, revision, library_name, library_version, cache_dir, user_agent, force_download, force_filename, proxies, etag_timeout, resume_download, use_auth_token, local_files_only, legacy_cache_layout)
   1052 try:
-> 1053     metadata = get_hf_file_metadata(
   1054         url=url,
   1055         use_auth_token=use_auth_token,
   1056         proxies=proxies,
   1057         timeout=etag_timeout,
   1058     )
   1059 except EntryNotFoundError as http_error:
   1060     # Cache the non-existence of the file and raise

File /mnt/1da05489-3812-4f15-a6e5-c8d3c57df39e/env/lib/python3.9/site-packages/huggingface_hub/file_download.py:1359, in get_hf_file_metadata(url, use_auth_token, proxies, timeout)
   1350 r = _request_wrapper(
   1351     method="HEAD",
   1352     url=url,
   (...)
   1357     timeout=timeout,
   1358 )
-> 1359 hf_raise_for_status(r)
   1361 # Return

File /mnt/1da05489-3812-4f15-a6e5-c8d3c57df39e/env/lib/python3.9/site-packages/huggingface_hub/utils/_errors.py:231, in hf_raise_for_status(response, endpoint_name)
    226     message = (
    227         f"{response.status_code} Client Error."
    228         + "\n\n"
    229         + f"Entry Not Found for url: {response.url}."
    230     )
--> 231     raise EntryNotFoundError(message, response) from e
    233 elif error_code == "RepoNotFound" or response.status_code == 401:

EntryNotFoundError: 404 Client Error. (Request ID: vwMqo-SJymZZUmQ2bMoXA)

Entry Not Found for url: https://huggingface.co/bigcode/tokenizer/resolve/main/bytelevel-dropout-0.1-50K/config.json.

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
Cell In [18], line 1
----> 1 tok = AutoTokenizer.from_pretrained("bigcode/tokenizer", subfolder="bytelevel-dropout-0.1-50K")

File /mnt/1da05489-3812-4f15-a6e5-c8d3c57df39e/env/lib/python3.9/site-packages/transformers/models/auto/tokenization_auto.py:566, in AutoTokenizer.from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs)
    564 if config_tokenizer_class is None:
    565     if not isinstance(config, PretrainedConfig):
--> 566         config = AutoConfig.from_pretrained(
    567             pretrained_model_name_or_path, trust_remote_code=trust_remote_code, **kwargs
    568         )
    569     config_tokenizer_class = config.tokenizer_class
    570     if hasattr(config, "auto_map") and "AutoTokenizer" in config.auto_map:

File /mnt/1da05489-3812-4f15-a6e5-c8d3c57df39e/env/lib/python3.9/site-packages/transformers/models/auto/configuration_auto.py:770, in AutoConfig.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
    768 kwargs["name_or_path"] = pretrained_model_name_or_path
    769 trust_remote_code = kwargs.pop("trust_remote_code", False)
--> 770 config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
    771 if "auto_map" in config_dict and "AutoConfig" in config_dict["auto_map"]:
    772     if not trust_remote_code:

File /mnt/1da05489-3812-4f15-a6e5-c8d3c57df39e/env/lib/python3.9/site-packages/transformers/configuration_utils.py:558, in PretrainedConfig.get_config_dict(cls, pretrained_model_name_or_path, **kwargs)
    556 original_kwargs = copy.deepcopy(kwargs)
    557 # Get config dict associated with the base config file
--> 558 config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
    559 if "_commit_hash" in config_dict:
    560     original_kwargs["_commit_hash"] = config_dict["_commit_hash"]

File /mnt/1da05489-3812-4f15-a6e5-c8d3c57df39e/env/lib/python3.9/site-packages/transformers/configuration_utils.py:613, in PretrainedConfig._get_config_dict(cls, pretrained_model_name_or_path, **kwargs)
    609 configuration_file = kwargs.pop("_configuration_file", CONFIG_NAME)
    611 try:
    612     # Load from local folder or from cache or download from model Hub and cache
--> 613     resolved_config_file = cached_file(
    614         pretrained_model_name_or_path,
    615         configuration_file,
    616         cache_dir=cache_dir,
    617         force_download=force_download,
    618         proxies=proxies,
    619         resume_download=resume_download,
    620         local_files_only=local_files_only,
    621         use_auth_token=use_auth_token,
    622         user_agent=user_agent,
    623         revision=revision,
    624         subfolder=subfolder,
    625         _commit_hash=commit_hash,
    626     )
    627     commit_hash = extract_commit_hash(resolved_config_file, commit_hash)
    628 except EnvironmentError:
    629     # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted to
    630     # the original exception.

File /mnt/1da05489-3812-4f15-a6e5-c8d3c57df39e/env/lib/python3.9/site-packages/transformers/utils/hub.py:454, in cached_file(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, use_auth_token, revision, local_files_only, subfolder, user_agent, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash)
    452     if revision is None:
    453         revision = "main"
--> 454     raise EnvironmentError(
    455         f"{path_or_repo_id} does not appear to have a file named {full_filename}. Checkout "
    456         f"'[https://huggingface.co/{path_or_repo_id}/{](https://huggingface.co/%7Bpath_or_repo_id%7D/%7Brevision)[revision](https://huggingface.co/%7Bpath_or_repo_id%7D/%7Brevision)}' for available files."
    457     )
    458 except HTTPError as err:
    459     # First we try to see if we have a cached version (not up to date):
    460     resolved_file = try_to_load_from_cache(path_or_repo_id, full_filename, cache_dir=cache_dir, revision=revision)

OSError: bigcode/tokenizer does not appear to have a file named bytelevel-dropout-0.1-50K/config.json. Checkout 'https://huggingface.co/bigcode/tokenizer/main' for available files.
```



### Expected behavior

The tokenizer to load from the subfolder

Comments:
Indeed, thanks for the clear issue. The `subfolder` argument is not properly passed along in the utils that get the tokenizer config, and since that tokenizer config is then not found, `AutoTokenizer` then tries to find a config (which does not exist here).

Will send a fix shortly.