Tune language foundation model (Generative AI)

Tune language foundation models with a tuning dataset.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample


Before trying this sample, follow the Node.js setup instructions in the Vertex AI quickstart using client libraries. For more information, see the Vertex AI Node.js API reference documentation.

To authenticate to Vertex AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

 * TODO(developer): Uncomment these variables before running the sample.\
 * (Not necessary if passing values as arguments)
// const project = 'YOUR_PROJECT_ID';
// const location = 'YOUR_PROJECT_LOCATION';
const aiplatform = require('@google-cloud/aiplatform');
const {PipelineServiceClient} = aiplatform.v1;

// Import the helper module for converting arbitrary protobuf.Value objects.
const {helpers} = aiplatform;

// Specifies the location of the api endpoint
const clientOptions = {
  apiEndpoint: 'europe-west4-aiplatform.googleapis.com',
const model = 'text-bison@001';

const pipelineClient = new PipelineServiceClient(clientOptions);

async function tuneLLM() {
  // Configure the parent resource
  const parent = `projects/${project}/locations/${location}`;

  const parameters = {
    train_steps: helpers.toValue(trainSteps),
    project: helpers.toValue(project),
    location: helpers.toValue('us-central1'),
    dataset_uri: helpers.toValue(datasetUri),
    large_model_reference: helpers.toValue(model),
    model_display_name: helpers.toValue(modelDisplayName),
    accelerator_type: helpers.toValue('GPU'), // Optional: GPU or TPU

  const runtimeConfig = {
    parameterValues: parameters,

  const pipelineJob = {
    displayName: 'my-tuning-job',

  const createPipelineRequest = {
  await new Promise((resolve, reject) => {
      response => resolve(response),
      e => reject(e)
  }).then(response => {
    const [result] = response;
    console.log('Tuning pipeline job:');
    console.log(`\tName: ${result.name}`);
      `\tCreate time: ${new Date(1970, 0, 1)
    console.log(`\tStatus: ${result.status}`);

await tuneLLM();

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.