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?

RHEL AIをAWS上で構築し、ワークフローを学ぶ

Last updated at Posted at 2025-04-14

目的

RHEL AIをAWSのEC2インスタンスにインストールし、LLMを使用するためのワークフローを学ぶ。

1. AWSのEC2上にインストール

上記に従ってやればできるが、つまづいた所を記載しておく。

RAW Imageのダウンロードとアップロードに時間がかかる

ダウンロードは半日ほど時間がかかったが、端末を放置しておけば良かったので手間は少なかった。
アップロードは、Management Consoleからやると端末を放置したままではエラーとなった。AWS CLIで実行したら、半日ほどで完了した。

インストールするInstance Typeに注意!!

公式ページにHardware requirementがあるので、それを参考にすること。私はそれを知らずにt3.medium, g4dn.xlarge, g4dn.2xlarge にインストールしたが、スペック不足で ilab model serve commandが失敗し、それ以上先へ進めなかった。

私は個人のアカウントでやっており潤沢なリソースを使えないので、最低限のg6.2xlargeを選択した。1時間動かすと、On-Demandで1USD弱かかる。

Spot instanceの方が安いので、それをやってみようと思った。
Spot Instanceで作るにはIDをリクエストする必要がある。Requestしようとしたが、自分のAMIを使えないようで、より調査が必要。
Instance Typeも自由に選べそうでないため、今回は諦める。

SSHで接続

AWS CLIでEC2へ接続する。Security GroupのInbound RulesにTCP 22ポートを追加しておくこと。
EC2のManagement ConsoleからKeypairを作成し、以下のコマンドを実行すること。

chmod 400 mykey.pem

Your key file must not be publicly viewable for SSH to work. Use this command if needed: chmod 400 mykey.pem

ユーザは管理者権限のあるec2-userを指定した。

ilabコマンドを実行するには、あらかじめRed Hat Insightsに登録しておく必要がある。ダッシュボードにアクセスして、Activation Keyを作成後に以下のコマンドを実行する。

sudo rhc connect --activation-key rhel-ai-insights-activation-key --organization 1xxxxxxx

この後、ilabコマンドが実行できれば準備完了。

2. InitializeからChatまで

上記のTutorialを参考に、以下の4つのプロセスを実行した。

Trying out a LLM
1. Initialize environment
2. download model
3. serve model
4. interact with the model

実行した際に気づいた点、注意点等をにまとめておく。

Initialize Environment

ilab config init

を実行し、GPUモデルを指定する。g6シリーズはNVIDIA L4を使用しており、2xlargeは8個のvCPUを積んでいるので、 NVIDIA L4 X8 を選択した。

Next, please select the specific hardware configuration that most closely matches your system.
[0] NO SYSTEM PROFILE
[1] NVIDIA A100 X2
[2] NVIDIA A100 X4
[3] NVIDIA A100 X8
[4] NVIDIA H100 X2
[5] NVIDIA H100 X4
[6] NVIDIA H100 X8
[7] NVIDIA L4 X8
[8] NVIDIA L40S X4
[9] NVIDIA L40S X8
nvidia-smi -q

を実行すると、GPUの詳細を見ることができる。

Download model

skopeo login registry.redhat.io

上記コマンドを実行し、UsernameとPasswordを入力することでRed HatのRegistoryからRHEL AIでサポートされているモデルをダウンロードできる。

今回は granite-7b-starter と、 granite-8b-starter-v1 の2つをダウンロードした。EC2のRegionをTokyoでなくNorth Virginiaにしたら、ダウンロードが圧倒的に早かった。

ilab model list

を実行するとOS内にインストールされているモデルのリストが出る。

Serve model

ilab config edit

を使い、gpus=1, nmu_cpus=8に変更しておくこと!!g6.2xlargeにはGPUが1つしかなく、vCPUが8であるため。これをやらないと ilab model serve を実行してもエラーが出て ApplictionがReadyにならない。
granite-7b-starter は起動できたが、 granite-8b-starter-v1 は起動できず。他にも設定変更が必要かもしれない。

