Tutorial | Surface external models within Dataiku#

Background#

Watch the featurette

Often, an organization employs a variety of tools and architectures in its technological schema. For instance, organizations commonly work with different tools for model training and deployment.

Fortunately, an organization that trains and deploys models outside of Dataiku can benefit from Dataiku’s flexible MLOps offering by “hopping on or off” at a number of different integration points.

This tutorial will review an integration that lets you take a model deployed on a cloud ML platform and surface it within Dataiku as an external model.

Slide of Dataiku's MLOps approach.

Objectives#

In this tutorial, you will:

  • Surface within Dataiku a model externally deployed on a cloud ML platform.

  • Use that external model for explainability reports, comparisons with other types of models in Dataiku, and scoring data.

Prerequisites#

Completing the setup for this tutorial requires the assistance of your instance administrator and knowledge of the security and configuration of your cloud ML platform.

Before beginning this tutorial, you’ll need to:

  • Have access to an instance of Dataiku (version 12.2 or above).

  • Have an active deployed endpoint in either Amazon SageMaker, Azure Machine Learning, or Google Vertex AI. We’ll point to external resources for creating a sample endpoint in each case. Unrelated to Dataiku, you may need certain knowledge or rights to complete these tutorials.

  • Have an instance administrator create the external models code environment in the Administration > Settings > Misc section, as noted in the reference documentation.

  • Grant permissions to Dataiku to access your external endpoint. This may not be granted to your current instance as it relates to specific scope rights. We will specify the minimum required permissions to the extent possible.

  • Have an instance administrator create a dedicated connection to your cloud ML platform.

Create the project#

To get started, you can import a Dataiku project including many of the starter objects for your chosen cloud ML platform.

  1. From the Dataiku Design homepage, click +New Project > DSS tutorials > MLOps Practitioner > External Models.

Note

You can also download the starter project from this website and import it as a zip file.

Deploy a working external endpoint#

Before you can surface an external model in Dataiku, you need an endpoint running in your cloud ML platform. In each case, we have created an example endpoint following the cloud ML platform’s documentation.


  1. Create an Amazon SageMaker endpoint by following their tutorial on customer churn prediction with XGBoost.

When finished, you should be able to get predictions, such as:

dummy = "5,0,12.524227291335833,2,5.639471129269478,5,4.937219265876419,150,5.881787271425925,5,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0"
dummy_ar = np.fromstring(dummy, sep=',')
predictions = predict(dummy_ar)
print(predictions)

It should print something like:

['0.9981379508972168']

  1. Create an Azure Machine Learning endpoint by following their tutorial on deploying a model to predict credit card defaults as an online endpoint.

When finished, this code block from the tutorial should return '[1,0]'.

# test the blue deployment with the sample data
ml_client.online_endpoints.invoke(
    endpoint_name=online_endpoint_name,
    deployment_name="blue",
    request_file="./deploy/sample-request.json",
)

  1. Create a Google Vertex AI endpoint by following their tutorial on AutoML tabular training and prediction.

When finished, you should be able to get predictions, such as:

prediction = endpoint.predict(
    [
        {
            "Type": "Cat",
            "Age": "3",
            "Breed1": "Tabby",
            "Gender": "Male",
            "Color1": "Black",
            "Color2": "White",
            "MaturitySize": "Small",
            "FurLength": "Short",
            "Vaccinated": "No",
            "Sterilized": "No",
            "Health": "Healthy",
            "Fee": "100",
            "PhotoAmt": "2",
        }
    ]
)

print(prediction)

It should print something like:

Prediction(predictions=[
    {'classes': ['Yes', 'No'],
    'scores': [0.6285621523857117, 0.3714377582073212]
    }],
    ...
)

Create a connection in Dataiku to access the external endpoint#

After confirming that you have an endpoint running in your cloud ML platform, the next step is to create a connection in Dataiku with sufficient credentials to access the endpoint.

Important

Creating the connection requires administrative access. However, once the connection is created, other users only require the security setting Details readable by to access it.

  1. From the Applications menu of the Design node, click Administration.

  2. Navigate to the Connections tab.

  3. Click + New Connection.

  4. Choose your cloud ML platform from the Managed Model Deployment Infrastructures section.


  1. Provide any name, such as sagemaker-ext.

  2. Enter a working way to get a role with the right to query the SageMaker endpoint on the correct account and region. (This screenshot is using STS with AssumeRole logic).

