調整語言基礎模型 (生成式 AI)
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[],[],null,["# Tune language foundation model (Generative AI)\n\nTune language foundation models with a tuning dataset.\n\nCode sample\n-----------\n\n### Java\n\n\nBefore trying this sample, follow the Java setup instructions in the\n[Vertex AI quickstart using\nclient libraries](/vertex-ai/docs/start/client-libraries).\n\n\nFor more information, see the\n[Vertex AI Java API\nreference documentation](/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1).\n\n\nTo authenticate to Vertex AI, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import com.google.cloud.aiplatform.v1.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.CreatePipelineJobRequest.html;\n import com.google.cloud.aiplatform.v1.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.LocationName.html;\n import com.google.cloud.aiplatform.v1.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineJob.html;\n import com.google.cloud.aiplatform.v1.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineJob.html.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineJob.RuntimeConfig.html;\n import com.google.cloud.aiplatform.v1.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineServiceClient.html;\n import com.google.cloud.aiplatform.v1.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineServiceSettings.html;\n import com.google.protobuf.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.Value.html;\n import java.io.IOException;\n import java.util.HashMap;\n import java.util.Map;\n\n public class CreatePipelineJobModelTuningSample {\n\n public static void main(String[] args) throws IOException {\n // TODO(developer): Replace these variables before running the sample.\n String project = \"PROJECT\";\n String location = \"europe-west4\"; // europe-west4 and us-central1 are the supported regions\n String pipelineJobDisplayName = \"PIPELINE_JOB_DISPLAY_NAME\";\n String modelDisplayName = \"MODEL_DISPLAY_NAME\";\n String outputDir = \"OUTPUT_DIR\";\n String datasetUri = \"DATASET_URI\";\n int trainingSteps = 300;\n\n createPipelineJobModelTuningSample(\n project,\n location,\n pipelineJobDisplayName,\n modelDisplayName,\n outputDir,\n datasetUri,\n trainingSteps);\n }\n\n // Create a model tuning job\n public static void createPipelineJobModelTuningSample(\n String project,\n String location,\n String pipelineJobDisplayName,\n String modelDisplayName,\n String outputDir,\n String datasetUri,\n int trainingSteps)\n throws IOException {\n final String endpoint = String.format(\"%s-aiplatform.googleapis.com:443\", location);\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineServiceSettings.html pipelineServiceSettings =\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineServiceSettings.html.newBuilder().setEndpoint(endpoint).build();\n\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests.\n try (https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineServiceClient.html client = https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineServiceClient.html.create(pipelineServiceSettings)) {\n Map\u003cString, Value\u003e parameterValues = new HashMap\u003c\u003e();\n parameterValues.put(\"project\", stringToValue(project));\n parameterValues.put(\"model_display_name\", stringToValue(modelDisplayName));\n parameterValues.put(\"dataset_uri\", stringToValue(datasetUri));\n parameterValues.put(\n \"location\",\n stringToValue(\n \"us-central1\")); // Deployment is only supported in us-central1 for Public Preview\n parameterValues.put(\"large_model_reference\", stringToValue(\"text-bison@001\"));\n parameterValues.put(\"train_steps\", numberToValue(trainingSteps));\n parameterValues.put(\"accelerator_type\", stringToValue(\"GPU\")); // Optional: GPU or TPU\n\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineJob.RuntimeConfig.html runtimeConfig =\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineJob.RuntimeConfig.html.newBuilder()\n .setGcsOutputDirectory(outputDir)\n .https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineJob.RuntimeConfig.Builder.html#com_google_cloud_aiplatform_v1_PipelineJob_RuntimeConfig_Builder_putAllParameterValues_java_util_Map_java_lang_String_com_google_protobuf_Value__(parameterValues)\n .build();\n\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineJob.html pipelineJob =\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineJob.html.newBuilder()\n .https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineJob.Builder.html#com_google_cloud_aiplatform_v1_PipelineJob_Builder_setTemplateUri_java_lang_String_(\n \"https://us-kfp.pkg.dev/ml-pipeline/large-language-model-pipelines/tune-large-model/v2.0.0\")\n .setDisplayName(pipelineJobDisplayName)\n .https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineJob.Builder.html#com_google_cloud_aiplatform_v1_PipelineJob_Builder_setRuntimeConfig_com_google_cloud_aiplatform_v1_PipelineJob_RuntimeConfig_(runtimeConfig)\n .build();\n\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.LocationName.html parent = https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.LocationName.html.of(project, location);\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.CreatePipelineJobRequest.html request =\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.CreatePipelineJobRequest.html.newBuilder()\n .setParent(parent.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.LocationName.html#com_google_cloud_aiplatform_v1_LocationName_toString__())\n .setPipelineJob(pipelineJob)\n .build();\n\n https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineJob.html response = client.createPipelineJob(request);\n System.out.format(\"response: %s\\n\", response);\n System.out.format(\"Name: %s\\n\", response.https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.PipelineJob.html#com_google_cloud_aiplatform_v1_PipelineJob_getName__());\n }\n }\n\n static https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.Value.html stringToValue(String str) {\n return https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.Value.html.newBuilder().setStringValue(str).build();\n }\n\n static https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.Value.html numberToValue(int n) {\n return https://cloud.google.com/java/docs/reference/google-cloud-aiplatform/latest/com.google.cloud.aiplatform.v1.Value.html.newBuilder().setNumberValue(n).build();\n }\n }\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=aiplatform)."]]