保存したいディレクトリでターミナルやPowerShellを開き、下の通りに入力すると現在のディレクトリに.ckptと.ptがすべて保存されます。
> pip install huggingface-hub
> python
>>> from huggingface_hub import snapshot_download
>>> snapshot_download(repo_id="ユーザー名/リポジトリ名", allow_patterns=["*.ckpt","*.pt"], repo_type="model", cache_dir="./")
> pip install huggingface-hub
はライブラリのインストールなので、初めに一回実行すればOKです。
保存先は「現在のディレクトリ/リポジトリ名/snapshots/最新のコミットのハッシュ値(32桁の英数字)/」です。
ログ
> python
Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from huggingface_hub import snapshot_download
>>> snapshot_download(repo_id="ユーザー名/リポジトリ名", allow_patterns=["*.ckpt","*.pt"], repo_type="model", cache_dir="./")
Downloading: 100%|████████████████████████████████████████████████████████████████| 3.85G/3.85G [02:12<00:00, 29.1MB/s]
C:\Users\UserName\AppData\Local\Programs\Python\Python310\lib\site-packages\huggingface_hub\file_download.py:123: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in D:UsersPath_to_Cache_Folder. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.
To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to see activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development
warnings.warn(message)
Downloading: 100%|█████████████████████████████████████████████████████████████████| x.0G/x.0G [xx:xx<00:00, 110MB/s]
Fetching 2 files: 100%|██████████████████████████████████████████████████████████████████| 3/3 [XX:XX<00:00, 73.04s/it]
'./(リポジトリ名)\\snapshots\\(32桁の英数字。コミットのハッシュ値のこと。)'
なにこれ?
Pythonの対話モード上でHuggingFaceのライブラリを使ってダウロードしてます。
一応オプションについて。設定すれば好きなファイルをダウンロードできます。

- 『repo_id』:リポジトリid
- 上の画像で「ユーザー名/ユーザー名」の部分
- modelに関してはURLの「https://huggingface.co/」以下の部分でもある
- 『allow_patterns』:ダウンロードするファイルを絞り込む。
- 『repo_type』:リポジトリの種類。
- URLが「https://huggingface.co/space/ユーザー名/リポジトリ名/」ならspace
- URLが「https://huggingface.co/ユーザー名/リポジトリ名」ならNoneかmodel
- 『cache_dir』:ダウンロード先のディレクトリ
- 「./」:「.」が一つ上のディレクトリなので「./」は現在のディレクトリを指す。
その他のオプションはここをお読みください。

Download files from the Hub
We’re on a journey to advance and democratize artificial intelligence through open source and open science.

Downloading files
We’re on a journey to advance and democratize artificial intelligence through open source and open science.
感想
ライブラリ作ってくれてありがとうございます…。リポジトリの保管とかweb上でのデモ実行とか、Hugging Face様々ですね…。
コメント