Tune a pre-trained code generation model.

## Code sample

### Python


Before trying this sample, follow the Python setup instructions in the
[Vertex AI quickstart using
client libraries](https://docs.cloud.google.com/vertex-ai/docs/start/client-libraries).


For more information, see the
[Vertex AI Python API
reference documentation](https://docs.cloud.google.com/python/docs/reference/aiplatform/latest).


To authenticate to Vertex AI, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    from __future__ import annotations

    import os

    import https://docs.cloud.google.com/python/docs/reference/vertexai/latest
    from vertexai.language_models import CodeGenerationModel

    PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")


    def tune_code_generation_model() -> CodeGenerationModel:
        # Initialize Vertex AI
        https://docs.cloud.google.com/python/docs/reference/vertexai/latest.init(project=PROJECT_ID, location="us-central1")

        model = CodeGenerationModel.from_pretrained("code-bison@002")

        # TODO(developer): Update the training data path
        tuning_job = model.tune_model(
            training_data="gs://cloud-samples-data/ai-platform/generative_ai/headline_classification.jsonl",
            tuning_job_location="europe-west4",
            tuned_model_location="us-central1",
        )

        print(tuning_job._status)
        # Example response:
        # ...
        # pipeline_job = aiplatform.PipelineJob.get('projects/1234567890/locations/europe-west4/pipelineJobs/tune...
        # PipelineState.PIPELINE_STATE_PENDING
        return model

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples?product=generativeaionvertexai).