修改huggingface 的cache缓存路径

使用hugging face 来跑代码时,往往会把模型缓存到系统目录下,比如我的ubuntu系统就缓存到~.cache目录下。由于自己的home空间不足,先需要修改缓存的 .cache目录,修改方法如下:

找到自己安装的huggingface_hub下的constants.py 文件,比如我的文件位置在 lib/python3.10/site-packages/huggingface_hub 下。然后修改constants.py代码:

python 复制代码
# default cache
default_home = os.path.join(os.path.expanduser("~"), ".cache")
HF_HOME = os.path.expanduser(
    os.getenv(
        "HF_HOME",
        os.path.join(os.getenv("XDG_CACHE_HOME", default_home), "huggingface"),
    )
)
hf_cache_home = HF_HOME  # for backward compatibility. TODO: remove this in 1.0.0

把 default_home 修改为自己需要保存的文件路径即可。

我这里修改为:

python 复制代码
# default cache
default_home = os.path.join(os.path.expanduser("/root/autodl-tmp"), ".cache")
相关推荐
slacker-kian6 天前
HuggingFace API加载模型超时:用 ModelScopeAPI 替代
人工智能·python·transformer·huggingface·blip·modelscope·blipprocessor
uncle_ll1 个月前
深入探索 Hugging Face核心组件及实践
llm·nlp·bert·huggingface·hf-mirror·hf
All The Way North-2 个月前
【Transformers 实战——特征提取】从 Tokenizer 编码到 BERT 四类返回值详解与 NER 选型避坑
bert·huggingface·transformers·tokenizer·特征提取·pooler_output·last_hidden
chen_zn953 个月前
Hugging Face 无法访问的解决方案
huggingface
baidu_392113503 个月前
window如何利用hfd下载huggingface模型
huggingface
进击切图仔4 个月前
从零手写 RAG
python·huggingface·rag
itmrl4 个月前
DeepInfra 加入 HuggingFace 推理提供商:统一入口背后的基础设施逻辑
huggingface·开源模型·ai基础设施·推理服务·deepinfra
AI自动化工坊4 个月前
Hugging Face ml-intern技术深度解析:AI机器学习工程师的工程实践
人工智能·机器学习·huggingface·ml-intern·ai机器学习
冬瓜神君5 个月前
Token 预估这件小事:使用HuggingFace Tokenizers精准预估上下文Tokens
node.js·huggingface·tiktoken·tokens预估
阿钱真强道5 个月前
02 SDXL:环境安装、模型下载与图片生成实战 ARM + Ubuntu 24 + RTX 4090
aigc·huggingface·sdxl·stablediffusion·diffusers·rtx4090