Using Token to Access Llama2
I have been granted access to the Llama 70b model (it says that when I go to that page).  I have a token.  I tried this code (but I replaced “my token” with the actual token in quotes.  However, I get this error:  “OSError: You are trying to access a gated repo.Make sure to request access atmeta-llama/Llama-2-70b-chat-hf · Hugging Faceand pass a token having permission to this repo either by logging in withhuggingface-cli loginor by passingtoken=<your_token>.”MY CODE:from transformers import AutoModelForCausalLM, AutoTokenizerimport osREDACTED_TOKEN_token = “my token”os.environ[“HF_ACCESS_TOKEN”] = REDACTED_TOKEN_tokentokenizer = AutoTokenizer.from_pretrained(“meta-llama/Llama-2-70b-chat-hf”)model = AutoModelForCausalLM.from_pretrained(“meta-llama/Llama-2-70b-chat-hf”)I also tried this code with my actual token instead of your_token_herefrom transformers import LlamaForCausalLM, LlamaTokenizerimport sentencepiecetoken = “<your_token_here>”  # Replace <your_token_here> with the token you obtainedtokenizer = LlamaTokenizer.from_pretrained(“meta-llama/Llama-2-70b-chat-hf”, use_auth_token=token)model = LlamaForCausalLM.from_pretrained(“meta-llama/Llama-2-70b-chat-hf”, use_auth_token=token)Again, I got a message about it being a gated model.  Can anyone tell me what I am doing wrong?  Thank you .
2024-02-13T21:50:39Z
I’ve been having the same silly problem. Try changing the parameter name fromuse_auth_tokento simplytoken(ignoring the HF documentation:token = “<your_token_here>” # Replace <your_token_here> with the token you obtained

tokenizer = LlamaTokenizer.from_pretrained(“meta-llama/Llama-2-70b-chat-hf”, token=token)
model = LlamaForCausalLM.from_pretrained(“meta-llama/Llama-2-70b-chat-hf”, token=token)
2024-02-21T16:41:17Z
huggingface_hub import notebook_loginrun this and thennotebook_login()paste your token
2024-02-21T17:01:35Z
In my case (and I suspect many others), this will not work. I wasn’t able to interact with the script as this command requires. For context, I send a request to a remote machine which executes the script to download a HF model specified by the user, then run inference and send back the response. In situations where the script is noninteractive, use the DrewG’s solution above. In interactive sessions, El-chapoo’s should work well.