从Linux复制Hugging Face模型到Windows环境
Windows环境无法通过互联网直接下载Hugging Face的模型文件,通过Linux环境下载后需要复制到Windows环境,可按照如下步骤进行操作。
模型存储路径
Windows环境Hugging Face模型存储路径:
C:\Users\<Username>\.cache\huggingface\hub
Linux环境Hugging Face模型存储路径:
~/.cache/huggingface/hub
复制模型
首先在Linux环境下载好模型文件。
可通过huggingface-cli下载模型,会自动存储到~/.cache/huggingface/hub目录。
在~/.cache/huggingface/目录创建fix.py,内容为下方代码,并且手动执行。
import os
import shutil
source_base = "hub"
destination_base = "hub_new"
for root, dirs, files in os.walk(source_base):
    if "snapshots" in root:
        relative_path = os.path.relpath(root, source_base)
        destination_path = os.path.join(destination_base, relative_path)
        
        if not os.path.exists(destination_path):
            os.makedirs(destination_path)
        
        for file in files:
            source_file = os.path.join(root, file)
            destination_file = os.path.join(destination_path, file)
            shutil.copy2(source_file, destination_file)
python fix.py

                
            
        
浙公网安备 33010602011771号