|
| 1 | +/* |
| 2 | + * Copyright 2023 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +'use strict'; |
| 18 | + |
| 19 | +async function main( |
| 20 | + project, |
| 21 | + pipelineJobId, |
| 22 | + modelDisplayName, |
| 23 | + gcsOutputDirectory, |
| 24 | + location = 'europe-west4', |
| 25 | + datasetUri = 'gs://cloud-samples-data/ai-platform/generative_ai/sql_create_context.jsonl', |
| 26 | + trainSteps = 300 |
| 27 | +) { |
| 28 | + // [START aiplatform_genai_code_model_tuning] |
| 29 | + /** |
| 30 | + * TODO(developer): Uncomment these variables before running the sample.\ |
| 31 | + * (Not necessary if passing values as arguments) |
| 32 | + */ |
| 33 | + // const project = 'YOUR_PROJECT_ID'; |
| 34 | + // const location = 'YOUR_PROJECT_LOCATION'; |
| 35 | + const aiplatform = require('@google-cloud/aiplatform'); |
| 36 | + const {PipelineServiceClient} = aiplatform.v1; |
| 37 | + |
| 38 | + // Import the helper module for converting arbitrary protobuf.Value objects. |
| 39 | + const {helpers} = aiplatform; |
| 40 | + |
| 41 | + // Specifies the location of the api endpoint |
| 42 | + const clientOptions = { |
| 43 | + apiEndpoint: `${location}-aiplatform.googleapis.com`, |
| 44 | + }; |
| 45 | + const model = 'code-bison@001'; |
| 46 | + |
| 47 | + const pipelineClient = new PipelineServiceClient(clientOptions); |
| 48 | + |
| 49 | + async function tuneLLM() { |
| 50 | + // Configure the parent resource |
| 51 | + const parent = `projects/${project}/locations/${location}`; |
| 52 | + |
| 53 | + const parameters = { |
| 54 | + train_steps: helpers.toValue(trainSteps), |
| 55 | + project: helpers.toValue(project), |
| 56 | + location: helpers.toValue('us-central1'), |
| 57 | + dataset_uri: helpers.toValue(datasetUri), |
| 58 | + large_model_reference: helpers.toValue(model), |
| 59 | + model_display_name: helpers.toValue(modelDisplayName), |
| 60 | + }; |
| 61 | + |
| 62 | + const runtimeConfig = { |
| 63 | + gcsOutputDirectory, |
| 64 | + parameterValues: parameters, |
| 65 | + }; |
| 66 | + |
| 67 | + const pipelineJob = { |
| 68 | + templateUri: |
| 69 | + 'https://us-kfp.pkg.dev/ml-pipeline/large-language-model-pipelines/tune-large-model/v3.0.0', |
| 70 | + displayName: 'my-tuning-job', |
| 71 | + runtimeConfig, |
| 72 | + }; |
| 73 | + |
| 74 | + const createPipelineRequest = { |
| 75 | + parent, |
| 76 | + pipelineJob, |
| 77 | + pipelineJobId, |
| 78 | + }; |
| 79 | + |
| 80 | + const [response] = await pipelineClient.createPipelineJob( |
| 81 | + createPipelineRequest |
| 82 | + ); |
| 83 | + |
| 84 | + console.log('Tuning pipeline job:'); |
| 85 | + console.log(`\tName: ${response.name}`); |
| 86 | + console.log( |
| 87 | + `\tCreate time: ${new Date(1970, 0, 1) |
| 88 | + .setSeconds(response.createTime.seconds) |
| 89 | + .toLocaleString()}` |
| 90 | + ); |
| 91 | + console.log(`\tStatus: ${response.status}`); |
| 92 | + } |
| 93 | + |
| 94 | + await tuneLLM(); |
| 95 | + // [END aiplatform_genai_code_model_tuning] |
| 96 | +} |
| 97 | + |
| 98 | +exports.tuneModel = main; |
0 commit comments