Rocky Linux 9 AI 系列 012 — 安装大模型拉取工具 Git-LFS

Git LFS 简介

Git LFS(Large File Storage)是一种 Git 扩展,用于管理和存储大文件和二进制文件。它通过将大文件的实际内容存储在外部服务器上,并在 Git 仓库中保存指向这些文件的引用,从而优化了版本控制系统的性能。以下是 Git LFS 的一些关键特性和功能:

  1. 大文件管理 :Git LFS 通过对大文件进行专门管理,使得 Git 仓库更加轻量。大文件的实际内容存储在独立的存储服务器上,Git 仓库中只保存指向这些大文件的指针。
  2. 节省磁盘空间 :传统的 Git 没有对大文件进行专门优化,导致仓库的磁盘占用空间增大。Git LFS 则存储大文件的单一版本,只有指针文件被存储在 Git 仓库中,从而减少了磁盘使用。
  3. 加速克隆和拉取 :通过只下载需要的大文件,而不是整个历史仓库,Git LFS 可以显著加速仓库的克隆和拉取操作。
  4. 充分整合 Git :Git LFS 与标准的 Git 工作流程无缝整合,用户依然可以通过熟悉的 Git 命令进行操作。所有的大文件自动使用 LFS 仓库进行管理,对用户透明。

安装 Git-LFS

https://huggingface.co 克隆大模型仓库时,需要使用 git lfs 命令,直接使用 git 命令是无法拉取大模型文件的。

不同操作系统安装 git-lfs 的方法有所不同,建议参考:github/git-lfs – Installation · packagecloud。这是以 Rocky Linux 9 安装 git-lfs 为例,RPM 包链接:github/git-lfs – Results for el/9 in github/git-lfs,可以直接使用官方提供的 shell 脚本进行安装,木子这里采用手动安装。

# 配置安装源
[root@gpu-server-001 ~]# cat > /etc/yum.repos.d/github_git-lfs.repo << \EOF
[github_git-lfs]
name=github_git-lfs
baseurl=https://packagecloud.io/github/git-lfs/el/9/$basearch # 如果您使用的是 Rocky Linux 8,将这里的数字 9 改成 8
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/github/git-lfs/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

[github_git-lfs-source]
name=github_git-lfs-source
baseurl=https://packagecloud.io/github/git-lfs/el/9/SRPMS # 如果您使用的是 Rocky Linux 8,将这里的数字 9 改成 8
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/github/git-lfs/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
EOF

# 启用源,更新缓存
[root@gpu-server-001 ~]# yum -q makecache -y --disablerepo='*' --enablerepo='github_git-lfs'
Importing GPG key 0xDC282033:
 Userid     : "https://packagecloud.io/github/git-lfs (https://packagecloud.io/docs#gpg_signing) <[email protected]>"
 Fingerprint: 6D39 8DBD 30DD 7894 1E2C 4797 FE2A 5F8B DC28 2033
 From       : https://packagecloud.io/github/git-lfs/gpgkey

# 安装 git-lfs
[root@gpu-server-001 ~]# dnf install git-lfs
github_git-lfs-source                                                                                                                                    176  B/s | 833  B     00:04   
github_git-lfs-source                                                                                                                                    1.5 kB/s | 3.8 kB     00:02   
Importing GPG key 0xDC282033:
 Userid     : "https://packagecloud.io/github/git-lfs (https://packagecloud.io/docs#gpg_signing) <[email protected]>"
 Fingerprint: 6D39 8DBD 30DD 7894 1E2C 4797 FE2A 5F8B DC28 2033
 From       : https://packagecloud.io/github/git-lfs/gpgkey
Is this ok [y/N]: y
github_git-lfs-source                                                                                                                                    153  B/s | 1.5 kB     00:09   
Dependencies resolved.
=========================================================================================================================================================================================
 Package                                   Architecture                             Version                                       Repository                                        Size
=========================================================================================================================================================================================
Installing:
 git-lfs                                   x86_64                                   3.5.1-1.el9                                   github_git-lfs                                   3.7 M

Transaction Summary
=========================================================================================================================================================================================
Install  1 Package

Total download size: 3.7 M
Installed size: 11 M
Is this ok [y/N]: y
Downloading Packages:
git-lfs-3.5.1-1.el9.x86_64.rpm                                                                                                                           2.0 MB/s | 3.7 MB     00:01    
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                    1.9 MB/s | 3.7 MB     00:01     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                 1/1 
  Installing       : git-lfs-3.5.1-1.el9.x86_64                                                                                                                                      1/1 
  Running scriptlet: git-lfs-3.5.1-1.el9.x86_64                                                                                                                                      1/1 
Git LFS initialized.

  Verifying        : git-lfs-3.5.1-1.el9.x86_64                                                                                                                                      1/1 

Installed:
  git-lfs-3.5.1-1.el9.x86_64                                                                                                                                                             

Complete!

# 初始化 Git LFS
[root@gpu-server-001 ~]# git lfs install
Git LFS initialized.

# 验证是否安装成功
[root@gpu-server-001 ~]# git lfs --version
git-lfs/3.5.1 (GitHub; linux amd64; go 1.21.8; git e237bb3a)

除了可以使用 git lfs 命令外,还可以使用 HuggingFace 官方提供的 huggingface-cli 命令行工具。

大模型拉取

# 复制上图中对应链接,直接克隆,这时候会发现报错 OpenSSL,这是因为国内无法直接访问 huggingface.co 大模型网站
[root@gpu-server-001 ~]# git clone https://huggingface.co/openai/whisper-large-v3-turbo
Cloning into 'whisper-large-v3-turbo'...
fatal: unable to access 'https://huggingface.co/openai/whisper-large-v3-turbo/': OpenSSL SSL_connect: Connection reset by peer in connection to huggingface.co:443 

# 通过国内镜像站克隆
[root@gpu-server-001 ~]# git clone  https://hf-mirror.com/openai/whisper-large-v3-turbo
Cloning into 'whisper-large-v3-turbo'...
remote: Enumerating objects: 53, done.
remote: Total 53 (delta 0), reused 0 (delta 0), pack-reused 53 (from 1)
Unpacking objects: 100% (53/53), 1.20 MiB | 1.87 MiB/s, done.

# 拉取更新
[root@gpu-server-001 ~]# cd whisper-large-v3-turbo
[root@gpu-server-001 whisper-large-v3-turbo]# git lfs pull
Downloading LFS objects:   0% (0/1), 97 MB | 1.7 MB/s  

目前比较常用的大模型下载站有两个,国内构建的 ModelScope 魔搭社区,以及国外的 HuggingFace(简称:笑脸),而 HF-MirrorHuggingFace 国内镜像站。
ModelScope 魔搭社区:首页 · 魔搭社区
HuggingFace:HuggingFace,国内镜像站:HF-Mirror

参考文献

[1] github/git-lfs – Packages · packagecloud
[2] github/git-lfs – Installation · packagecloud

Avatar photo

关于 木子

Founder of the Rocky Linux Chinese community, MVP、VMware vExpert、TVP, advocate for cloud native technologies, with over ten years of experience in site reliability engineering (SRE) and the DevOps field. Passionate about Cloud Computing、Microservices、CI&CD、DevOps、Kubernetes, currently dedicated to promoting and implementing Rocky Linux in Chinese-speaking regions.
用一杯咖啡支持我们,我们的每一篇[文档]都经过实际操作和精心打磨,而不是简单地从网上复制粘贴。期间投入了大量心血,只为能够真正帮助到您。
暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