모델 조정을 사용하면 해당 태스크 또는 동작을 보여주는 많은 예시를 모델에 제공하여 특정 태스크에 대한 모델 성능 또는 원하는 동작을 향상시킬 수 있습니다. 모델이 특정 동작 또는 틈새 항목을 학습하도록 하려면 조정이 필요합니다. 자세한 내용은 모델 조정 사용 시나리오를 참조하세요.
모델 조정 데이터 세트 준비
데이터 세트에는 모델로 수행하려는 태스크와 일치하는 예시가 10개 이상 포함되어야 합니다. 더 나은 결과를 얻으려면 최소 100개 이상의 예시가 권장됩니다. 자세한 내용은 모델 조정 데이터 세트 준비를 참조하세요.
이 예시는 샘플 데이터 세트로 사용될 수 있습니다.
{"input_text": "question: How many people live in Beijing? context: With over 21 million residents, Beijing is the world's most populous national capital city and is China's second largest city after Shanghai. It is located in Northern China, and is governed as a municipality under the direct administration of the State Council with 16 urban, suburban, and rural districts.[14] Beijing is mostly surrounded by Hebei Province with the exception of neighboring Tianjin to the southeast; together, the three divisions form the Jingjinji megalopolis and the national capital region of China.", "output_text": "over 21 million people"}
{"input_text": "question: How many parishes are there in Louisiana? context: The U.S. state of Louisiana is divided into 64 parishes (French: paroisses) in the same manner that 48 other states of the United States are divided into counties, and Alaska is divided into boroughs.", "output_text": "64"}
{"input_text": "question: How many churches in Texas? context: In 2010, there were a number of religious congregations in the state of Texas.", "output_text": "27,848"}
{"input_text": "question: How many lakes in North Dakota? context: North Dakota has many lakes and rivers offering exciting action for walleye, northern pike, perch, bass, salmon, catfish and other game fish with seasons for most species open year-round.", "output_text": "400"}
{"input_text": "question: How many rivers in the United States? context: The United States of America has over 250,000 rivers, with a total of about 3,500,000 miles of rivers. The longest river in the USA is the Missouri River (it is a tributary of the Mississippi River and is 2,540 miles long), but the biggest in terms of water volume is the deeper Mississippi River", "output_text": "over 250,000"}
{"input_text": "question: How many mountains in Oregon? context: There are 4760 named mountain ranges in Oregon and approximately 3,764 mountains altogether.", "output_text": "3,764"}
{"input_text": "question: How many small businesses in the state of Vermont? context: Vermont has 78,883 small businesses, most of which are sole proprietors. Vermont small businesses employ 157,131 workers, which is 60.2% of the state's workforce. The top three industries for small business in Vermont are professional, scientific, and technical services; construction; and retail.", "output_text": "78,883"}
{"input_text": "question: How many states grow apples? context: 2,500 varieties of apples are grown in the United States. 7,500 varieties of apples are grown throughout the world. 100 varieties of apples are grown commercially in the United States. Apples are grown commercially in 36 states.", "output_text": "36"}
{"input_text": "question: How many states grow mangos? context: Because mangos need a tropical climate to flourish, only Florida, California, Hawaii, and Puerto Rico grow mangos.", "output_text": "4"}
{"input_text": "question: How often does it storm in Missouri? context: Thunderstorms normally occur between 40 and 50 days per year. During any year, there are usually a few of these thunderstorms that are severe, and produce large hail and damaging winds. Tornadoes have produced extensive damage and loss of life in the St. Louis area.", "output_text": "Thunderstorms normally occur between 40 and 50 days per year."}
Cloud Storage 버킷에 데이터 세트 업로드
다음 단계에 따라 데이터 세트를 업로드합니다.
새 Cloud Storage 버킷을 만들거나 기존 버킷을 사용하여 데이터 세트 파일을 저장합니다. 버킷의 리전은 중요하지 않지만 모델 조정을 실행하려는 동일한 Google Cloud 프로젝트에 있는 버킷을 사용하는 것이 좋습니다.
버킷이 준비되면 데이터 세트 파일을 버킷에 업로드합니다.
모델 조정 작업 만들기
탭을 선택하고 안내에 따라 샘플을 실행합니다.
REST
모델 조정 작업을 만들려면 pipelineJobs 메서드를 사용하여 POST 요청을 전송합니다.
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- PIPELINEJOB_DISPLAYNAME: pipelineJob의 표시 이름입니다.
- OUTPUT_DIR: 파이프라인 아티팩트를 출력할 버킷의 URI입니다.
- PROJECT_ID: 프로젝트 ID
- MODEL_DISPLAYNAME: pipelineJob에서 업로드(생성)한 모델의 표시 이름입니다.
- DATASET_URI: 데이터 세트 파일의 URI입니다.
- PIPELINE_JOB_REGION: 파이프라인 조정 작업이 실행되는 리전입니다. 또한 조정된 모델이 업로드되는 기본 리전입니다. 모델을 다른 리전에 업로드하려면
location
매개변수를 사용하여 조정된 모델 업로드 리전을 지정합니다. 자세한 내용은 모델 업로드 리전을 참조하세요. - MODEL_UPLOAD_REGION: (선택사항) 조정된 모델이 업로드된 리전입니다. 모델 업로드 리전을 지정하지 않으면 조정된 모델이 파이프라인 작업이 실행되는 동일한 리전에 업로드됩니다. 자세한 내용은 모델 업로드 리전을 참조하세요.
- ACCELERATOR_TYPE: (선택사항, 기본값
GPU
) 모델 조정에 사용할 가속기 유형입니다. 유효한 옵션은 다음과 같습니다.GPU
: 조정에 8개의 A100 80GB GPU를 사용합니다. 할당량이 충분한지 확인합니다.GPU
를 선택하면 VPC-SC가 지원됩니다. CMEK는 조정 위치 및 모델 업로드 위치가us-centra1
일 때 지원됩니다. 자세한 내용은 지도 조정 리전 설정을 참조하세요.GPU
를 선택하면 모델 조정 계산이us-central1
리전에서 수행됩니다.TPU
: 조정에 TPU v3 포드 코어 64개를 사용합니다. 할당량이 충분한지 확인합니다. CMEK는 지원되지 않지만 VPC-SC가 지원됩니다.TPU
를 선택하면 모델 조정 계산이europe-west4
리전에서 수행됩니다.
- LARGE_MODEL_REFERENCE: 조정할 기반 모델의 이름입니다. 옵션은 다음과 같습니다.
text-bison@002
chat-bison@002
- DEFAULT_CONTEXT (chat only): 조정 데이터 세트의 모든 미세 조정 예시에 적용되는 컨텍스트입니다. 예시에서
context
필드를 설정하면 기본 컨텍스트가 재정의됩니다. - STEPS: 모델 조정을 위해 실행할 단계 수입니다. 기본값은 300입니다. 배치 크기는 조정 위치 및 모델 크기에 따라 달라집니다.
text-bison@002
,chat-bison@002
,code-bison@002
,codechat-bison@002
와 같은 8k 모델의 경우:us-central1
의 배치 크기는 8입니다.europe-west4
의 배치 크기는 24입니다.
text-bison-32k
,chat-bison-32k
,code-bison-32k
,codechat-bison-32k
와 같은 32k 모델의 경우:us-central1
의 배치 크기는 8입니다.europe-west4
의 배치 크기는 8입니다.
예를 들어
europe-west4
에서text-bison@002
를 학습시키는 경우, 학습 데이터 세트에 240개의 예시가 있고,steps
를 20으로 설정하면 학습 예시 수는 20단계와 배치 크기 24의 곱으로, 480개의 학습 단계가 됩니다. 이 경우 예시가 두 번 진행되므로 학습 프로세스에 2세대가 있습니다.us-central1
에서 학습 데이터 세트에 240개의 예시가 있고steps
를 15로 설정하는 경우, 학습 예시의 수는 15 단계와 배치 크기 8의 곱으로, 120개의 학습 단계가 됩니다. 이 경우에는 학습 단계가 예시의 절반이므로 0.5세대가 있습니다. - LEARNING_RATE_MULTIPLIER: 권장 학습률에 적용할 배수입니다. 권장 학습률을 사용하려면
1.0
을 사용합니다. - EVAL_DATASET_URI (text only): (선택사항) 일괄 예측 및 평가를 위한 평가 데이터 세트가 포함된 JSONL 파일의 URI입니다.
chat-bison
에는 평가가 지원되지 않습니다. 자세한 내용은 코드 모델 조정을 위한 데이터 세트 형식을 참조하세요. 평가 데이터 세트에는 10~250개 사이의 예시가 필요합니다. - EVAL_INTERVAL (text only): (선택사항, 기본값
20
) 각 평가 사이의 조정 단계 수입니다. 채팅 모델에는 평가 간격이 지원되지 않습니다. 평가가 전체 평가 데이터 세트에서 실행되므로 평가 간격이 좁을수록 조정 시간이 더 길어집니다. 예를 들어steps
가 200이고EVAL_INTERVAL
이 100인 경우에는 평가 측정항목에 데이터 포인트가 2개만 사용됩니다. 이 매개변수를 사용하려면evaluation_data_uri
를 설정해야 합니다. - ENABLE_EARLY_STOPPING (text only): (선택사항, 기본값
true
)true
로 설정된 경우 예측 토큰의 정확도로 측정되는 모델 성능이 평가 실행 사이에 충분히 향상되지 않을 경우 모든 조정 단계를 완료하기 전에 조정을 중지하는boolean
입니다.false
이면 모든 조정 단계가 완료될 때까지 조정이 계속됩니다. 이 매개변수를 사용하려면evaluation_data_uri
를 설정해야 합니다. 채팅 모델에는 조기 중단 사용 설정이 지원되지 않습니다. - TENSORBOARD_RESOURCE_ID: (선택사항) Vertex AI 텐서보드 인스턴스의 ID입니다. Vertex AI 텐서보드 인스턴스는 조정 작업이 완료된 후 실험을 만드는 데 사용됩니다. Vertex AI 텐서보드 인스턴스는 조정 파이프라인과 동일한 리전에 있어야 합니다.
- ENCRYPTION_KEY_NAME: (선택사항) 데이터 암호화에 사용할 고객 관리 암호화 키(CMEK)의 정규화된 이름입니다.
us-central1
에서만 CMEK를 사용할 수 있습니다.us-central1
을 사용하고 CMEK를 지정하지 않으면 Google 관리 암호화 키가 사용됩니다. 기본적으로 Google 관리 암호화 키는 다른 모든 사용 가능한 리전에서 사용됩니다. 자세한 내용은 CMEK 개요를 참조하세요. - TEMPLATE_URI: 사용할 조정 템플릿은 조정 중인 모델에 따라 달라집니다.
- 텍스트 모델:
https://us-kfp.pkg.dev/ml-pipeline/large-language-model-pipelines/tune-large-model/v2.0.0
- 채팅 모델:
https://us-kfp.pkg.dev/ml-pipeline/large-language-model-pipelines/tune-large-chat-model/v3.0.0
- 텍스트 모델:
- SERVICE_ACCOUNT: (선택사항) Vertex AI가 파이프라인 작업을 실행하는 데 사용하는 서비스 계정입니다. 기본적으로 프로젝트의 Compute Engine 기본 서비스 계정(
PROJECT_NUMBER‑compute@developer.gserviceaccount.com
)이 사용됩니다. 커스텀 서비스 계정 연결에 대해 자세히 알아보세요.
HTTP 메서드 및 URL:
POST https://PIPELINE_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/PIPELINE_JOB_REGION/pipelineJobs
JSON 요청 본문:
{ "displayName": "PIPELINEJOB_DISPLAYNAME", "runtimeConfig": { "gcsOutputDirectory": "gs://OUTPUT_DIR", "parameterValues": { "project": "PROJECT_ID", "model_display_name": "MODEL_DISPLAYNAME", "dataset_uri": "gs://DATASET_URI", "location": "MODEL_UPLOAD_REGION", "accelerator_type": "ACCELERATOR_TYPE", "large_model_reference": "LARGE_MODEL_REFERENCE", "default_context": "DEFAULT_CONTEXT (chat only)", "train_steps": STEPS, "learning_rate_multiplier": LEARNING_RATE_MULTIPLIER, "evaluation_data_uri": "gs://EVAL_DATASET_URI (text only)", "evaluation_interval": EVAL_INTERVAL (text only), "enable_early_stopping": ENABLE_EARLY_STOPPING (text only), "enable_checkpoint_selection": "ENABLE_CHECKPOINT_SELECTION (text only)", "tensorboard_resource_id": "TENSORBOARD_ID", "encryption_spec_key_name": "ENCRYPTION_KEY_NAME" } }, "encryptionSpec": { "kmsKeyName": "ENCRYPTION_KEY_NAME" }, "serviceAccount": "SERVICE_ACCOUNT", "templateUri": "TEMPLATE_URI" }
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://PIPELINE_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/PIPELINE_JOB_REGION/pipelineJobs"
PowerShell
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://PIPELINE_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/PIPELINE_JOB_REGION/pipelineJobs" | Select-Object -Expand Content
다음과 비슷한 JSON 응답이 수신됩니다. pipelineSpec
는 공간 절약을 위해 잘렸습니다.
Python
Python을 설치하거나 업데이트하는 방법은 Python용 Vertex AI SDK 설치를 참조하세요. 자세한 내용은 Python API 참고 문서를 참조하세요.
Node.js
이 샘플을 사용해 보기 전에 Vertex AI 빠른 시작: 클라이언트 라이브러리 사용의 Node.js 설정 안내를 따르세요. 자세한 내용은 Vertex AI Node.js API 참고 문서를 참조하세요.
Vertex AI에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
Java
이 샘플을 사용해 보기 전에 Vertex AI 빠른 시작: 클라이언트 라이브러리 사용의 Java 설정 안내를 따르세요. 자세한 내용은 Vertex AI Java API 참고 문서를 참조하세요.
Vertex AI에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
Console
Google Cloud 콘솔을 사용하여 모델 조정 작업을 만들려면 다음 단계를 수행합니다.
- Google Cloud 콘솔의 Vertex AI 섹션에서 Vertex AI 스튜디오 페이지로 이동합니다.
- 조정 탭을 클릭합니다.
- 조정된 모델 만들기를 클릭합니다.
- 다음과 같이 조정 데이터 세트를 업로드하거나 지정합니다.
- 데이터 세트 파일을 업로드하려면
JSONL 파일 업로드
- JSONL 파일 선택 텍스트 상자에서 찾아보기를 클릭하고 데이터 세트 파일을 선택합니다.
- Cloud Storage 위치 텍스트 상자에서 찾아보기를 클릭하고 데이터 세트 파일을 저장할 Cloud Storage 버킷을 선택합니다.
기존 Cloud Storage 파일
Cloud Storage 경로 텍스트 상자에서 찾아보기를 클릭하고 데이터 세트 파일이 있는 Cloud Storage 버킷을 선택합니다.
JSONL 파일 업로드를 선택합니다. 데이터 세트 파일이 이미 Cloud Storage 버킷에 있으면 기존 Cloud Storage 파일을 선택합니다.
- 데이터 세트 파일을 업로드하려면
- 계속을 클릭합니다.
- 모델 세부정보를 다음과 같이 구성합니다.
- 모델 이름: 조정된 모델의 이름을 입력합니다.
- 기본 모델: 조정하려는 기반 모델을 선택합니다.
- 학습 단계: 모델 조정을 위해 실행할 단계 수를 입력합니다.
배치 크기는 조정 위치에 따라 달라집니다.
us-central1
의 배치 크기는 8입니다.europe-west4
의 배치 크기는 24입니다.
학습 데이터 세트에 240개의 예시가 있으면
europe-west4
에서 전체 데이터 세트를 한 번 처리하는 데 240/24 = 10단계가 걸립니다.us-central1
에서는 전체 데이터 세트를 한 번 처리하는 데 240/8 = 30단계가 걸립니다. - 학습률 배수: 권장 학습률에 적용할 배수를 입력합니다. 권장 학습률을 사용하려면
1.0
을 입력합니다. - 작업 디렉터리: 조정된 모델을 저장할 버킷의 URI를 입력합니다.
- 리전: 미세 조정을 수행할 리전을 입력합니다. 지원되는 리전은 다음과 같습니다.
- 조정 시작을 클릭합니다.
curl 명령어 예시
PROJECT_ID=myproject
DATASET_URI=gs://my-gcs-bucket-uri/dataset
OUTPUT_DIR=gs://my-gcs-bucket-uri/output
curl \
-X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
"https://europe-west4-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/europe-west4/pipelineJobs?pipelineJobId=tune-large-model-$(date +%Y%m%d%H%M%S)" -d \
$'{
"displayName": "tune-llm",
"runtimeConfig": {
"gcsOutputDirectory": "'${OUTPUT_DIR}'",
"parameterValues": {
"project": "'${PROJECT_ID}'",
"model_display_name": "The display name for your model in the UI",
"dataset_uri": "'${DATASET_URI}'",
"location": "us-central1",
"large_model_reference": "text-bison@001",
"train_steps": 300,
"learning_rate_multiplier": 1.0
}
},
"templateUri": "https://us-kfp.pkg.dev/ml-pipeline/large-language-model-pipelines/tune-large-model/v2.0.0"
}'
다음 단계
- 텍스트 프롬프트 및 텍스트 채팅 프롬프트 설계 알아보기
- Vertex AI Studio에서 프롬프트 테스트 방법 알아보기
- 텍스트 임베딩 알아보기
- 책임감 있는 AI 권장사항 및 Vertex AI 안전 필터 알아보기