0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【手順メモ】Hugging FaceにSSHで接続してGitでモデルをPushする方法

Last updated at Posted at 2025-04-10

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?