INFO:     Started server process [34]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO 04-13 05:59:54 metrics.py:351] Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.0 tokens/s, Running: 0 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.0%, CPU KV cache usage: 0.0%.

Application startup complete が出力できれば準備完了。

Interact with the model

ilab model chat --model ~/.cache/instructlab/models/granite-7b-starter

ilab model serve を実行したTerminalとは別のTerminalを起動し、上記コマンドを入れればLLMとチャットできる。日本語で質問してもまともな答えが返ってこなかった。

3. Modelをトレーニングする

以下のプロセスを順番に実行し、Modelをトレーニングしてみる。

Train a LLM for accuracy
1. Prepare new knowledge
2. Generate synthetic data
3. Train the model

1. Prepare new knowledge

InstructLabで提供されるSynthetic Data Generation (SDG) プロセスを利用してモデルをトレーニングするには、新しいKnowledge(知識)を生成する。

以下のサンプルを使用してqna.yamlファイルを作成した。

cd  ~/.local/share/instructlab
mkdir -p ./taxonomy/knowledge/science/astronomy/constellations/Phoenix
cd ./taxonomy/knowledge/science/astronomy/constellations/Phoenix
vi qna.yaml
vi attribution.txt

RHEL AI上にあるサンプルの知識は不要なので削除しておく。

rm ~/.local/share/instructlab/taxonomy/compositional_skills/grounded/linguistics/inclusion/qna.yaml
rm ~/.local/share/instructlab/taxonomy/compositional_skills/grounded/linguistics/writing/rewriting/qna.yaml
rm ~/.local/share/instructlab/taxonomy/compositional_skills/linguistics/synonyms/qna.yaml
rm ~/.local/share/instructlab/taxonomy/knowledge/arts/music/fandom/swifties/qna.yaml
rm ~/.local/share/instructlab/taxonomy/knowledge/science/animals/birds/black_capped_chickadee/qna.yaml

作成したファイルをValidateする。以下のようなメッセージが出ると、Validationが成功していることが分かる。

ilab taxonomy diff
knowledge/science/astronomy/constellations/Phoenix/qna.yaml
Taxonomy in /var/home/ec2-user/.local/share/instructlab/taxonomy is valid :)

2. Generate synthetic data

作成したファイルを使ってモデルをトレーニングする。以下のサイトを参考にトレーニングを試みたが、HWスペックが足りずに失敗した。

generate 前に ilab config edit で設定変更する必要がある。

ilab config edit
cat ~/.config/instructlab/config.yaml

誰がTeacherモデルになりますか?
私の使っているHWでは7bのモデルしか動かないのでmerliniteを指定したが、エラーとなってデータを生成できなかった。。
この時点でのilabのデフォルトのTeacherは mixtral-8x7b-instruct-v0-1 だった。

 # Generate configuration section.
 # Teacher model that will be used to synthetically generate training data.
 model: /var/home/ec2-user/.cache/instructlab/models/merlinite-7b-lab-Q4_K_M.gguf

Student(Trainされる人)とJudgeする人は誰ですか?
Studentにはgranite-7b-starter、Judgeにはmistral-7b-instruct-v0.2.Q4_K_M.ggufを指定したが、エラーになった。
この時点でのilabのデフォルトのJudgeは prometheus-8x7b-v2-0 だった。

# Train configuration section.
# Directory where the model to be trained is stored.
model_path: /var/home/ec2-user/.cache/instructlab/models/granite-7b-starter
# Judge model path for phased MT-Bench evaluation.
phased_mt_bench_judge: /var/home/ec2-user/.cache/instructlab/models/mistral-7b-instruct-v0.2.Q4_K_M.gguf

参考文献

文中に記載した記事、リンクを貼った記事を以下に記載した。
当サイトに掲載している記事は個人の見解であり、所属する組織の公式見解ではない。

Red Hat社の公式サイト

InstructLabの公式ドキュメント

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?