修改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")
相关推荐
_Meilinger_12 天前
碎片笔记|PromptStealer复现要点(附Docker简单实用教程)
docker·huggingface·tmux·promptstealer·hf-mirror
Uncertainty!!2 个月前
在huggingface上制作小demo
开发语言·python·机器学习·huggingface
leo03082 个月前
修改HuggingFace模型默认缓存路径
人工智能·大模型·llm·huggingface
mask哥3 个月前
huggingface NLP主要知识点以及超级详解使用
pytorch·python·自然语言处理·大模型·huggingface
伪_装3 个月前
Linux服务器部署Deepseek、Dify、RAGflow实战教程
linux·服务器·docker·huggingface·dify·ollama·ragflow
熊文豪3 个月前
轻松微调大模型:利用 Colab 和 Unsloth 实现高效训练
lora·huggingface·ollama·unsloth·googlecolab·ai微调·医疗ai
GarryLau3 个月前
huggingface/pytorch-image-models
pytorch·python·huggingface
阡之尘埃4 个月前
本地部署DeepSeek-R1模型(新手保姆教程)
python·llm·huggingface·deepseek·deepseek-r1·lmstudio
chaplinthink4 个月前
Huggingface使用
ai·大模型·transformer·huggingface
yuanlulu4 个月前
llamafactory使用8张昇腾910b算力卡lora微调训练qwen2-72b大模型
lora·llm·transformer·分布式训练·大语言模型·huggingface·多卡训练