Dataiku screenshot of an Amazon SageMaker connection.

Dataiku external models require the following rights:

  • sagemaker:DescribeEndpoint

  • sagemaker:DescribeEndpointConfig

  • sagemaker:InvokeEndpoint

  • sagemaker:ListEndpointConfigs

  • sagemaker:ListEndpoints

Note

See the Amazon SageMaker documentation on API permissions for details.


  1. Provide any name, such as azureml-ext.

  2. Enter a working way to get a role with the right to query the Azure Machine Learning endpoints you want to use. (This screenshot is using the OAuth from App method).

Dataiku screenshot of an Azure ML connection.

  1. Provide any name, such as vertex-ext.

  2. Enter the credentials to use. Ensure that this account is allowed to query Vertex endpoints, which is given by the role Vertex AI User.

Dataiku screenshot of an Google Vertex AI connection.

If you want more granular access, Dataiku requires the following rights:

  • aiplatform.endpoints.get

  • aiplatform.endpoints.list

  • aiplatform.endpoints.predict

Note

See the Vertex AI documentation on access control with IAM for details.

Add an evaluation dataset in Dataiku#

Once you have a connection in Dataiku to the external endpoint, you can create an external saved model.

However, before creating the actual model, a good practice is to have a dataset for Dataiku to evaluate the model performance. For each case here, we will use the model’s training data found in the starter project.

If you prefer not to evaluate the model, you can make that selection when creating a version of the external saved model. However, you’ll still need to provide a dataset so that Dataiku can save the feature names and types.


  1. In the Amazon SageMaker Flow zone, find the sagemaker_churn_prepared dataset.

Note

We initially uploaded the dataset from the churn tutorial as sagemaker_churn. However, as SageMaker models require a very specific format, we needed to transform this dataset into sagemaker_churn_prepared with a Python recipe using the exact same code as in the tutorial notebook.


  1. In the Azure ML Flow zone, find the default_of_credit_card_clients_prepared dataset.

Note

We uploaded the dataset from this Azure ML example data, removed the first line of X1, X2,..., and dropped the ID column in a Prepare recipe.


  1. In the Vertex AI Flow zone, find the petfinder-tabular-classification dataset.

Note

We uploaded it from this Google Cloud sample data.

Create an external saved model in Dataiku#

Now that you have an evaluation dataset, let’s proceed with the creation of the external saved model itself.

  1. From the Visual Analyses menu in the top navigation bar, click on Saved Models.

  2. Click + New External Saved Model.

  3. Choose your cloud ML platform.

Dataiku screenshot of the dialog for creating a new external saved model.

Important

Although you’ll see MLflow as an option here, you should be aware of a key difference. This MLflow option refers to a model designed outside of Dataiku, packaged using the MLflow format, and imported into Dataiku. On the other hand, for the external models discussed here, the models remain deployed where they are, but are made available to Dataiku users — as you will see.

Fill in the basic model information:


  1. Give a meaningful name to your model like sagemaker-churn.

  2. The prediction type is a Two-class classification.

  3. For the Authentication field, select the connection used in the previous step; sagemaker-ext in our case.

  4. Select the Region where your endpoint is deployed; eu-west-1 in our case.

Dataiku screenshot of the dialog for creating a new Amazon SageMaker external model.

  1. Give a meaningful name to your model like az-credit-fraud.

  2. The prediction type is a Two-class classification.

  3. For the Authentication field, select the connection used in the previous step; sagemaker-ext in our case.

  4. The other fields (Subscription ID, Resource group, and Workspace) are specific to your setup.

Dataiku screenshot of the dialog for creating a new Azure ML external model.

  1. Give a meaningful name to your model like vertex-petfinder.

  2. The prediction type is a Two-class classification.

  3. For the Authentication field, select the connection used in the previous step; vertex-ext in our case.

  4. Select the Region where your endpoint is deployed; europe-west-1 in our case.

  5. Project name is specific to your setup.

Dataiku screenshot of the dialog for creating a new Google Vertex AI external model.

Add a model version#

