Scheduled Training and Deployment

Overview

To retrain an ML model and deploy the new version periodically, we'll need a schedule-based automation.

In this tutorial, we show how to configure the scheduled automation.

When does it make sense to use the scheduled-based automation?

It won't help to retrain the model when using the same training data every time.

Because of that, the model's build function should retrieve the up-to-date training data from the Feature Store.

If you aren't familiar with the Qwak Feature Store, check out our Getting Started guide.

Pre-requisites

Make sure you store the model code in a Git. We will need the repository URL and the access token later on.

Configuration

First, we create an empty Python script and define the import the dependencies and create an instance of the Automation class and configure it:

from qwak.automations import Automation, ScheduledTrigger, \
      QwakBuildDeploy,BuildSpecifications, BuildMetric, \
        ThresholdDirection, DeploymentSpecifications

test_automation = Automation(
    name="automation_name",
    model_id="model_to_be_deployed",
    trigger=ScheduledTrigger(cron="0 0 * * 0"),
    action=QwakBuildDeploy(
        build_spec=BuildSpecifications(git_uri="https://github.com/org_id/repository_name.git#directory/another_directory",
                                       git_access_token_secret="secret_name",
                                       git_branch="main",
                                       main_dir="main",
                                       tags=["prod"],
                                       env_vars=["key1=val1","key2=val2","key3=val3"]),
        deployment_condition=BuildMetric(metric_name="f1_score",
                                         direction=ThresholdDirection.ABOVE,
                                         threshold="0.65"),
        deployment_spec=DeploymentSpecifications(number_of_pods=1,
                                                 cpu_fraction=2.0,
                                                 memory="2Gi",
                                                 variation_name="B",
                                                 environments=["env1","env2"])
    )
)

We have described the configuration parameters in our Automating Build & Deploy page.

Publishing the automation

Finally, we can use the Qwak CLI to publish the automation. We specify the name of the Qwak environment --environment and the directory containing the automation definitions-p, In this case, the current working directory.

qwak automations register --environment environment_name -p .