はじめに
InstructLabを使って、環境構築してみます。
InstructLabとは?
Red HatとIBMが共同で開発したオープンソースプロジェクトで、生成人工知能(生成AI)アプリケーションで使用される大規模言語モデル(LLM)を強化することを目的としています。このプロジェクトは、LLMのアライメント(モデルの出力を人間の意図や価値観に適合させること)を改善するための費用対効果の高いソリューションを提供し、機械学習の経験が少ない人でも貢献できる環境を提供しています。
(出典:日本IBM)
実際にInstructLabを使ってみよう
InstructLabは、IBM Researchの「Large-scale Alignment for chatBots(LAB)」という研究に基づいており、モデルの再トレーニングに通常必要とされる大量の人間生成データやコンピューティングリソースを大幅に削減し、LLMを強化することを目指しています。
オープンソースなので、実際に使ってみましょう。
環境構築
0. 事前確認
Python <3.12, >=3.10
のバージョンでないと動きません。
元々PCで利用していたPython v3.12.4は動きませんでした。
1. instructlabのインストール
公式ドキュメントに従って、実際に構築します。
https://github.com/instructlab/instructlab
pip install instructlab
パッケージのバージョンは下記を今回、使用します。
instructlab==0.23.1
下記コマンドが動けば正常にインストールできています。
$ ilab
"""
Usage: ilab [OPTIONS] COMMAND [ARGS]...
NOTE: ilab no longer supports Python 3.9 or Python 3.12 as of version 0.18.
If you are using either of these Python versions, there is no upgrade path
from ilab 0.17 to newer ilab versions. Please switch to Python 3.10 or 3.11
to use the latest ilab. ilab 0.17 will receive no bug fixes or additional
features. You can check which Python version you are using by running
python --version
CLI for interacting with InstructLab.
If this is your first time running ilab, it's best to start with ilab init
to create the environment.
Options:
--config PATH Path to a configuration file. [default: config.yaml]
--version Show the version and exit.
--help Show this message and exit.
Commands:
config Command Group for Interacting with the Config of InstructLab.
data Command Group for Interacting with the Data generated by...
model Command Group for Interacting with the Models in InstructLab.
sysinfo Print system information
taxonomy Command Group for Interacting with the Taxonomy of InstructLab.
Aliases:
chat: model chat
convert: model convert
diff: taxonomy diff
download: model download
generate: data generate
init: config init
serve: model serve
test: model test
train: model train
"""
2. instructlabの初期設定
$ ilab config init
Enterを押した後に、以下のメッセージが出力された際は、yを押します。
`taxonomy` seems to not exist or is empty. Should I clone https://github.com/instructlab/taxonomy.git for you? [y/N]:
すると現在のディレクトリにconfig.yamlが生成されます。
Generating `config.yaml` in the current directory...
3. モデルのダウンロード
デフォルトでは、instructlab/merlinite-7b-lab-GGUFモデルがダウンロードされるようです。
$ ilab model download
"""
Downloading model from instructlab/merlinite-7b-lab-GGUF@main to models...
Downloading 'merlinite-7b-lab-Q4_K_M.gguf' to 'models/.cache/huggingface/download/merlinite-7b-lab-Q4_K_M.gguf.9ca044d727db34750e1aeb04e3b18c3cf4a8c064a9ac96cf00448c506631d16c.incomplete'
INFO 2025-02-04 16:40:42,682 file_download.py:1536: _download_to_tmp_and_move Downloading 'merlinite-7b-lab-Q4_K_M.gguf' to 'models/.cache/huggingface/download/merlinite-7b-lab-Q4_K_M.gguf.9ca044d727db34750e1aeb04e3b18c3cf4a8c064a9ac96cf00448c506631d16c.incomplete'
merlinite-7b-lab-Q4_K_M.gguf: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4.37G/4.37G [07:24<00:00, 9.82MB/s]
Download complete. Moving file to models/merlinite-7b-lab-Q4_K_M.gguf
"""
ダウンロードした利用可能なモデルは下記で確認できます。
$ ilab model list
+----------------------------+---------------------+--------+
| Model Name | Last Modified | Size |
+----------------------------+---------------------+--------+
| granite-7b-lab-Q4_K_M.gguf | 2025-02-04 23:50:42 | 3.8 GB |
+----------------------------+---------------------+--------+
なお、下記のエラーに出会った際は、huggingfaceの権限エラーなので、環境変数$HF_TOKENを適用された環境で実行するか、--hf-tokenオプションでilab model download
が実行できます。
ilab model download --hf-token <your-huggingface-token>
Downloading model failed with the following Hugging Face Hub error: 401 Client Error. (Request ID: Root=1-67a1bfdf-3219b1de47773576545377cb;d57e18fa-e8b0-4216-a16e-272b5d539bbb)
Repository Not Found for url: https://huggingface.co/api/models/instructlab/merlinite-7b-lab-GGUF/tree/main?recursive=True&expand=False.
Please make sure you specified the correct `repo_id` and `repo_type`.
If you are trying to access a private or gated repo, make sure you are authenticated.
Invalid credentials in Authorization header
4. モデルのサービング
さぁ、お待ちかね、モデルに対して、推論を実行させてみます。まずは、モデルをサーブします。
$ ilab model serve
"""
INFO 2024-03-02 02:21:11,352 lab.py:201 Using model 'models/ggml-granite-7b-lab-Q4_K_M.gguf' with -1 gpu-layers and 4096 max context size.
Starting server process
After application startup complete see http://127.0.0.1:8000/docs for API.
Press CTRL+C to shut down the server.
"""
新たなターミナルを立ち上げて、モデルとchatしよう。下記のコマンドを実行します。
$ ilab model chat
"""
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────── system ────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Welcome to InstructLab Chat w/ GRANITE-7B-LAB-Q4_K_M.GGUF (type /h for help) │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
>>> instructlabについて日本語で教えて [S][default]
╭───────────────────────────────────────────────────────────────────────────────────────────────── granite-7b-lab-Q4_K_M.gguf ──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ instructlabは、AIアシスタントの一つである。宣言機械学習に基づいており、ユーザーの要求を理解し、正しいコマンドや回答を提供する。これは、Natural Language Processing (NLP) と呼ばれる技術によって実現されます。 │
│ │
│ instructlabは、Red Hat(リードハット)とIBM Researchによって開発されました。Red │
│ Hatは、オープンソースソフトウェアとシステムインテグレーターの企業です。彼らが開発したという認知度が高く、日本語で「リードハット」は、オープンソースに関する意味で使われます。IBM │
│ Researchは、国際的な研究機関であり、AIやデータ解析などの領域で有力です。 │
│ │
│ instructlabは、Granite-7b-baseに基づいて開発されました。Granite-7b-baseは、機械学習モデルの一つで、Natural Language Understanding (NLU) とNatural Language Generation (NLG) │
│ に関するパラメータを提供します。これらのパラメータは、instructlabがユーザーからの要求を理解するという機能を支持します。 │
│ │
│ instructlabは、AIアシスタントとして、ユーザーに対し、正しいコマンドや回答を提供することで、既知のモデルを超えて新しい機能を持っております。これは、モデルのアップグレードや再学習を含めたプロセスによって達成されます。 │
│ │
│ instructlabは、まだ完全に開発されていませんが、将来的な計画として、機械学習モデルの開発と、それを既知のアプレシオンやサービスに統合することで、ユーザーのニーズを従った、新しいAIアシスタントを作ります。 │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── elapsed 12.013 seconds ─
"""
最後に
今回はInstructLabに関する環境構築をしてみました。InstructLabを使うことで独自LLMを使用することができます。