We now have an external model, but we need to create a model version that will contain all the details to query the endpoint.

  1. Open the saved model, and click on + Add Model Version.

  2. In the first section, click on Get Endpoints List to fetch a list of accessible endpoints.

  3. Select your endpoint from the list. Alternatively, you can enter its ID directly.

  4. Enter a simple version ID, such as v1.

Then complete the rest of the window with details specific to the case at hand:


  1. Enter the classes: 0 and 1 in our case.

  2. Leaving the default option to evaluate the model selected, enter the evaluation dataset, sagemaker_churn_prepared to have performance metrics on the model directly in Dataiku.

  3. Select Churn?_True. as the target column.

  4. As the computation of explainability data is not very long in this sample, uncheck the Skip expensive reports box.

  5. In this case, you can leave the default option of allowing Dataiku to guess the input/output format using the evaluation dataset.

  6. Click Create to let Dataiku create and evaluate this model. The creation is fairly fast, but the evaluation can take some time.

Dataiku screenshot of the dialog for creating a new Amazon SageMaker model version.

  1. Enter the classes: 0 and 1 in our case.

  2. Leaving the default option to evaluate the model selected, enter the evaluation dataset, default_of_credit_card_clients_prepared to have performance metrics on the model directly in Dataiku.

  3. Select default payment next month as the target column.

  4. As the computation of explainability data is not very long in this sample, uncheck the Skip expensive reports box.

  5. In this case, you can leave the default option of allowing Dataiku to guess the input/output format using the evaluation dataset.

  6. Click Create to let Dataiku create and evaluate this model. The creation is fairly fast, but the evaluation can take some time.

Dataiku screenshot of the dialog for creating a new Azure ML model version.

  1. Enter the classes: Yes and No in our case.

  2. Leaving the default option to evaluate the model selected, enter the evaluation dataset, petfinder-tabular-classification to have performance metrics on the model directly in Dataiku.

  3. Select Adopted as the target column.

  4. As the computation of explainability data is not very long in this sample, uncheck the Skip expensive reports box.

  5. Click Create to let Dataiku create and evaluate this model. The creation is fairly fast, but the evaluation can take some time.

Dataiku screenshot of the dialog for creating a new Google Vertex AI model version.

Note

Unchecking the default option to Skip expensive reports allows Dataiku to perform the requests required to compute the explainability sections. Although this adds value to the model, it triggers thousands of requests.

This is acceptable for our purpose, but for production endpoints, the additional stress on the endpoint may be a factor to consider. If need be, these reports can also be computed afterward individually.

Manage external endpoint changes#

Before demonstrating how you can use an external model that has been surfaced in Dataiku, it is important to recognize that Dataiku does not control the endpoint behind this object. Accordingly, these endpoints can change without notice. This could be a technical change, such as the addition of memory to the underlying infrastructure, or a change in the exposed model, such as a new deployed version.

  1. From the Saved Models page, open your saved model.

  2. Open the report for your model version (such as v1).

  3. In the Summary panel, find the following details about the external endpoint and the Check Endpoint button:


Dataiku screenshot of the model summary for an Amazon SageMaker endpoint.

Dataiku screenshot of the model summary for an Azure ML endpoint.

Dataiku screenshot of the model summary for an Vertex AI endpoint.

The Check Endpoint button is used to control whether the data we fetched and stored at the creation time is still accurate. If there are differences, Dataiku will offer you the ability to create a new saved model version as the potential data on performances and explainability is incorrect.

Dataiku screenshot of the result of the check endpoint dialog.

Use an external model in Dataiku#

Once you have a version of an external saved model in Dataiku, you can use it much like other visual models in Dataiku. In particular, we’ll highlight the following three benefits:

Model explainability#

To avoid black box models, Dataiku offers many built-in visualizations to understand the nature of a model. The same interface for investigating a model built in Dataiku can be used for investigating models deployed on a cloud ML platform.

  1. From the report of your model version, browse the Explainability and Performance sections on the left that were computed during the evaluation process.

  2. If you left the Skip expensive report option checked when creating the model version, feel free to request their computation manually.


Dataiku screenshot of the explainability panel for an Amazon SageMaker endpoint.

Dataiku screenshot of the explainability panel for an Azure ML endpoint.

Note

