Authenticated but still unable to access model
I think I’m going insane.I have been trying to access theLlama-2-7b-chat modelwhich requires Meta to grant you a licence, and then HuggingFace to accept you using that licence. I defintiely have the licence from Meta, receiving two emails confirming it. Likewise, I have gotten permission from HuggingFace that I can access the model, as not only did I get an email, but on the link I can seeEverything is telling me, I can access this model. However, I get the error:Traceback (most recent call last):
  File "/home/archie/Project/39Env/39venv/lib/python3.9/site-packages/huggingface_hub/utils/_errors.py", line 286, in REDACTED_TOKEN_for_status
    response.raise_for_status()
  File "/home/archie/Project/39Env/39venv/lib/python3.9/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/meta-llama/Llama-2-7b-chat-hf/resolve/main/config.json

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/archie/Project/39Env/39venv/lib/python3.9/site-packages/transformers/utils/hub.py", line 430, in cached_file
    resolved_file = REDACTED_TOKEN_download(
  File "/home/archie/Project/39Env/39venv/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
  File "/home/archie/Project/39Env/39venv/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 1457, in REDACTED_TOKEN_download
    http_get(
  File "/home/archie/Project/39Env/39venv/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 451, in http_get
    r = _request_wrapper(
  File "/home/archie/Project/39Env/39venv/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 409, in _request_wrapper
    REDACTED_TOKEN_for_status(response)
  File "/home/archie/Project/39Env/39venv/lib/python3.9/site-packages/huggingface_hub/utils/_errors.py", line 302, in REDACTED_TOKEN_for_status
    raise GatedRepoError(message, response) from e
huggingface_hub.utils._errors.GatedRepoError: 401 Client Error. (Request ID: Root=1-65860f70-301020471abb8dd86535f434;30d52fbe-f7d1-4f11-be9f-bab338fdd795)

Cannot access gated repo for url https://huggingface.co/meta-llama/Llama-2-7b-chat-hf/resolve/main/config.json.
Repo model meta-llama/Llama-2-7b-chat-hf is gated. You must be authenticated to access it.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/archie/Project/39Env/Llama2Learn/llama/test1.py", line 8, in <module>
    model = LlamaForCausalLM.from_pretrained(model_dir, token="REDACTED_TOKEN")
  File "/home/archie/Project/39Env/39venv/lib/python3.9/site-packages/transformers/modeling_utils.py", line 2600, in from_pretrained
    resolved_config_file = cached_file(
  File "/home/archie/Project/39Env/39venv/lib/python3.9/site-packages/transformers/utils/hub.py", line 445, in cached_file
    raise EnvironmentError(
OSError: You are trying to access a gated repo.
Make sure to request access at https://huggingface.co/meta-llama/llama-2-7b-chat-hf and pass a token having permission to this repo either by logging in with `huggingface-cli login` or by passing `token=<your_token>`.The code I am trying to run is as follows:import torch
import transformers
from pathlib import Path

from transformers import LlamaForCausalLM, LlamaTokenizer

model_dir = "meta-llama/llama-2-7b-chat-hf"
model = LlamaForCausalLM.from_pretrained(model_dir)

tokenizer = LlamaTokenizer.from_pretrained(model_dir)I am running it on WSL Ubuntu, running the program in a python 3.9.18 virtual environment.Now before someone yells, Yes I do know that I need a user access code to login so that HuggingFace knows that I am actually me, and I have done that! I have tried doing it by callinghuggingface-cli loginin the cmd line and using my code. I have tried it by passing the token as a parameter in thefrom_pretrainedfunction. I have tried calling the login from within the code in case it wasn’t jelling. None of these options did anything different. I have refreshed the tokens, and my computer, and tried it over a couple days, and still nothing.I originally tried to get it to work by using the local file, which has been correctly downloaded to my computer, but that brought about other issues. Primarily it being unable to find config.json that it needed to find.I am desparate for any help here; like I am nearing my breaking point. Please, huggingface forum, you are my only hope.
2023-12-23T11:20:50Z
It looks like the environment variable with your token isn’t properly set/recognized.Could you try running !huggingface-cli whoami in the terminal?See this guide:Command Line Interface (CLI).
2024-04-21T08:30:17Z
I was facing the same issue but I solved it by explicitly logging into huggingface on notebook using huggingface token. Followed the following steps,from huggingface_hub import login
login(token = <huggingfaec-token>)

tokenizer = AutoTokenizer.from_pretrained(
    "meta-llama/Llama-2-7b-chat-hf",
    cache_dir="/kaggle/working/"
)

model = AutoModelForCausalLM.from_pretrained(
    "meta-llama/Llama-2-7b-chat-hf",
    cache_dir="/kaggle/working/",
    device_map="auto",
)
2024-04-30T19:40:44Z
This worked for me, TYSM
2024-07-24T15:45:34Z
You need to log in to your hugging face using the following in your command line:huggingface-cli loginThis will ask for your HF Token, and you’ll be good to go after that.Alternatively, as replied by@abdurrehman245login from within your python script as below:from huggingface_hub import login
login(token = <huggingfaec-token>)
2024-09-12T05:22:40Z
i am having the the same issue but it’s a ungated model , it’s sentence-transformers/all-MiniLM-L12-v2it’s still showing unauthorized and i am even logged in to my account via terminal
2024-12-29T12:41:23Z
You could also check whether you’ve added the HF token to an.envfile. That willoverridethe token you set viahuggingface-cli login.