Problems with starting meta-llama/Llama-2-7b-hf model using transformers library. HFValidationError
Author: Karoljv
Pull request: no

### System Info

I am using:
Windows 11
Python 3.10.4
Torch 2.2.0
Transformers 4.37.2

### Who can help?

_No response_

### Information

- [x] The official example scripts
- [ ] 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

Hi I have problems with Llama-2-7B-hf model. I was granted access to this model.

I am facing issue while running this code:
model = "meta-llama/Llama-2-7b-hf"

model = AutoModelForCausalLM.from_pretrained(
    model,
    cache_dir = "./model/",
    device_map = "auto"
)

tokenizer = AutoTokenizer.from_pretrained(model, cache_dir = "./model/")


I am logged into hugging face hub by access token. I providing correct model id used in https://huggingface.co/meta-llama/Llama-2-7b-hf.



Here is the error:
Here is the error:

HFValidationError                         Traceback (most recent call last)
File [d:\Magister\llama_hugging_face\venv\lib\site-packages\transformers\utils\hub.py:385](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:385), in cached_file(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, repo_type, user_agent, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash, **deprecated_kwargs)
    [383](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:383) try:
    [384](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:384)     # Load from URL or cache if already cached
--> [385](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:385)     resolved_file = hf_hub_download(
    [386](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:386)         path_or_repo_id,
    [387](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:387)         filename,
    [388](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:388)         subfolder=None if len(subfolder) == 0 else subfolder,
    [389](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:389)         repo_type=repo_type,
    [390](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:390)         revision=revision,
    [391](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:391)         cache_dir=cache_dir,
    [392](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:392)         user_agent=user_agent,
    [393](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:393)         force_download=force_download,
    [394](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:394)         proxies=proxies,
    [395](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:395)         resume_download=resume_download,
    [396](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:396)         token=token,
    [397](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:397)         local_files_only=local_files_only,
    [398](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:398)     )
    [399](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:399) except GatedRepoError as e:

File [d:\Magister\llama_hugging_face\venv\lib\site-packages\huggingface_hub\utils\_validators.py:110](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/huggingface_hub/utils/_validators.py:110), in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    [109](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/huggingface_hub/utils/_validators.py:109) if arg_name in ["repo_id", "from_id", "to_id"]:
--> [110](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/huggingface_hub/utils/_validators.py:110)     validate_repo_id(arg_value)
    [112](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/huggingface_hub/utils/_validators.py:112) elif arg_name == "token" and arg_value is not None:

File [d:\Magister\llama_hugging_face\venv\lib\site-packages\huggingface_hub\utils\_validators.py:164](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/huggingface_hub/utils/_validators.py:164), in validate_repo_id(repo_id)
    [163](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/huggingface_hub/utils/_validators.py:163) if not REPO_ID_REGEX.match(repo_id):
--> [164](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/huggingface_hub/utils/_validators.py:164)     raise HFValidationError(
    [165](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/huggingface_hub/utils/_validators.py:165)         "Repo id must use alphanumeric chars or '-', '_', '.', '--' and '..' are"
    [166](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/huggingface_hub/utils/_validators.py:166)         " forbidden, '-' and '.' cannot start or end the name, max length is 96:"
    [167](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/huggingface_hub/utils/_validators.py:167)         f" '{repo_id}'."
    [168](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/huggingface_hub/utils/_validators.py:168)     )
    [170](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/huggingface_hub/utils/_validators.py:170) if "--" in repo_id or ".." in repo_id:

HFValidationError: Repo id must use alphanumeric chars or '-', '_', '.', '--' and '..' are forbidden, '-' and '.' cannot start or end the name, max length is 96: 'LlamaForCausalLM(
  (model): LlamaModel(
    (embed_tokens): Embedding(32000, 4096)
    (layers): ModuleList(
      (0-31): 32 x LlamaDecoderLayer(
        (self_attn): LlamaSdpaAttention(
          (q_proj): Linear(in_features=4096, out_features=4096, bias=False)
          (k_proj): Linear(in_features=4096, out_features=4096, bias=False)
          (v_proj): Linear(in_features=4096, out_features=4096, bias=False)
          (o_proj): Linear(in_features=4096, out_features=4096, bias=False)
          (rotary_emb): LlamaRotaryEmbedding()
        )
        (mlp): LlamaMLP(
          (gate_proj): Linear(in_features=4096, out_features=11008, bias=False)
          (up_proj): Linear(in_features=4096, out_features=11008, bias=False)
          (down_proj): Linear(in_features=11008, out_features=4096, bias=False)
          (act_fn): SiLU()
        )
        (input_layernorm): LlamaRMSNorm()
        (post_attention_layernorm): LlamaRMSNorm()
      )
    )
    (norm): LlamaRMSNorm()
  )
  (lm_head): Linear(in_features=4096, out_features=32000, bias=False)
)'.

The above exception was the direct cause of the following exception:

OSError                                   Traceback (most recent call last)
Cell In[12], [line 9](vscode-notebook-cell:?execution_count=12&line=9)
      [1](vscode-notebook-cell:?execution_count=12&line=1) model = "meta-llama/Llama-2-7b-hf"
      [3](vscode-notebook-cell:?execution_count=12&line=3) model = AutoModelForCausalLM.from_pretrained(
      [4](vscode-notebook-cell:?execution_count=12&line=4)     model,
      [5](vscode-notebook-cell:?execution_count=12&line=5)     cache_dir = "[./model/](https://file+.vscode-resource.vscode-cdn.net/d%3A/Magister/llama_hugging_face/model/)",
      [6](vscode-notebook-cell:?execution_count=12&line=6)     device_map = "auto"
      [7](vscode-notebook-cell:?execution_count=12&line=7) )
----> [9](vscode-notebook-cell:?execution_count=12&line=9) tokenizer = AutoTokenizer.from_pretrained(model, cache_dir = "[./model/](https://file+.vscode-resource.vscode-cdn.net/d%3A/Magister/llama_hugging_face/model/)")

File [d:\Magister\llama_hugging_face\venv\lib\site-packages\transformers\models\auto\tokenization_auto.py:758](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:758), in AutoTokenizer.from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs)
    [755](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:755)     return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
    [757](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:757) # Next, let's try to use the tokenizer_config file to get the tokenizer class.
--> [758](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:758) tokenizer_config = get_tokenizer_config(pretrained_model_name_or_path, **kwargs)
    [759](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:759) if "_commit_hash" in tokenizer_config:
    [760](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:760)     kwargs["_commit_hash"] = tokenizer_config["_commit_hash"]

File [d:\Magister\llama_hugging_face\venv\lib\site-packages\transformers\models\auto\tokenization_auto.py:590](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:590), in get_tokenizer_config(pretrained_model_name_or_path, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, **kwargs)
    [587](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:587)     token = use_auth_token
    [589](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:589) commit_hash = kwargs.get("_commit_hash", None)
--> [590](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:590) resolved_config_file = cached_file(
    [591](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:591)     pretrained_model_name_or_path,
    [592](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:592)     TOKENIZER_CONFIG_FILE,
    [593](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:593)     cache_dir=cache_dir,
    [594](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:594)     force_download=force_download,
    [595](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:595)     resume_download=resume_download,
    [596](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:596)     proxies=proxies,
    [597](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:597)     token=token,
    [598](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:598)     revision=revision,
    [599](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:599)     local_files_only=local_files_only,
    [600](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:600)     subfolder=subfolder,
    [601](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:601)     _raise_exceptions_for_missing_entries=False,
    [602](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:602)     _raise_exceptions_for_connection_errors=False,
    [603](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:603)     _commit_hash=commit_hash,
    [604](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:604) )
    [605](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:605) if resolved_config_file is None:
    [606](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/models/auto/tokenization_auto.py:606)     logger.info("Could not locate the tokenizer configuration file, will try to use the model config instead.")

File [d:\Magister\llama_hugging_face\venv\lib\site-packages\transformers\utils\hub.py:450](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:450), in cached_file(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, repo_type, user_agent, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash, **deprecated_kwargs)
    [448](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:448)     raise EnvironmentError(f"There was a specific connection error when trying to load {path_or_repo_id}:\n{err}")
    [449](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:449) except HFValidationError as e:
--> [450](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:450)     raise EnvironmentError(
    [451](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:451)         f"Incorrect path_or_model_id: '{path_or_repo_id}'. Please provide either the path to a local folder or the repo_id of a model on the Hub."
    [452](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:452)     ) from e
    [453](file:///D:/Magister/llama_hugging_face/venv/lib/site-packages/transformers/utils/hub.py:453) return resolved_file

OSError: Incorrect path_or_model_id: 'LlamaForCausalLM(
  (model): LlamaModel(
    (embed_tokens): Embedding(32000, 4096)
    (layers): ModuleList(
      (0-31): 32 x LlamaDecoderLayer(
        (self_attn): LlamaSdpaAttention(
          (q_proj): Linear(in_features=4096, out_features=4096, bias=False)
          (k_proj): Linear(in_features=4096, out_features=4096, bias=False)
          (v_proj): Linear(in_features=4096, out_features=4096, bias=False)
          (o_proj): Linear(in_features=4096, out_features=4096, bias=False)
          (rotary_emb): LlamaRotaryEmbedding()
        )
        (mlp): LlamaMLP(
          (gate_proj): Linear(in_features=4096, out_features=11008, bias=False)
          (up_proj): Linear(in_features=4096, out_features=11008, bias=False)
          (down_proj): Linear(in_features=11008, out_features=4096, bias=False)
          (act_fn): SiLU()
        )
        (input_layernorm): LlamaRMSNorm()
        (post_attention_layernorm): LlamaRMSNorm()
      )
    )
    (norm): LlamaRMSNorm()
  )
  (lm_head): Linear(in_features=4096, out_features=32000, bias=False)
)'. Please provide either the path to a local folder or the repo_id of a model on the Hub.


### Expected behavior

Correctly loaded model

Comments: