修改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")
相关推荐
GarryLau11 天前
huggingface/pytorch-image-models
pytorch·python·huggingface
阡之尘埃18 天前
本地部署DeepSeek-R1模型(新手保姆教程)
python·llm·huggingface·deepseek·deepseek-r1·lmstudio
chaplinthink20 天前
Huggingface使用
ai·大模型·transformer·huggingface
yuanlulu1 个月前
llamafactory使用8张昇腾910b算力卡lora微调训练qwen2-72b大模型
lora·llm·transformer·分布式训练·大语言模型·huggingface·多卡训练
阿正的梦工坊2 个月前
AMP 混合精度训练中的动态缩放机制: grad_scaler.py函数解析( torch._amp_update_scale_)
人工智能·pytorch·llm·huggingface
阿正的梦工坊2 个月前
Gemma2 2B 模型的model.safetensors.index.json文件解析
llm·huggingface
weixin_404551242 个月前
HUGGINGFACE NLP- MAIN NLP TASKS
人工智能·自然语言处理·nlp·huggingface·tasks
weixin_404551242 个月前
huggingface NLP-微调一个预训练模型
人工智能·自然语言处理·微调·nlp·huggingface·fine-train
HuggingFace3 个月前
人工评估 | 基础概念
huggingface·人工评估
Tonyfield3 个月前
Visual Code的Terminal (PowerShell)中下载huggingface模型
人工智能·深度学习·huggingface·modal·下载模型