์ด ๊ฐ์ด๋์์๋ Saxml์ ์ฌ์ฉํด์ Vertex AI์์ Tensor Processing Unit(TPU)์ ์ฌ์ฉํ์ฌ Gemma ๊ฐ๋ฐฉํ ๋ชจ๋ธ ๋๊ท๋ชจ ์ธ์ด ๋ชจ๋ธ(LLM)์ ์ ๊ณตํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค. ์ด ๊ฐ์ด๋์์๋ 2B ๋ฐ 7B ๋งค๊ฐ๋ณ์ ๋ช ๋ น์ด ์กฐ์ ๋ Gemma ๋ชจ๋ธ์ Cloud Storage์ ๋ค์ด๋ก๋ํ๊ณ TPU์์ Saxml์ ์คํํ๋ Vertex AI์ ๋ฐฐํฌํฉ๋๋ค.
๋ฐฐ๊ฒฝ
Saxml์ ํตํด Vertex AI์์ TPU๋ฅผ ์ฌ์ฉํ์ฌ Gemma๋ฅผ ์ ๊ณตํฉ๋๋ค. ํ์ ์์ค ์ธํ๋ผ๋ฅผ ๊ด๋ฆฌํ๊ณ LLM์ ์ ๊ณตํ๋ ๋น์ฉ ํจ์จ์ ์ธ ๋ฐฉ๋ฒ์ ์ ๊ณตํ๋ ๊ด๋ฆฌํ AI ์๋ฃจ์ ์ ํ์ฉํ ์ ์์ต๋๋ค. ์ด ์น์ ์์๋ ์ด ํํ ๋ฆฌ์ผ์์ ์ฌ์ฉ๋๋ ์ฃผ์ ๊ธฐ์ ์ ์ค๋ช ํฉ๋๋ค.
Gemma
Gemma๋ ์คํ ๋ผ์ด์ ์ค๋ก ์ถ์๋ ๊ณต๊ฐ์ ์ผ๋ก ์ฌ์ฉ ๊ฐ๋ฅํ ๊ฐ๋ฒผ์ด ์์ฑํ ์ธ๊ณต์ง๋ฅ(AI) ๋ชจ๋ธ ์งํฉ์ ๋๋ค. ์ด๋ฌํ AI ๋ชจ๋ธ์ ์ ํ๋ฆฌ์ผ์ด์ , ํ๋์จ์ด, ํด๋๊ธฐ๊ธฐ ๋๋ ํธ์คํ ๋ ์๋น์ค์์ ์คํํ ์ ์์ต๋๋ค. ํ ์คํธ ์์ฑ์ Gemma ๋ชจ๋ธ์ ์ฌ์ฉํ ์ ์์ง๋ง ํน์ํ ํ์คํฌ๋ฅผ ์ํด ์ด๋ฌํ ๋ชจ๋ธ์ ์กฐ์ ํ ์๋ ์์ต๋๋ค.
์์ธํ ๋ด์ฉ์ Gemma ๋ฌธ์๋ฅผ ์ฐธ์กฐํ์ธ์.
Saxml
Saxml์ ์ถ๋ก ์ ์ํด Paxml, JAX, PyTorch ๋ชจ๋ธ์ ์ ๊ณตํ๋ ์คํ์ฉ ์์คํ ์ ๋๋ค. ์ด ํํ ๋ฆฌ์ผ์์๋ Saxml์ ๋ ๋น์ฉ ํจ์จ์ ์ธ TPU์์ Gemma๋ฅผ ์ ๊ณตํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํฉ๋๋ค. GPU ์ค์ ๋ ๋น์ทํฉ๋๋ค. Saxml์ ์ด ํํ ๋ฆฌ์ผ์์ ์ฌ์ฉํ Vertex AI์ฉ ์ปจํ ์ด๋๋ฅผ ๋น๋ํ๋ ์คํฌ๋ฆฝํธ๋ฅผ ์ ๊ณตํฉ๋๋ค.
TPU
TPU๋ Google์์ ์ปค์คํ ๊ฐ๋ฐํ ASIC(Application-Specific Integrated Circuits)๋ก์ TensorFlow, PyTorch, JAX์ ๊ฐ์ ๋ฐ์ดํฐ ์ฒ๋ฆฌ ํ๋ ์์ํฌ๋ฅผ ๊ฐ์ํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
์ด ํํ ๋ฆฌ์ผ์ Gemma 2B ๋ฐ Gemma 7B ๋ชจ๋ธ์ ์ฌ์ฉํฉ๋๋ค. Vertex AI๋ ๋ค์๊ณผ ๊ฐ์ ๋จ์ผ ํธ์คํธ TPU v5e ๋ ธ๋ ํ์์ ์ด๋ฌํ ๋ชจ๋ธ์ ํธ์คํ ํฉ๋๋ค.
- Gemma 2B: ํ๋์ TPU ์นฉ์ ๋ํ๋ด๋
1x1
ํ ํด๋ก์ง๊ฐ ์๋ TPU v5e ๋ ธ๋ ํ์์ ํธ์คํ ๋ฉ๋๋ค. ๋ ธ๋์ ๋จธ์ ์ ํ์ct5lp-hightpu-1t
์ ๋๋ค. - Gemma 7B: 4๊ฐ์ TPU ์นฉ์ ๋ํ๋ด๋
2x2
ํ ํด๋ก์ง๊ฐ ์๋ TPU v5e ๋ ธ๋ ํ์์ ํธ์คํ ๋ฉ๋๋ค. ๋ ธ๋์ ๋จธ์ ์ ํ์ct5lp-hightpu-4t
์ ๋๋ค.
์์ํ๊ธฐ ์ ์
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Vertex AI์ฉ TPU v5e ์นฉ์ ์ถฉ๋ถํ ํ ๋น๋์ด ์๋์ง ํ์ธํฉ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ์ด ํ ๋น๋์ 0์
๋๋ค.
1x1
ํ ํด๋ก์ง์ ๊ฒฝ์ฐ 1์ด์ด์ผ ํฉ๋๋ค.2x2
์ ๊ฒฝ์ฐ 4์ฌ์ผ ํฉ๋๋ค. ๋ ํ ํด๋ก์ง๋ฅผ ๋ชจ๋ ์คํํ๋ ค๋ฉด 5์ฌ์ผ ํฉ๋๋ค. - Kaggle ๊ณ์ ์ด ์๋ ๊ฒฝ์ฐ ๋ง๋ญ๋๋ค.
- Kaggle.com์ ๋ชจ๋ธ ๋์ ํ์ด์ง์ ์ก์ธ์คํฉ๋๋ค.
- ์์ง ๋ก๊ทธ์ธํ์ง ์์๋ค๋ฉด Kaggle์ ๋ก๊ทธ์ธํฉ๋๋ค.
- ์ก์ธ์ค ์์ฒญ์ ํด๋ฆญํฉ๋๋ค.
- ๋์๋ฅผ ์ํ ๊ณ์ ์ ํ ์น์ ์์ Kaggle ๊ณ์ ์ ํตํด ์ธ์ฆ์ ์ ํํ์ฌ ๋์๋ฅผ ์ํด Kaggle ๊ณ์ ์ ์ฌ์ฉํฉ๋๋ค.
- ๋ชจ๋ธ ์ด์ฉ์ฝ๊ด์ ๋์ํฉ๋๋ค.
- ๋ธ๋ผ์ฐ์ ์์ Kaggle ์ค์ ์ผ๋ก ์ด๋ํฉ๋๋ค.
API ์น์ ์์ ์ ํ ํฐ ๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
kaggle.json
์ด๋ผ๋ ํ์ผ์ด ๋ค์ด๋ก๋๋ฉ๋๋ค.- Cloud Shell์์ > ์ ๋ก๋๋ฅผ ํด๋ฆญํฉ๋๋ค. ๋๋ณด๊ธฐ
- ํ์ผ์ ์ ํํ๊ณ ํ์ผ ์ ํ์ ํด๋ฆญํฉ๋๋ค.
kaggle.json
ํ์ผ์ ์ฝ๋๋ค.- ์ ๋ก๋๋ฅผ ํด๋ฆญํฉ๋๋ค.
- PROJECT_ID: Google Cloudํ๋ก์ ํธ ID
- LOCATION_ID: Vertex AI๋ฅผ ์ฌ์ฉํ๋ ๋ฆฌ์ TPU๋ us-west1์์๋ง ์ฌ์ฉํ ์ ์์ต๋๋ค.
-
DEPLOYED_MODEL_NAME:
DeployedModel
์ ์ด๋ฆ.DeployedModel
์Model
ํ์ ์ด๋ฆ๋ ์ฌ์ฉํ ์ ์์ต๋๋ค. - LOCATION_ID: Vertex AI๋ฅผ ์ฌ์ฉํ๋ ๋ฆฌ์
- ENDPOINT_NAME: ์๋ํฌ์ธํธ์ ํ์ ์ด๋ฆ
- LOCATION_ID: Vertex AI๋ฅผ ์ฌ์ฉํ๋ ๋ฆฌ์
- ENDPOINT_NAME: ์๋ํฌ์ธํธ์ ํ์ ์ด๋ฆ
-
DEPLOYED_MODEL_NAME:
DeployedModel
์ ์ด๋ฆ.DeployedModel
์Model
ํ์ ์ด๋ฆ๋ ์ฌ์ฉํ ์ ์์ต๋๋ค. - LOCATION_ID: Vertex AI๋ฅผ ์ฌ์ฉํ๋ ๋ฆฌ์
- ENDPOINT_NAME: ์๋ํฌ์ธํธ์ ํ์ ์ด๋ฆ
- instances.json์ ํ์์
{"instances": [{"text_batch": "<your prompt>"},{...}]}
์ ๋๋ค. ์๋ํฌ์ธํธ์์ ๋ชจ๋ธ์ ๋ฐฐํฌ ํด์ ํ๊ณ ์๋ํฌ์ธํธ๋ฅผ ์ญ์ ํ๋ ค๋ฉด ์ ธ์์ ๋ค์ ๋ช ๋ น์ด๋ฅผ ์คํํฉ๋๋ค.
ENDPOINT_ID=$(gcloud ai endpoints list \ --region=LOCATION \ --filter=display_name=ENDPOINT_NAME \ --format="value(name)") DEPLOYED_MODEL_ID=$(gcloud ai endpoints describe $ENDPOINT_ID \ --region=LOCATION \ --format="value(deployedModels.id)") gcloud ai endpoints undeploy-model $ENDPOINT_ID \ --region=LOCATION \ --deployed-model-id=$DEPLOYED_MODEL_ID gcloud ai endpoints delete $ENDPOINT_ID \ --region=LOCATION \ --quiet
LOCATION์ ์ด์ ์น์ ์์ ๋ชจ๋ธ์ ๋ง๋ ๋ฆฌ์ ์ผ๋ก ๋ฐ๊ฟ๋๋ค.
๋ชจ๋ธ์ ์ญ์ ํ๋ ค๋ฉด ์ ธ์์ ๋ค์ ๋ช ๋ น์ด๋ฅผ ์คํํฉ๋๋ค.
MODEL_ID=$(gcloud ai models list \ --region=LOCATION \ --filter=display_name=DEPLOYED_MODEL_NAME \ --format="value(name)") gcloud ai models delete $MODEL_ID \ --region=LOCATION \ --quiet
LOCATION์ ์ด์ ์น์ ์์ ๋ชจ๋ธ์ ๋ง๋ ๋ฆฌ์ ์ผ๋ก ๋ฐ๊ฟ๋๋ค.
- Vertex AI์์๋ Cloud TPU๊ฐ
us-west1
์์๋ง ์ง์๋ฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ์์น๋ฅผ ์ฐธ์กฐํ์ธ์. - Llama2 ๋ฐ GPT-J์ ๊ฐ์ ๋ค๋ฅธ Saxml ๋ชจ๋ธ์ ๋ฐฐํฌํ๋ ๋ฐฉ๋ฒ์ ์์๋ด ๋๋ค.
์ด ํํ ๋ฆฌ์ผ์์๋ Cloud Shell์ ์ฌ์ฉํ์ฌ Google Cloud์ ์ํธ์์ฉํ๋ค๊ณ ๊ฐ์ ํฉ๋๋ค. Cloud Shell ๋์ ๋ค๋ฅธ ์ ธ์ ์ฌ์ฉํ๋ ค๋ฉด ๋ค์ ์ถ๊ฐ ๊ตฌ์ฑ์ ์ํํ์ธ์.
๋ชจ๋ธ ์ก์ธ์ค ๊ถํ ์ป๊ธฐ
Cloud Shell์๋ ๋ชจ๋ธ ๊ฐ์ค์น๋ฅผ ๋ค์ด๋ก๋ํ๊ธฐ์ ์ถฉ๋ถํ ๋ฆฌ์์ค๊ฐ ์์ ์ ์์ต๋๋ค. ์ด ๊ฒฝ์ฐ ํด๋น ์์ ์ ์คํํ Vertex AI Workbench ์ธ์คํด์ค๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค.
Vertex AI์ ๋ฐฐํฌํ๊ธฐ ์ํด Gemma ๋ชจ๋ธ์ ์ก์ธ์คํ๋ ค๋ฉด Kaggle ํ๋ซํผ์ ๋ก๊ทธ์ธํ๊ณ ๋ผ์ด์ ์ค ๋์ ๊ณ์ฝ์ ์๋ช ํ๊ณ Kaggle API ํ ํฐ์ ๊ฐ์ ธ์์ผ ํฉ๋๋ค. ์ด ํํ ๋ฆฌ์ผ์์๋ Kaggle ์ฌ์ฉ์ ์ธ์ฆ ์ ๋ณด์ Kubernetes ๋ณด์ ๋น๋ฐ์ ์ฌ์ฉํฉ๋๋ค.
๋ผ์ด์ ์ค ๋์ ๊ณ์ฝ ์๋ช
Gemma๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด ๋์ ๊ณ์ฝ์ ์๋ช ํด์ผ ํฉ๋๋ค. ๋ค์ ์๋ด๋ฅผ ๋ฐ๋ฅด์ธ์.
์ก์ธ์ค ํ ํฐ ์์ฑ
Kaggle์ ํตํด ๋ชจ๋ธ์ ์ก์ธ์คํ๋ ค๋ฉด Kaggle API ํ ํฐ์ด ํ์ํฉ๋๋ค.
์์ง ํ ํฐ์ด ์์ผ๋ฉด ๋ค์ ๋จ๊ณ์ ๋ฐ๋ผ ์ ํ ํฐ์ ์์ฑํฉ๋๋ค.
Cloud Shell์ ์ก์ธ์ค ํ ํฐ ์ ๋ก๋
Cloud Shell์์ Kaggle API ํ ํฐ์ Google Cloudํ๋ก์ ํธ์ ์ ๋ก๋ํ ์ ์์ต๋๋ค.
Cloud Storage ๋ฒํท ๋ง๋ค๊ธฐ
๋ชจ๋ธ ์ฒดํฌํฌ์ธํธ๋ฅผ ์ ์ฅํ Cloud Storage ๋ฒํท์ ๋ง๋ญ๋๋ค.
Cloud Shell์์ ๋ค์์ ์คํํฉ๋๋ค.
gcloud storage buckets create gs://CHECKPOINTS_BUCKET_NAME
CHECKPOINTS_BUCKET_NAME์ ๋ชจ๋ธ ์ฒดํฌํฌ์ธํธ๋ฅผ ์ ์ฅํ๋ Cloud Storage ๋ฒํท์ ์ด๋ฆ์ผ๋ก ๋ฐ๊ฟ๋๋ค.
Cloud Storage ๋ฒํท์ ๋ชจ๋ธ ๋ณต์ฌ
Cloud Shell์์ ๋ค์์ ์คํํฉ๋๋ค.
pip install kaggle --break-system-packages
# For Gemma 2B
mkdir -p /data/gemma_2b-it
kaggle models instances versions download google/gemma/pax/2b-it/1 --untar -p /data/gemma_2b-it
gcloud storage cp /data/gemma_2b-it/* gs://CHECKPOINTS_BUCKET_NAME/gemma_2b-it/ --recursive
# For Gemma 7B
mkdir -p /data/gemma_7b-it
kaggle models instances versions download google/gemma/pax/7b-it/1 --untar -p /data/gemma_7b-it
gcloud storage cp /data/gemma_7b-it/* gs://CHECKPOINTS_BUCKET_NAME/gemma_7b-it/ --recursive
๋ชจ๋ธ ๋ฐฐํฌ
๋ชจ๋ธ ์ ๋ก๋
Saxml ์ปจํ
์ด๋๋ฅผ ์ฌ์ฉํ๋ Model
๋ฆฌ์์ค๋ฅผ ์
๋ก๋ํ๋ ค๋ฉด ๋ค์ gcloud ai models upload
๋ช
๋ น์ด๋ฅผ ์คํํฉ๋๋ค.
Gemma 2B-it
gcloud ai models upload \
--region=LOCATION \
--display-name=DEPLOYED_MODEL_NAME \
--container-image-uri=us-docker.pkg.dev/vertex-ai/prediction/sax-tpu:latest \
--artifact-uri='gs://CHECKPOINTS_BUCKET_NAME/gemma_2b-it/' \
--container-args='--model_path=saxml.server.pax.lm.params.gemma.Gemma2BFP16' \
--container-args='--platform_chip=tpuv5e' \
--container-args='--platform_topology=2x2' \
--container-args='--ckpt_path_suffix=checkpoint_00000000' \
--container-ports=8502
Gemma 7B-it
gcloud ai models upload \
--region=LOCATION \
--display-name=DEPLOYED_MODEL_NAME \
--container-image-uri=us-docker.pkg.dev/vertex-ai/prediction/sax-tpu:latest \
--artifact-uri='gs://CHECKPOINTS_BUCKET_NAME/gemma_7b-it/' \
--container-args='--model_path=saxml.server.pax.lm.params.gemma.Gemma7BFP16' \
--container-args='--platform_chip=tpuv5e' \
--container-args='--platform_topology=2x2' \
--container-args='--ckpt_path_suffix=checkpoint_00000000' \
--container-ports=8502
๋ค์์ ๋ฐ๊ฟ๋๋ค.
์๋ํฌ์ธํธ ๋ง๋ค๊ธฐ
์จ๋ผ์ธ ์ถ๋ก ์ ๊ณต์ ์ํด ๋ชจ๋ธ์ ์ฌ์ฉํ๋ ค๋ฉด ๋จผ์ ๋ชจ๋ธ์ ์๋ํฌ์ธํธ์ ๋ฐฐํฌํด์ผ ํฉ๋๋ค. ๊ธฐ์กด ์๋ํฌ์ธํธ์ ๋ชจ๋ธ์ ๋ฐฐํฌํ๋ ๊ฒฝ์ฐ ์ด ๋จ๊ณ๋ฅผ ๊ฑด๋๋ธ ์ ์์ต๋๋ค. ๋ค์ ์์์์๋ gcloud ai endpoints create
๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํฉ๋๋ค.
gcloud ai endpoints create \
--region=LOCATION \
--display-name=ENDPOINT_NAME
๋ค์์ ๋ฐ๊ฟ๋๋ค.
Google Cloud CLI ๋๊ตฌ๊ฐ ์๋ํฌ์ธํธ๋ฅผ ๋ง๋๋ ๋ฐ ๋ช ์ด ์ ๋ ๊ฑธ๋ฆด ์ ์์ต๋๋ค.
์๋ํฌ์ธํธ์ ๋ชจ๋ธ ๋ฐฐํฌ
์๋ํฌ์ธํธ๊ฐ ์ค๋น๋๋ฉด ์๋ํฌ์ธํธ์ ๋ชจ๋ธ์ ๋ฐฐํฌํฉ๋๋ค.
ENDPOINT_ID=$(gcloud ai endpoints list \
--region=LOCATION \
--filter=display_name=ENDPOINT_NAME \
--format="value(name)")
MODEL_ID=$(gcloud ai models list \
--region=LOCATION \
--filter=display_name=DEPLOYED_MODEL_NAME \
--format="value(name)")
gcloud ai endpoints deploy-model $ENDPOINT_ID \
--region=LOCATION \
--model=$MODEL_ID \
--display-name=DEPLOYED_MODEL_NAME \
--machine-type=ct5lp-hightpu-4t \
--traffic-split=0=100
๋ค์์ ๋ฐ๊ฟ๋๋ค.
Gemma 2B
๋ ๋ ์์ ct5lp-hightpu-1t ๋จธ์ ์ ๋ฐฐํฌํ ์ ์์ต๋๋ค. ์ด ๊ฒฝ์ฐ ๋ชจ๋ธ์ ์
๋ก๋ํ ๋ --platform_topology=1x1
์ ์ง์ ํด์ผ ํฉ๋๋ค.
Google Cloud CLI ๋๊ตฌ๋ก ๋ชจ๋ธ์ ์๋ํฌ์ธํธ์ ๋ฐฐํฌํ๋ ค๋ฉด ๋ช ๋ถ ์ ๋ ๊ฑธ๋ฆด ์ ์์ต๋๋ค. ๋ชจ๋ธ์ด ์ฑ๊ณต์ ์ผ๋ก ๋ฐฐํฌ๋๋ฉด ์ด ๋ช ๋ น์ด๊ฐ ๋ค์ ์ถ๋ ฅ์ ํ์ํฉ๋๋ค.
Deployed a model to the endpoint xxxxx. Id of the deployed model: xxxxx.
๋ฐฐํฌ๋ ๋ชจ๋ธ์์ ์จ๋ผ์ธ ์ถ๋ก ๊ฐ์ ธ์ค๊ธฐ
Vertex AI ์๋ํฌ์ธํธ๋ฅผ ํตํด ๋ชจ๋ธ์ ํธ์ถํ๋ ค๋ฉด ํ์ค ์ถ๋ก ์์ฒญ JSON ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ์ฌ ์ถ๋ก ์์ฒญ์ ํ์์ ์ง์ ํฉ๋๋ค.
๋ค์ ์์์์๋ gcloud ai endpoints predict
๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํฉ๋๋ค.
ENDPOINT_ID=$(gcloud ai endpoints list \
--region=LOCATION \
--filter=display_name=ENDPOINT_NAME \
--format="value(name)")
gcloud ai endpoints predict $ENDPOINT_ID \
--region=LOCATION \
--http-headers=Content-Type=application/json \
--json-request instances.json
๋ค์์ ๋ฐ๊ฟ๋๋ค.
์ญ์
Vertex AI ์๊ธ ๋ฐ Artifact Registry ์๊ธ์ด ๊ณ์ ์ฒญ๊ตฌ๋์ง ์๊ฒ ํ๋ ค๋ฉด ์ด ํํ ๋ฆฌ์ผ์์ ๋ง๋ Google Cloud ๋ฆฌ์์ค๋ฅผ ์ญ์ ํฉ๋๋ค.