本地使用huggingface的diffuser包,来读取vae模型,读取时间过长

部署运行你感兴趣的模型镜像
from diffusers import AutoencoderKL
vae = AutoencoderKL.from_pretrained(
        "your local model cache",
        torch_dtype=torch.float16,
        local_files_only=True # 使用这个来强制读取本地模型
    )

使用上述代码读取模型后,模型加载时间异常,使用ctrl+c中断后,发现终止在socket连接处。由于中国ip访问huggingface有问题,想试下能不能使用镜像网站。

将下述代码添加后仍然无效,逐行分析代码寻找原因:

import os
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'

发现问题出在读取模型时,在diffuser包中的model_utils.py中使用了send_telemetry函数来验证模型结构,对huggingface发送了请求。具体调用如下:

send_telemetry(
                {"model_class": cls.__name__, "model_path": "local", "framework": "pytorch"},
                name="diffusers_from_pretrained",
            )

send_telemetry的具体实现在hub_utils.py中,具体如下:

def send_telemetry(data: Dict, name: str):
    """
    Sends logs to the Hub telemetry endpoint.

    Args:
        data: the fields to track, e.g. {"example_name": "dreambooth"}
        name: a unique name to differentiate the telemetry logs, e.g. "diffusers_examples" or "diffusers_notebooks"
    """
    if DISABLE_TELEMETRY or HF_HUB_OFFLINE:
        pass

    headers = {"user-agent": http_user_agent(data)}
    endpoint = HUGGINGFACE_CO_TELEMETRY + name
    try:
        r = requests.head(endpoint, headers=headers)
        r.raise_for_status()
    except Exception:
        # We don't want to error in case of connection errors of any kind.
        pass

可以发现放松请求的地址来自于endpoint这个变量,点击HUGGINGFACE_CO_TELEMETRY溯源,发现最终来自diffuser包中的utils中的__init__.py中的HUGGINGFACE_CO_RESOLVE_ENDPOINT

将其修改为

# HUGGINGFACE_CO_RESOLVE_ENDPOINT = "https://huggingface.co"
HUGGINGFACE_CO_RESOLVE_ENDPOINT="https://hf-mirror.com"

即可直接访问国内的镜像网站,问题解决。

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值