1
0

Hugging Face からのモデルのダウンロード

Posted at

CP4D版watsonx.aiでは、バージョン4.8.4以降、「Bring Your Own Model」機能を使用すると、 watsonx.ai の推論機能で使用するためのカスタム・ファウンデーション・モデルをアップロードしてデプロイすることができます。

Hugging Face にあるモデルをアップロードしたい場合、インターネットに接続された環境では、Hugging Face からモデルを直接 git clone できますが、air-gap環境では、一旦インターネット接続環境でモデルをダウンロードしたうえで、それをair-gap環境に転送して使用する必要があります。このような場合に必要となるモデルのダウンロード手順の一例をご紹介します。

こちらのモデルをダウンロードする場合の例です。

image.png

検証環境

# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.9 (Ootpa)

前提要件のインストール

yum install python3.12

# python3.12 --version
Python 3.12.1
yum install python3.12-pip

# pip3.12 list
Package    Version
---------- -------
pip        23.2.1
setuptools 68.2.2

pipを使ったhuggingface_hubインストール

huggingface_hubのインストールは仮想環境で行うことが推奨されています。

## 仮想環境の作成
python3.12 -m venv .env

## 仮想環境の有効化
source .env/bin/activate

## huggingface_hubのインストール
pip install --upgrade huggingface_hub
pip3.12 install --upgrade huggingface_hub

## 確認例

(.env) # pip3.12 list
Package            Version
------------------ --------
certifi            2024.6.2
charset-normalizer 3.3.2
filelock           3.15.3
fsspec             2024.6.0
huggingface-hub    0.23.4
idna               3.7
packaging          24.1
pip                23.2.1
PyYAML             6.0.1
requests           2.32.3
setuptools         68.2.2
tqdm               4.66.4
typing_extensions  4.12.2
urllib3            2.2.2

リポジトリ全体のダウンロード

(.env) # vi download.py

from huggingface_hub import snapshot_download
snapshot_download(repo_id="cyberagent/open-calm-7b", revision="main")


(.env) # python ./download.py
Downloading: 100%|??????????????????????????????????????????????????????????????????????????????????????????| 1.48k/1.48k [00:00<00:00, 3.35MB/s]
Downloading: 100%|??????????????????????????????????????????????????????????????????????????????????????????| 3.59k/3.59k [00:00<00:00, 7.80MB/s]
Downloading: 100%|??????????????????????????????????????????????????????????????????????????????????????????????| 611/611 [00:00<00:00, 1.76MB/s]
Downloading: 100%|???????????????????????????????????????????????????????????????????????????????????????????????| 116/116 [00:00<00:00, 258kB/s]
Downloading: 100%|??????????????????????????????????????????????????????????????????????????????????????????| 9.93G/9.93G [02:15<00:00, 73.4MB/s]
Downloading: 100%|??????????????????????????????????????????????????????????????????????????????????????????| 3.95G/3.95G [00:53<00:00, 73.3MB/s]
Downloading: 100%|???????????????????????????????????????????????????????????????????????????????????????????| 42.0k/42.0k [00:00<00:00, 274kB/s]
Downloading: 100%|???????????????????????????????????????????????????????????????????????????????????????????????| 129/129 [00:00<00:00, 421kB/s]
Downloading: 100%|??????????????????????????????????????????????????????????????????????????????????????????| 3.23M/3.23M [00:00<00:00, 3.65MB/s]
Downloading: 100%|???????????????????????????????????????????????????????????????????????????????????????????????| 323/323 [00:00<00:00, 971kB/s]
(.env) #


これで、$HOME/.cache/huggingface/hub 下に cyberagent--open-alm-7b.main.276a5fb67510554e11ef191a2da44c919acccdf5 ディレクトリが作成されファイルがダウンロードされています。

# ls -l cyberagent--open-calm-7b.main.276a5fb67510554e11ef191a2da44c919acccdf5
合計 13556304
-rw-------. 1 root root       3586  6月 21 16:52 README.md
-rw-------. 1 root root        611  6月 21 16:52 config.json
-rw-------. 1 root root        116  6月 21 16:52 generation_config.json
-rw-------. 1 root root 9926368022  6月 21 16:55 pytorch_model-00001-of-00002.bin
-rw-------. 1 root root 3951988632  6月 21 16:56 pytorch_model-00002-of-00002.bin
-rw-------. 1 root root      42028  6月 21 16:56 pytorch_model.bin.index.json
-rw-------. 1 root root        129  6月 21 16:56 special_tokens_map.json
-rw-------. 1 root root    3231617  6月 21 16:56 tokenizer.json
-rw-------. 1 root root        323  6月 21 16:56 tokenizer_config.json

watsonx.aiにおいて、air-gap環境でBYOMをデプロイする場合は、これらファイルをair-gap環境に転送し、セットアップしたストレージ(PVC)にアップロードします。

参考

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