The endpoint in the Azure ML tutorial model happens to be non-probabilistic (it only outputs 0 or 1), and so many of the reports cannot be computed.


Dataiku screenshot of the explainability panel for a Google Vertex AI endpoint.

Model comparison#

In order to determine a champion model from any number of challengers, you may be familiar with creating a model comparison in Dataiku. This feature enables you to compare metrics side by side for any combination of models built in Dataiku, MLflow models imported into Dataiku, and models deployed externally.

The starter project already includes a model comparison containing a simple AutoML model built in Dataiku. You just need to add the external model to the existing model comparison object.


  1. From the Visual Analyses menu in the top navigation bar, click on Model Comparisons.

  2. Click to open the SageMaker vs AutoML comparison.

  3. Click Configure.

  4. Click + Add Items.

  5. Click Select Saved Model Versions from the Flow.

  6. Select the model version of your external endpoint.

  7. Click Add.

  8. Click Apply.

Dataiku screenshot of the model comparison including an Amazon SageMaker endpoint.

  1. From the Visual Analyses menu in the top navigation bar, click on Model Comparisons.

  2. Click to open the Azure ML vs AutoML comparison.

  3. Click Configure.

  4. Click + Add Items.

  5. Click Select Saved Model Versions from the Flow.

  6. Select the model version of your external endpoint.

  7. Click Add.

  8. Click Apply.

Dataiku screenshot of the model comparison including an Azure ML endpoint.

  1. From the Visual Analyses menu in the top navigation bar, click on Model Comparisons.

  2. Click to open the Vertex AI vs AutoML comparison.

  3. Click Configure.

  4. Click + Add Items.

  5. Click Select Saved Model Versions from the Flow.

  6. Select the model version of your external endpoint.

  7. Click Add.

  8. Click Apply.

Dataiku screenshot of the model comparison including a Google Vertex AI endpoint.

Model scoring#

If the external model is indeed your champion, you can use it in a Score recipe in a Dataiku Flow as you would for a visual model — either manually or through a scenario for ad hoc scoring or a real high-volume scoring batch.

  1. From the Flow zone dedicated to your cloud ML platform, select the external model and its evaluation dataset.

  2. In the Actions tab, select the Score recipe.

  3. Click Create Recipe.

  4. In the Settings tab of the Score recipe, notice the engine selection of External Model at the bottom left. Recall that although you have surfaced the model in Dataiku, it is only deployed externally.

  5. Click Run to score the data using the external endpoint’s engine.

Dataiku screenshot of the engine selection for a Score recipe with an external model.

Dataiku screenshot of a scoring Flow including an Amazon SageMaker endpoint.

Dataiku screenshot of a scoring Flow including an Azure ML endpoint.

Dataiku screenshot of a scoring Flow including a Vertex AI endpoint.

Additional considerations#

Endpoint scalability amidst increased democratization#

A key advantage of surfacing an external endpoint within Dataiku is the expanded audience of users who will be able to interact with the model. However, as with any democratization benefit, you’ll need to consider the corresponding impact on performance and volume on the endpoint.

The operations shown here generate queries to the external endpoint. This is especially true with explainability requests, which can easily reach into the thousands. To serve this new usage, you’ll need to plan for your endpoint to scale accordingly.

End user discovery and import of external models#

Although using external models in Dataiku is straightforward, actually surfacing them requires some knowledge of the underlying model and, potentially, administration rights to Dataiku and the ML cloud platform.

To simplify this process for end users, administrators might consider creating a dedicated Dataiku project that serves as a home for all external models and their corresponding sample datasets.

By making these models shareable and granting permissions to this project, a wider audience of Dataiku users can search for and add the desired external model into their own projects.

Deployment to a production environment#

This tutorial only demonstrated the usage of an external model in a Design sandbox. However, external models can also be surfaced in a scheduled, operationalized project. Deploying such a project to an Automation node is perfectly workable, provided the required connection also exists on the Automation node.

What’s next?#

Congratulations! You have taken an endpoint deployed on your cloud ML platform, and surfaced it as an external model within Dataiku so that you, as well as a wider audience, can use it for key functions like model explainability, comparisons, and scoring.

Note

You can learn more about external models in the reference documentation.

You can also learn more about other MLOps integrations points, such as: