How do I get a model id in a a Vertex AI pipeline?

674 Views Asked by At

Part of my pipeline:

    training_op = gcc_aip.AutoMLTabularTrainingJobRunOp(
        project=project,
        display_name=display_name,
        optimization_prediction_type="classification",
        budget_milli_node_hours=1000,
        column_transformations=[ ... ],
        dataset=dataset_create_op.outputs["dataset"],
        target_column="Class",
    )
    model_to_evaluate= training_op.outputs["model"]

    model_id=model_to_evaluate.name

This works except model_id is set to 'model'. I want the underlying model id ie the bit at the end of a model's resource name:

model_resource_name= f'projects/{PROJECT}/locations/{LOCATION}/models/{model_id}'
1

There are 1 best solutions below

0
chesu On

What you're looking for is available in the metadata of the model artifact, with key name resourceName. Try model_to_evaluate.metadata['resourceName'].

You can also parse model_to_evalue.uri to get the model id. The URI is in format https://{LOCATION}-aiplatform.googleapis.com/v1/projects/{PROJECT}/locations/{LOCATION}/models/{model_id}