跳转到内容

下载与管理模型文件

先验证小型 Hugging Face 文件下载,再尝试大型模型。

  • 有效的 Standard、Pro 订阅,或符合条件的试用。
  • 能够连接本教程所用服务或下载资源的网络。
  • 若资源要求身份验证,需要 Hugging Face 账号和具有所需权限的 Token。

下载教程示例项目

Notebook → huggingface_hub
  1. import json
    try:
        from huggingface_hub import hf_hub_download
        path = hf_hub_download("google-bert/bert-base-uncased", "config.json",
                               token=True, force_download=True)
        with open(path) as config_file:
            config = json.load(config_file)
        print("Configuration downloaded:", config.get("model_type") == "bert")
    except Exception as error:
        status = getattr(getattr(error, "response", None), "status_code", None)
        print("Download error:", type(error).__name__, "HTTP:", status)
    
·
放大查看操作位置

Configuration downloaded: True 表示小型配置文件已下载且能正确解析,不代表模型推理或其他模型的访问权限已验证。

  • 新保存的 Token 或环境变量未生效时,重启内核。
  • 遇到 401/403 时,检查 Token 和资源的账号访问权限。
  • 下载成功但不能加载时,检查格式、所需依赖和可用内存。

联系支持