Sub topic 12
Rolling an endpoint forward to a new version
This chapter assumes you have already registered main.default.iris_classifier and created iris-endpoint for version 1. It also assumes you have the Databricks SDK for Python installed and authenticated.
What an endpoint points at
A serving endpoint is pinned to a specific model version number. If you move the champion alias to version 2, the endpoint keeps serving version 1. You have to update the endpoint configuration yourself.
The update is a rolling one. Databricks starts the new configuration while the current one keeps answering requests. When the new one is ready, traffic switches over. If the new configuration fails to start, the old one stays live.
Updating to version 2
Register the new version first, using the same log_model call as before. Then call update_config_and_wait. It replaces the whole configuration, so repeat any settings you want to keep.
from databricks.sdk import WorkspaceClient
from databricks.sdk.service.serving import ServedEntityInput
w = WorkspaceClient()
w.serving_endpoints.update_config_and_wait(
name="iris-endpoint",
served_entities=[
ServedEntityInput(
entity_name="main.default.iris_classifier",
entity_version="2",
workload_size="Small",
scale_to_zero_enabled=True,
)
],
)Afterwards, move the alias so it matches what is live:
from mlflow import MlflowClient
import mlflow
mlflow.set_registry_uri("databricks-uc")
MlflowClient().set_registered_model_alias(
"main.default.iris_classifier", "champion", 2
)Do the alias change after the endpoint update succeeds. Otherwise the alias and the endpoint disagree.
Splitting traffic between versions
To test a new version on real requests, serve both and divide traffic. Give each served entity a name, then route percentages to those names. The percentages must add up to 100.
from databricks.sdk import WorkspaceClient
from databricks.sdk.service.serving import (
ServedEntityInput,
TrafficConfig,
Route,
)
w = WorkspaceClient()
w.serving_endpoints.update_config_and_wait(
name="iris-endpoint",
served_entities=[
ServedEntityInput(
name="v1",
entity_name="main.default.iris_classifier",
entity_version="1",
workload_size="Small",
scale_to_zero_enabled=True,
),
ServedEntityInput(
name="v2",
entity_name="main.default.iris_classifier",
entity_version="2",
workload_size="Small",
scale_to_zero_enabled=True,
),
],
traffic_config=TrafficConfig(
routes=[
Route(served_model_name="v1", traffic_percentage=90),
Route(served_model_name="v2", traffic_percentage=10),
]
),
)If version 2 behaves well, run the update again with only v2 at 100 percent, or with only version 2 listed.
Rolling back
Rolling back is the same operation in the other direction. Update the endpoint to the earlier version number. Because the older version is still registered, nothing needs to be rebuilt or re-logged.
Common errors
- The update is rejected while another is running. An endpoint accepts one configuration change at a time. Wait for the current update to finish, or use the
_and_waitcall so your script blocks until it does. - Clients still get old predictions. Check the endpoint's served entity version, not the alias. The alias does not control the endpoint.
- The new version fails to start. The old version stays live. Open the endpoint's build logs and service logs to find the error. A missing dependency or a missing privilege on the model are typical causes.
- Responses change shape. A new version with a different signature can break existing clients. Compare the signatures of the two versions before switching traffic.
Exercise
You registered version 3 of a model and moved the alias champion to it. Clients of the endpoint still receive version 2 predictions. Why, and what do you do?
Show answer
The endpoint is pinned to version 2 in its served entity configuration, and aliases do not change that. Call updateconfigandwait with entityversion="3" (optionally with a traffic split first). After it succeeds, the endpoint serves version 3.