Hugging Face HubにモデルをSSHでPushする手順メモ
以下の公式ドキュメントに詳しい手順が書かれていますが、自分用に簡潔にまとめたメモです。
1. 公開鍵の生成と登録
まずはHugging FaceにSSHで接続するための鍵を作成します。
$ cd ~/.ssh
$ ssh-keygen
Enter file in which to save the key (/Users/username/.ssh/id_rsa): id_hf_git
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
公開鍵が id_hf_git.pub に生成されます。以下のコマンドでクリップボードにコピーします。
$ pbcopy < id_hf_git.pub
次に、以下のリンクにアクセスして「Add SSH Key」から先ほどコピーした公開鍵を貼り付けます:
2. SSH Configの設定
SSH経由でHugging Faceに接続できるよう、~/.ssh/config を設定します。
$ vim ~/.ssh/config
以下の内容を追加:
Host hf.co
User <huggingface_username>
IdentityFile ~/.ssh/id_hf_git
IdentitiesOnly yes
AddKeysToAgent yes
3. レポジトリの作成とモデルのPush
レポジトリの作成
以下のリンクから新しいリポジトリを作成します:
モデルのPush手順
Hugging Faceのリポジトリには、デフォルトで main ブランチに .gitattributes が含まれているため、最初に fetch しておくとスムーズです。また、大きなファイルの管理のために git lfs を使用します。
$ cd <path to your model>
$ git init
$ git remote add origin git@hf.co:huggingface_username/repo_name
$ git fetch origin main
$ git checkout main
$ git lfs install
$ huggingface-cli lfs-enable-largefiles . #In case any file is bigger than 5GB
$ git add .
$ git commit -m "initial commit"
$ git push -u origin main