일괄 텍스트 생성 가져오기

일괄 예측은 지연 시간에 민감하지 않은 다수의 텍스트 프롬프트 요청을 효율적으로 전송하기 위한 방법입니다. 한 번에 입력 요청 하나로 제한되는 온라인 예측과 달리 단일 일괄 요청에서 다수의 LLM 요청을 전송할 수 있습니다. Vertex AI의 테이블 형식 데이터에 대해 일괄 예측을 수행하는 방법과 마찬가지로 출력 위치를 결정하고 입력 프롬프트를 추가하면 응답이 출력 위치에 비동기식으로 채워집니다.

텍스트 모델에 대한 일괄 요청을 제출하고 결과를 검토한 후 모델 조정을 통해 모델을 조정할 수 있습니다. 조정 후 평소와 같이 일괄 생성을 위해 업데이트된 모델을 제출할 수 있습니다. 모델 조정에 대한 자세한 내용은 기반 모델 조정을 참조하세요.

일괄 예측을 지원하는 텍스트 모델

  • text-bison

입력 준비

일괄 요청의 입력은 일괄 생성을 위해 모델에 보낼 항목을 지정합니다. 모델에 텍스트 분류를 사용하는 경우 JSON Lines 파일 또는 BigQuery 테이블을 사용하여 입력 목록을 지정할 수 있습니다. BigQuery 테이블을 BigQuery에 저장하고 JSON Lines 파일을 Cloud Storage에 저장합니다.

텍스트 모델에 대한 일괄 요청은 BigQuery 스토리지 소스 및 Cloud Storage만 허용합니다. 요청에는 프롬프트가 최대 30,000개까지 포함될 수 있습니다.

형식 지정에 대한 자세한 내용은 다음을 참조하세요.

JSONL 예시

JSONL 입력 형식

{"prompt":"Give a short description of a machine learning model:"}
{"prompt":"Best recipe for banana bread:"}

JSONL 출력

{"instance":{"prompt":"Give..."},"predictions": [{"content":"A machine","safetyAttributes":{...}}],"status":""}
{"instance":{"prompt":"Best..."},"predictions": [{"content":"Sure", "safetyAttributes":{...}}],"status":""}

BigQuery 예시

BigQuery 입력 형식

이 예시에서는 단일 열 BigQuery 테이블을 보여줍니다.

프롬프트
'머신러닝 모델에 대한 간단한 설명을 제공하세요.'
'최고의 바나나 빵 레시피:'

BigQuery 출력

프롬프트 예측 상태
'머신러닝 모델에 대한 간단한 설명을 제공하세요.'

'[{
   "content": "A machine learning model is a
               statistical method",
   "safetyAttributes": {
     "blocked": false,
     "scores": [
       0.10000000149011612
     ],
     "categories": [
       "Violent"
     ]
   }
 }]'
 
'최고의 바나나 빵 레시피:'

'[{"content": "Sure, here is a recipe for banana
               bread:\n\nIngredients:\n\n*",
   "safetyAttributes": {
     "scores": [
       0.10000000149011612
     ],
     "blocked": false,
     "categories": [
       "Violent"
     ]
   }
}]'

일괄 응답 요청

제출한 입력 항목 수에 따라 일괄 생성 태스크를 완료하는 데 다소 시간이 걸릴 수 있습니다.

REST

Vertex AI API를 사용하여 텍스트 프롬프트를 테스트하려면 POST 요청을 게시자 모델 엔드포인트로 전송합니다.

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • PROJECT_ID: Google Cloud 프로젝트 이름
  • BP_JOB_NAME: 작업 이름
  • MODEL_PARAM: 모델 매개변수의 맵. 허용되는 매개변수로는 maxOutputTokens, topK, topP, temperature가 있습니다.
  • INPUT_URI: 입력 소스 URI. 이는 BigQuery 테이블 URI 또는 Cloud Storage의 JSONL 파일 URI입니다.
  • OUTPUT_URI: 출력 대상 URI입니다.

HTTP 메서드 및 URL:

POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/batchPredictionJobs

JSON 요청 본문:

{
    "name": "BP_JOB_NAME",
    "displayName": "BP_JOB_NAME",
    "model": "publishers/google/models/text-bison",
    "model_parameters": "MODEL_PARAM"
    "inputConfig": {
      "instancesFormat":"bigquery",
      "bigquerySource":{
        "inputUri" : "INPUT_URI"
      }
    },
    "outputConfig": {
      "predictionsFormat":"bigquery",
      "bigqueryDestination":{
        "outputUri": "OUTPUT_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://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/batchPredictionJobs"

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://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/batchPredictionJobs" | Select-Object -Expand Content

다음과 비슷한 JSON 응답이 표시됩니다.

{
  "name": "projects/{PROJECT_ID}/locations/us-central1/batchPredictionJobs/{BATCH_JOB_ID}",
  "displayName": "BP_sample_publisher_BQ_20230712_134650",
  "model": "projects/{PROJECT_ID}/locations/us-central1/models/text-bison",
  "inputConfig": {
    "instancesFormat": "bigquery",
    "bigquerySource": {
      "inputUri": "bq://sample.text_input"
    }
  },
  "modelParameters": {},
  "outputConfig": {
    "predictionsFormat": "bigquery",
    "bigqueryDestination": {
      "outputUri": "bq://sample.llm_dataset.embedding_out_BP_sample_publisher_BQ_20230712_134650"
    }
  },
  "state": "JOB_STATE_PENDING",
  "createTime": "2023-07-12T20:46:52.148717Z",
  "updateTime": "2023-07-12T20:46:52.148717Z",
  "labels": {
    "owner": "sample_owner",
    "product": "llm"
  },
  "modelVersionId": "1",
  "modelMonitoringStatus": {}
}

응답에는 일괄 작업의 고유 식별자가 포함됩니다. 작업 stateJOB_STATE_SUCCEEDED가 될 때까지 BATCH_JOB_ID를 사용하여 일괄 작업의 상태를 폴링할 수 있습니다. 예를 들면 다음과 같습니다.

curl \
  -X GET \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/batchPredictionJobs/BATCH_JOB_ID

Python

Python을 설치하거나 업데이트하는 방법은 Python용 Vertex AI SDK 설치를 참조하세요. 자세한 내용은 Python API 참고 문서를 참조하세요.

from vertexai.preview.language_models import TextGenerationModel
text_model = TextGenerationModel.from_pretrained("text-bison")
batch_prediction_job = text_model.batch_predict(
  source_uri=["gs://BUCKET_NAME/test_table.jsonl"],
  destination_uri_prefix="gs://BUCKET_NAME/tmp/2023-05-25-vertex-LLM-Batch-Prediction/result3",
  # Optional:
  model_parameters={
      "maxOutputTokens": "200",
      "temperature": "0.2",
      "topP": "0.95",
      "topK": "40",
  },
)
print(batch_prediction_job.display_name)
print(batch_prediction_job.resource_name)
print(batch_prediction_job.state)

일괄 출력 검색

일괄 예측 태스크가 완료되면 출력은 요청에 지정한 Cloud Storage 버킷이나 BigQuery 테이블에 저장됩니다.

다음 단계