llm auth_error ai_generated true

OSError: 无法加载模型'meta-llama/Llama-2-7b-chat-hf'。如果您正尝试从'https://huggingface.co/models'加载它,请确保您有访问该模型的权限并已登录。

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

其他格式: JSON · Markdown 中文 · English
85%修复率
90%置信度
1证据数
2023-07-18首次发现

版本兼容性

版本状态引入弃用备注
transformers>=4.30.0 active
huggingface-hub>=0.16.0 active

根因分析

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

English

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

官方文档

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

解决方案

  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'))

无效尝试

常见但无效的做法:

  1. 60% 失败

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

  2. 50% 失败

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