Adding MLFlow API for creating registered models

What does this MR do and why?

This MR adds the first MLFlow-compatible endpoints for the Registered Models API.

The Create RegisteredModel API accepts a name, descriptions and an array of tags which are key/value pairs. It returns a RegisteredModel object, or an error message if the validation fails.

The Get RegisteredModel API accepts a name and returns a RegisteredModel object, or an error message if the record is not found.

Example response payload:

{
  "name": "my-model-name",
  "creation_timestamp": "2023-10-17T18:26:55.556Z",
  "last_updated_timestamp": "2023-10-17T18:26:55.556Z",
  "description": "My Model Description",
  "user_id": "1",
  "tags": [
    {
      "key": "key1",
      "value": "value1"
    },
    {
      "key": "key2",
      "value": "value2"
    }
  ]
}

How to set up and validate locally

  1. In the Rails console, ensure the feature flag is enabled

    Feature.enable(:ml_experiment_tracking)
  2. Use the following cURL command to create a model in a local GDK project

    curl -X "POST" "http://GDKHOST/api/v4/projects/PROJECT_ID/ml/mlflow/api/2.0/mlflow/registered-models/create" \
        -H 'Authorization: Bearer PERSONAL_ACCESS_TOKEN' \
        -H 'Content-Type: application/json; charset=utf-8' \
        -d $'{
      "name": "my-model-name",
      "tags": [
        {
          "key": "key1",
          "value": "value1"
        },
        {
          "key": "key2",
          "value": "value2"
        }
      ],
      "description": "My Model Description"
    }'    
  3. Use the get API to look up the newly created entry.

    curl -X "GET" "http://GDKHOST/api/v4/projects/PROJECT_ID/ml/mlflow/api/2.0/mlflow/registered-models/get?name=my-model-name" \
        -H 'Authorization: Bearer PERSONAL_ACCESS_TOKEN'    

Database Review

Find Query

SELECT
  "ml_models".*
FROM
  "ml_models"
WHERE
  "ml_models"."project_id" = 37577134
  AND "ml_models"."name" = 'ml_experiment_4'
LIMIT
  1

Create Queries

Steps

  1. Find or create a model experiment
  2. Find or create a model
  3. Insert metadata records

Queries

  1. Look up existing model experiments

    SELECT
      1 AS one
    FROM
      "ml_experiments"
    WHERE
      "ml_experiments"."name" = 'my-experiment-name'
      AND "ml_experiments"."project_id" = 37577134
    LIMIT
      1

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/23291/commands/74953

  1. Insert new model experiment

    INSERT INTO
      "ml_experiments" (
        "created_at",
        "updated_at",
        "iid",
        "project_id",
        "name"
      )
    VALUES
      (
        '2023-10-19 20:54:35.627506',
        '2023-10-19 20:54:35.627506',
        99999,
        37577134,
        'my-experiment-name'
      ) RETURNING "id"

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/23291/commands/74954

  1. Look up existing model with given name

    SELECT
      "ml_models".*
    FROM
      "ml_models"
    WHERE
      "ml_models"."project_id" = 37577134
      AND "ml_models"."name" = 'ml_experiment_999'
    LIMIT
      1

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/23291/commands/74955

  1. Insert new model record

    INSERT INTO
      "ml_models" (
        "created_at",
        "updated_at",
        "project_id",
        "name",
        "user_id"
      )
    VALUES
      (
        '2023-10-19 20:54:35.645057',
        '2023-10-19 20:54:35.645057',
        37577134,
        'ml_experiment_999',
        1
      ) RETURNING "id"

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/23291/commands/74957

  1. Insert metadata entries

    INSERT INTO
      "ml_model_metadata" (
        "model_id",
        "name",
        "value",
        "created_at",
        "updated_at"
      )
    VALUES
      (
        13,
        'key1',
        'value1',
        CURRENT_TIMESTAMP,
        CURRENT_TIMESTAMP
      ),
      (
        13,
        'key2',
        'value2',
        CURRENT_TIMESTAMP,
        CURRENT_TIMESTAMP
      ) ON CONFLICT DO NOTHING

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Darby Frey

Merge request reports

Loading