解决huggingface下载仓库时有部分大文件不能下载的问题
1. 问题
我在使用一个脚本下载一个来自huggingface的代码库
"replica_cad_dataset": {"source": "https://huggingface.co/datasets/ai-habitat/ReplicaCAD_dataset.git","link": data_path + "replica_cad","version": "v1.6",
},
很奇怪,下载之后其中绝大部分的内容的都可以下载,但是仓库中.glb的对象都没能正常下载,git的下载的terminal也卡在了一个奇怪的地方,如下所示:
(habitat) ➜ habitat-sim git:(stable) ✗ proxychains python src_python/habitat_sim/utils/datasets_download.py --uids replica_cad_dataset --data-path /home/tipriest/dataset/replica_cad
ProxyChains-3.1 (http://proxychains.sf.net)
git clone --depth 1 --branch v1.6 https://huggingface.co/datasets/ai-habitat/ReplicaCAD_dataset.git /home/tipriest/dataset/replica_cad/versioned_data/replica_cad_dataset
Cloning into '/home/tipriest/dataset/replica_cad/versioned_data/replica_cad_dataset'...
|DNS-request| huggingface.co
|S-chain|-<>-127.0.0.1:7890-<><>-4.2.2.2:53-<><>-OK
|DNS-response| huggingface.co is 54.230.71.103
|S-chain|-<>-127.0.0.1:7890-<><>-54.230.71.103:443-<><>-OK
remote: Enumerating objects: 624, done.
remote: Counting objects: 100% (624/624), done.
remote: Compressing objects: 100% (427/427), done.
remote: Total 624 (delta 197), reused 621 (delta 197), pack-reused 0 (from 0)
Receiving objects: 100% (624/624), 785.07 KiB | 614.00 KiB/s, done.
Resolving deltas: 100% (197/197), done.
Note: switching to '6be07e532c83c5799a6e96152f926d07838c2084'.You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:git switch -c <new-branch-name>Or undo this operation with:git switch -Turn off this advice by setting config variable advice.detachedHead to false
我查看当前网速不像是在继续下载的样子,我应该怎么办呢
2. Answer useful for me
我明白你的问题了 —— 你的脚本用的是 Hugging Face 上的 ReplicaCAD_dataset 仓库,但你用 git clone --depth 1 拉下来后发现 .glb 文件没下来,而且下载过程卡住。
其实这是预期行为:
在 Hugging Face 上,很多大型数据集(尤其是包含 .glb、.mp4、.zip等大文件的仓库)并不是直接用 Git 存储文件的,而是通过 Git LFS(Large File Storage)来管理。
普通 git clone 只会下载文本文件和指针文件(Pointer files),真正的大文件需要通过 Git LFS 另外下载,如果你的网络不通畅,卡住的地方很可能就是在拉 LFS 文件时。
为什么 .glb 没下载?
因为 .glb 在仓库里是一个 Git LFS pointer file(几 KB 大小,指向真实大文件的存储位置),没有 Git LFS 客户端的话,git 只会取到这个指针文件,而不会下载真正的数据。
解决方法
-
安装 Git LFS
在终端执行:sudo apt update sudo apt install git-lfs # Ubuntu/Debian # 或 macOS: brew install git-lfs -
初始化 LFS
(只需执行一次)git lfs install -
重新下载仓库 + LFS 文件
如果你已经 clone 过,可以直接:cd /home/tipriest/dataset/replica_cad/versioned_data/replica_cad_dataset git lfs pull或重新克隆:
git clone https://huggingface.co/datasets/ai-habitat/ReplicaCAD_dataset.git cd ReplicaCAD_dataset git lfs pull -
注意网络
Hugging Face 的 LFS 文件走 HTTPS,速度可能受你代理影响。如果你用proxychains,确保代理能处理大文件下载,建议测试:proxychains curl -I https://huggingface.co/看能否正常响应。
如果 Hugging Face 无法直连(下载卡住)
你可以切换为 huggingface-cli 下载:
pip install huggingface_hub
huggingface-cli download ai-habitat/ReplicaCAD_dataset --repo-type dataset --revision v1.6
这样会直接用 API 下载文件,绕过 Git LFS 的一些网络问题,并可以断点续传。
✅ 结论
你需要安装并使用 Git LFS 来下载 .glb 文件,否则 git 永远不会拉取真正的大文件,你看到的只是一些小的指针文件。而卡住的情况大多是因为代理或网络导致 LFS 下载慢或中断。
使用git lfs后成功下载没有问题
