カスタム データセットを使用して Llama 3 モデルを微調整し、微調整されたモデルで推論を実行するための、完全に含まれたすぐに実行できる環境
注: これは、これまでのところ、NVIDIA RTX 2080 および NVIDIA Tesla T4 GPU でのみテストされています。他の GPU クラスや CPU ではテストされていません。
ホスト マシンでこのコマンドを実行して、インストールされている Nvidia GPU を確認します。
nvidia-smi
GPU 情報が表示されるはずです。
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.171.04 Driver Version: 535.171.04 CUDA Version: 12.2 |
| -----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
| =========================================+======================+====================== |
| 0 NVIDIA GeForce RTX 2080 Off | 00000000:01:00.0 On | N/A |
| 22% 38C P8 17W / 215W | 197MiB / 8192MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
git clone https://github.com/amithkoujalgi/llama3-playground.git
cd llama3-playground
bash build.sh
bash run.sh
これにより、次のサービスを含む Docker コンテナが起動されます。
サービス | 外部からアクセス可能なエンドポイント | 内部ポート | 説明 |
---|---|---|---|
スーパーバイザー | http://ローカルホスト:8884 | 9001 | カスタム データセットでトレーニングを実行し、トレーナー プロセスのログを表示するため |
FastAPIサーバー | http://localhost:8883/docs | 8070 | モデルサーバーのAPIにアクセスするため |
JupyterLab サーバー | http://localhost:8888/lab | 8888 | JupyterLab インターフェイスにアクセスして、コンテナーを参照し、コードを更新/実験します。 |
注: すべてのプロセス (OCR、トレーニング、推論) は GPU を使用するため、どのタイプのプロセスでも複数のプロセスが同時に実行されると、メモリ不足 (OOM) の問題が発生します。これに対処するために、システムは任意の時点で 1 つのプロセスのみを実行するように設計されています。 (つまり、OCR、トレーニング、または推論のインスタンスは一度に 1 つだけ実行できます)
必要に応じてコードを自由に更新してください。
ターミナルに移動して入力します
playground --train
ターミナルに移動して入力します
playground -l
これにより/app/data/trained-models/
の下にモデルが生成されます。トレーナー スクリプトは 2 つのモデルを生成します。
lora-adapters
が付いているモデル。OCR を実行します。
cd /app/llama3_playground/core
python ocr.py
-f " /app/sample.pdf "
オプションの意味を理解するには、JupyterLab に移動し、 python ocr.py -h
を実行してください。
RAG を使用した推論:
cd /app/llama3_playground/core
python infer_rag.py
-m " llama-3-8b-instruct-custom-1720802202 "
-d " /app/data/ocr-runs/123/text-result.txt "
-q " What is the employer name, address, telephone, TIN, tax year end, type of business, plan name, Plan Sequence Number, Trust ID, Account number, is it a new plan or existing plan as true or false, are elective deferrals and roth deferrals allowed as true or false, are loans permitted as true or false, are life insurance investments permitted and what is the ligibility Service Requirement selected? "
-t 256
-e " Alibaba-NLP/gte-base-en-v1.5 "
-p " There are checkboxes in the text that denote the value as selected if the text is [Yes], and unselected if the text is [No]. The checkbox option's value can either be before the selected value or after. Keep this in context while responding and be very careful and precise in picking these values. Always respond as JSON. Keep the responses precise and concise. "
オプションの意味を理解するには、JupyterLab に移動し、 python infer_rag.py -h
を実行してください。
これは、ホスト マシンに NVIDIA Container Toolkit がインストールされていない場合に必要になります。
# Configure the production repository
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list |
sed ' s#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g ' |
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
# Optionally, configure the repository to use experimental packages
sed -i -e ' /experimental/ s/^#//g ' /etc/apt/sources.list.d/nvidia-container-toolkit.list
# Update the packages list from the repository
sudo apt-get update
# Install the NVIDIA Container Toolkit packages
sudo apt-get install -y nvidia-container-toolkit
その他の環境についてはこちらを参照してください。
curl --silent -X ' POST '
' http://localhost:8883/api/infer/sync/ctx-text '
-H ' accept: application/json '
-H ' Content-Type: application/json '
-d ' {
"model_name": "llama-3-8b-instruct-custom-1720690384",
"context_data": "You are a magician who goes by the name Magica",
"question_text": "Who are you?",
"prompt_text": "Respond in a musical and Shakespearean tone",
"max_new_tokens": 50
} ' | jq -r " .data.response "
curl -X ' POST '
' http://localhost:8883/api/ocr/sync/pdf '
-H ' accept: application/json '
-H ' Content-Type: multipart/form-data '
-F ' file=@your_file.pdf;type=application/pdf '
true
を返し、それ以外の場合はfalse
を返します。 curl -X ' GET '
' http://localhost:8883/api/ocr/status '
-H ' accept: application/json '
参考文献: