llm auth_error ai_generated true

OSError: Can't load the model 'meta-llama/Llama-2-7b-chat-hf'. If you were trying to load it from 'https://huggingface.co/models', make sure you have access to the model and are logged in.

ID: llm/huggingface-model-not-found

Also available as: JSON · Markdown · 中文
85%Fix Rate
90%Confidence
1Evidence
2023-07-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
transformers>=4.30.0 active
huggingface-hub>=0.16.0 active

Root Cause

The model is gated or requires authentication, and the user is not logged in to Hugging Face Hub, or the access token is missing or invalid.

generic

中文

模型是受限的或需要认证,用户未登录Hugging Face Hub,或访问令牌缺失或无效。

Official Documentation

https://huggingface.co/docs/hub/en/security-gated-models

Workarounds

  1. 95% success Log in to Hugging Face Hub using a valid access token: from huggingface_hub import login login(token='hf_your_token_here') # Then load the model from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained('meta-llama/Llama-2-7b-chat-hf')
    Log in to Hugging Face Hub using a valid access token:
    from huggingface_hub import login
    login(token='hf_your_token_here')
    
    # Then load the model
    from transformers import AutoModelForCausalLM
    model = AutoModelForCausalLM.from_pretrained('meta-llama/Llama-2-7b-chat-hf')
  2. 90% success Set the token as an environment variable before running the script: export HUGGINGFACE_TOKEN='hf_your_token_here' # In Python import os from huggingface_hub import login login(token=os.getenv('HUGGINGFACE_TOKEN'))
    Set the token as an environment variable before running the script:
    export HUGGINGFACE_TOKEN='hf_your_token_here'
    # In Python
    import os
    from huggingface_hub import login
    login(token=os.getenv('HUGGINGFACE_TOKEN'))

中文步骤

  1. 使用有效的访问令牌登录Hugging Face Hub:
    from huggingface_hub import login
    login(token='hf_your_token_here')
    
    # 然后加载模型
    from transformers import AutoModelForCausalLM
    model = AutoModelForCausalLM.from_pretrained('meta-llama/Llama-2-7b-chat-hf')
  2. 在运行脚本前将令牌设置为环境变量:
    export HUGGINGFACE_TOKEN='hf_your_token_here'
    # 在Python中
    import os
    from huggingface_hub import login
    login(token=os.getenv('HUGGINGFACE_TOKEN'))

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Even local loading may require token verification for gated models; the license must be accepted first.

  2. 50% fail

    The token must have explicit permission for the model; a generic token without granted access fails.