ノート:
- このチュートリアルでは、Oracle Cloudへのアクセスが必要です。無料アカウントにサインアップするには、Oracle Cloud Infrastructure Free Tierの開始を参照してください。
- Oracle Cloud Infrastructureの資格証明、テナンシおよびコンパートメントの値の例を使用します。演習を完了するときに、これらの値をクラウド環境に固有の値に置き換えます。
ワンクリック・デプロイメントを使用したOracle Resource Managerを使用したOCI Compute A10.2インスタンスでのElyza LLMモデルの実行
イントロダクション
Oracle Cloud Infrastructure (OCI) Computeでは、様々なタイプのシェイプを作成して、ローカルにデプロイされた人工知能(AI)モデルのグラフィック処理ユニット(GPU)をテストできます。このチュートリアルでは、Oracle Resource Managerから選択できる既存のVCNおよびサブネット・リソースとともにA10.2シェイプを使用します。
Terraformコードには、自然言語処理タスク用にローカルのVirtual Large Language Model (vLLM) Elyzaモデルを実行するためのインスタンスの構成も含まれています。
目的
- OCI ComputeでA10.2シェイプを作成し、Elyza LLMモデルをダウンロードして、ローカルvLLMモデルを問い合せます。
前提条件
-
OCI Virtual Cloud Network (VCN)と、仮想マシン(VM)がデプロイされるサブネットがあることを確認します。
-
ネットワーク・コンポーネントとその関係の理解。詳細は、ネットワーキングの概要を参照してください。
-
クラウドでのネットワーキングの理解。詳細は、クラウドにおけるネットワーキングのビデオEP.01: Virtual Cloud Networksのビデオをご覧ください。
-
要件:
- インスタンス・タイプ: 2つのNvidia GPUを持つA10.2シェイプ。
- オペレーティング・システム: Oracle Linux。
- イメージの選択:デプロイメント・スクリプトは、GPUサポートを含む最新のOracle Linuxイメージを選択します。
- タグ:フリーフォーム・タグGPU_TAG = "A10-2"を追加します。
- ブート・ボリューム・サイズ: 250GB
- 初期化: cloud-initを使用して、vLLM Elyzaモデルをダウンロードおよび構成します。
タスク1: ワンクリック・デプロイメント用のTerraformコードのダウンロード
orm_stack_a10_2_gpu_elyza_models.zipからORM Terraformコードをダウンロードして、Elyza vLLMモデルをローカルに実装します。これにより、既存のVCNとサブネットを選択して、A10.2インスタンス・シェイプでのElyza vLLMモデルのローカル・デプロイメントをテストできます。
ORM Terraformコードをローカルにダウンロードしたら、フォルダからのスタックの作成のステップに従ってスタックをアップロードし、Terraformコードの適用を実行します。
ノート: VMがデプロイされるOCI Virtual Cloud Network (VCN)およびサブネットが作成されていることを確認します。
タスク2: OCIでのVCNの作成(オプション(まだ作成されていない場合)
Oracle Cloud InfrastructureでVCNを作成するには、OCIでVirtual Cloudネットワークを作成する方法の確認ビデオを参照してください。
または
VCNを作成するには、次のステップに従います。
-
OCIコンソールにログインし、「クラウド・テナント名」、「ユーザー名」および「パスワード」を入力します。
-
左上隅のハンバーガーメニュー(≡)をクリックします。
-
「ネットワーキング」、「Virtual Cloud Networks」に移動し、「リスト範囲」セクションから適切なコンパートメントを選択します。
-
「インターネット接続性を持つVCN」,を選択し、「VCNウィザードの起動」をクリックします
-
「インターネット接続性を持つVCNの作成」ページで、次の情報を入力して「次」をクリックします。
- VCN名:
OCI_HOL_VCN
と入力します。 - コンパートメント:適切なコンパートメントを選択します。
- VCN CIDRブロック:
10.0.0.0/16
と入力します。 - PUBLIC SUBNET CIDR BLOCK:
10.0.2.0/24
と入力します。 - PRIVATE SUBNET CIDR BLOCK:
10.0.1.0/24
と入力します。 - DNS解決: 「このVCNでDNSホスト名を使用」を選択します。
- VCN名:
-
「確認」ページで設定を確認し、「作成」をクリックします。
VCNの作成にはしばらく時間がかかり、進行状況画面ではワークフローが表示されなくなります。
-
VCNが作成されたら、「Virtual Cloud Networkの表示」をクリックします。
実際の状況では、アクセスの必要性(どのポートを開くか)およびアクセスできるユーザーに基づいて、複数のVCNを作成します。
タスク3: cloud-init構成の詳細を参照
cloud-init
スクリプトは、必要なすべての依存関係をインストールし、Dockerを起動し、vLLM Elyzaモデルをダウンロードして起動します。タスク1でダウンロードしたcloudinit.sh
ファイルに、次のコードがあります。
dnf install -y dnf-utils zip unzip
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
dnf remove -y runc
dnf install -y docker-ce --nobest
systemctl enable docker.service
dnf install -y nvidia-container-toolkit
systemctl start docker.service
...
Cloud-initは、Elyzaモデルの実行に必要なすべてのファイルをダウンロードし、Hugging Faceで事前定義されたAPIトークンを必要としません。タスク6でDockerを使用してElyzaモデルを起動するには、APIトークンが必要です。
タスク4: システムのモニター
次のコマンドを使用して、cloud-initの完了およびGPUリソースの使用状況を追跡します(必要な場合)。
-
cloud-initの完了をモニターします:
tail -f /var/log/cloud-init-output.log
。 -
GPU使用率の監視:
nvidia-smi dmon -s mu -c 100 --id 0,1
。 -
Pythonを使用してvLLM Elyzaモデルをデプロイおよび操作します: (必要な場合にのみパラメータを変更します。コマンドは
cloud-init
スクリプトにすでに含まれています):python -O -u -m vllm.entrypoints.api_server \ --host 0.0.0.0 \ --port 8000 \ --model /home/opc/models/${MODEL} \ --tokenizer hf-internal-testing/llama-tokenizer \ --enforce-eager \ --max-num-seqs 1 \ --tensor-parallel-size 2 \ >> /home/opc/${MODEL}.log 2>&1
タスク5: モデル統合のテスト
コマンドまたはJupyter Notebookの詳細を使用して、次の方法でモデルと対話します。
-
cloud-initが完了したら、コマンドライン・インタフェース(CLI)からモデルをテストします。
curl -X POST "http://0.0.0.0:8000/generate" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ -d '{"prompt": "Write a humorous limerick about the wonders of GPU computing.", "max_tokens": 64, "temperature": 0.7, "top_p": 0.9}'
-
Jupyter Notebookからモデルをテストします(ポート
8888
を開いていることを確認します)。import requests import json url = "http://0.0.0.0:8000/generate" headers = { "accept": "application/json", "Content-Type": "application/json", } data = { "prompt": "Write a short conclusion.", "max_tokens": 64, "temperature": 0.7, "top_p": 0.9 } response = requests.post(url, headers=headers, json=data) if response.status_code == 200: result = response.json() # Pretty print the response for better readability formatted_response = json.dumps(result, indent=4) print("Response:", formatted_response) else: print("Request failed with status code:", response.status_code) print("Response:", response.text)
-
Gradioとチャットボットを統合してモデルを問い合せる。
import requests import gradio as gr import os # Function to interact with the model via API def interact_with_model(prompt): url = 'http://0.0.0.0:8000/generate' headers = { "accept": "application/json", "Content-Type": "application/json", } data = { "prompt": prompt, "max_tokens": 64, "temperature": 0.7, "top_p": 0.9 } response = requests.post(url, headers=headers, json=data) if response.status_code == 200: result = response.json() completion_text = result["text"][0].strip() # Extract the generated text return completion_text else: return {"error": f"Request failed with status code {response.status_code}"} # Retrieve the MODEL environment variable model_name = os.getenv("MODEL") # Example Gradio interface iface = gr.Interface( fn=interact_with_model, inputs=gr.Textbox(lines=2, placeholder="Write a prompt..."), outputs=gr.Textbox(type="text", placeholder="Response..."), title=f"{model_name} Interface", # Use model_name to dynamically set the title description=f"Interact with the {model_name} deployed locally via Gradio.", # Use model_name to dynamically set the description live=True ) # Launch the Gradio interface iface.launch(share=True)
タスク6: Dockerを使用したモデルのデプロイ(必要な場合)
または、カプセル化された環境にDockerを使用してモデルをデプロイします:
-
外部ソースからのモデル。
docker run --gpus all \ --env "HUGGING_FACE_HUB_TOKEN=$TOKEN_ACCESS" \ -p 8000:8000 \ --ipc=host \ --restart always \ vllm/vllm-openai:latest \ --tensor-parallel-size 2 \ --model elyza/$MODEL
-
すでにダウンロードされているローカル・ファイルを使用してdockerで実行中のモデル(より速く起動します)。
docker run --gpus all \ -v /home/opc/models/$MODEL/:/mnt/model/ \ --env "HUGGING_FACE_HUB_TOKEN=$TOKEN_ACCESS" \ -p 8000:8000 \ --env "TRANSFORMERS_OFFLINE=1" \ --env "HF_DATASET_OFFLINE=1" \ --ipc=host vllm/vllm-openai:latest \ --model="/mnt/model/" \ --tensor-parallel-size 2
次の方法でモデルを問い合せることができます。
-
CLIからDockerで起動したモデルを問い合せます(これにはさらに注意が必要です):
-
外部ソースからのDockerで開始されたモデル。
(elyza) [opc@a10-2-gpu ~]$ curl -X 'POST' 'http://0.0.0.0:8000/v1/chat/completions' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "model": "elyza/'${MODEL}'", "messages": [{"role": "user", "content": "Write a humorous limerick about the wonders of GPU computing."}], "max_tokens": 64, "temperature": 0.7, "top_p": 0.9 }'
-
モデルがDockerでローカルに開始されました。
curl -X 'POST' 'http://0.0.0.0:8000/v1/chat/completions' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{ "model": "/mnt/model/", "messages": [{"role": "user", "content": "Write a humorous limerick about the wonders of GPU computing."}], "max_tokens": 64, "temperature": 0.7, "top_p": 0.9 }'
-
-
Jupyter NotebookからDockerで開始したモデルを問い合せます。
-
Docker Hubから開始したモデル。
import requests import json import os url = "http://0.0.0.0:8000/v1/chat/completions" headers = { "accept": "application/json", "Content-Type": "application/json", } # Assuming `MODEL` is an environment variable set appropriately model = f"elyza/{os.getenv('MODEL')}" data = { "model": model, "messages": [{"role": "user", "content": "Write a humorous limerick about the wonders of GPU computing."}], "max_tokens": 64, "temperature": 0.7, "top_p": 0.9 } response = requests.post(url, headers=headers, json=data) if response.status_code == 200: result = response.json() # Extract the generated text from the response completion_text = result["choices"][0]["message"]["content"].strip() print("Generated Text:", completion_text) else: print("Request failed with status code:", response.status_code) print("Response:", response.text)
-
コンテナはDockerでローカルに開始されました。
import requests import json import os url = "http://0.0.0.0:8000/v1/chat/completions" headers = { "accept": "application/json", "Content-Type": "application/json", } # Assuming `MODEL` is an environment variable set appropriately model = f"/mnt/model/" # Adjust this based on your specific model path or name data = { "model": model, "messages": [{"role": "user", "content": "Write a humorous limerick about the wonders of GPU computing."}], "max_tokens": 64, "temperature": 0.7, "top_p": 0.9 } response = requests.post(url, headers=headers, json=data) if response.status_code == 200: result = response.json() # Extract the generated text from the response completion_text = result["choices"][0]["message"]["content"].strip() print("Generated Text:", completion_text) else: print("Request failed with status code:", response.status_code) print("Response:", response.text)
-
-
チャットボットと統合されたGradioを使用して、Dockerで開始したモデルを問い合せます。
-
外部ソースからのDockerで開始されたモデル。
import requests import gradio as gr import os # Function to interact with the model via API def interact_with_model(prompt): url = 'http://0.0.0.0:8000/v1/chat/completions' # Update the URL to match the correct endpoint headers = { "accept": "application/json", "Content-Type": "application/json", } # Assuming `MODEL` is an environment variable set appropriately model = f"elyza/{os.getenv('MODEL')}" data = { "model": model, "messages": [{"role": "user", "content": prompt}], # Use the user-provided prompt "max_tokens": 64, "temperature": 0.7, "top_p": 0.9 } response = requests.post(url, headers=headers, json=data) if response.status_code == 200: result = response.json() completion_text = result["choices"][0]["message"]["content"].strip() # Extract the generated text return completion_text else: return {"error": f"Request failed with status code {response.status_code}"} # Retrieve the MODEL environment variable model_name = os.getenv("MODEL") # Example Gradio interface iface = gr.Interface( fn=interact_with_model, inputs=gr.Textbox(lines=2, placeholder="Write a prompt..."), outputs=gr.Textbox(type="text", placeholder="Response..."), title=f"{model_name} Interface", # Use model_name to dynamically set the title description=f"Interact with the {model_name} model deployed locally via Gradio.", # Use model_name to dynamically set the description live=True ) # Launch the Gradio interface iface.launch(share=True)
-
Gradioを使用してDockerでローカルにコンテナを開始
import requests import gradio as gr import os # Function to interact with the model via API def interact_with_model(prompt): url = 'http://0.0.0.0:8000/v1/chat/completions' # Update the URL to match the correct endpoint headers = { "accept": "application/json", "Content-Type": "application/json", } # Assuming `MODEL` is an environment variable set appropriately model = "/mnt/model/" # Adjust this based on your specific model path or name data = { "model": model, "messages": [{"role": "user", "content": prompt}], "max_tokens": 64, "temperature": 0.7, "top_p": 0.9 } response = requests.post(url, headers=headers, json=data) if response.status_code == 200: result = response.json() completion_text = result["choices"][0]["message"]["content"].strip() return completion_text else: return {"error": f"Request failed with status code {response.status_code}"} # Example Gradio interface iface = gr.Interface( fn=interact_with_model, inputs=gr.Textbox(lines=2, placeholder="Write a humorous limerick about the wonders of GPU computing."), outputs=gr.Textbox(type="text", placeholder="Response..."), title="Model Interface", # Set your desired title here description="Interact with the model deployed locally via Gradio.", live=True ) # Launch the Gradio interface iface.launch(share=True)
ノート: Jupyter Notebookの
8888
ポートを開くファイアウォール・コマンド。sudo firewall-cmd --zone=public --permanent --add-port 8888/tcp sudo firewall-cmd --reload sudo firewall-cmd --list-all
-
承認
-
著者 - Bogdan Bazarca (シニア・クラウド・エンジニア)
-
コントリビュータ - Oracle NACI-AI-CN-DEVチーム
その他の学習リソース
docs.oracle.com/learnの他のラボを確認するか、Oracle Learning YouTubeチャネルで無料のラーニング・コンテンツにアクセスしてください。また、education.oracle.com/learning-explorerにアクセスしてOracle Learning Explorerになります。
製品ドキュメントは、Oracle Help Centerを参照してください。
Run Elyza LLM Model on OCI Compute A10.2 Instance with Oracle Resource Manager using One Click Deployment
G11827-01
July 2024