Timeouts in Model Serving

Azure Databricks Model Serving endpoints can time out during deployment, on the server, and on the client.

Model deployment timeouts

When you deploy a model or update an existing deployment using Model Serving, the process might time out for several reasons. The Events tab of the model serving endpoint page records timeout messages. Search on "timed out" to find them.

Note

The deployment process times out if the container build and model deployment exceed a certain duration that is dependent on the endpoint workload configuration. Check your configuration before deploying and compare it to previous successful deployments.

  • The container build must finish within 2 hours. Retries count toward that time, and a failed build is retried up to 3 times.
  • The whole update must finish within 6 hours.
  • The deployment after the container is built waits up to 30 minutes for CPU workloads, 60 minutes for GPU_SMALL and GPU_MEDIUM workloads, and 120 minutes for GPU large and multi-GPU workloads before timing out.

Model Serving Endpoint Events Tab

If you find a "timed out" message, open the Logs tab and examine the build logs to determine the cause. Examples include library dependency issues, resource constraints, and configuration issues.

Model Serving Endpoint Build Logs

See Debug after container build failure.

Server-side timeouts

If your endpoint is healthy according to the Events and Logs tabs, but calls to the endpoint still time out, the timeout might be on the server-side. The default timeout depends on the type of model serving endpoint. The following table shows the default server-side timeouts for requests sent to model serving endpoints.

Endpoint type Request timeout limit (seconds) Notes
CPU or GPU serving endpoints Default 597 This limit can't be increased.
Foundation model serving endpoints Default 597 This limit can't be increased.
Open model serving endpoints (streaming requests) Default 1,796 Applies only to streaming requests to open models, except the legacy Meta Llama 3.1 8B, 70B, and 405B models, which use 597 seconds.

For the limits on custom model and agent endpoints, see Resource and payload limits.

To determine if you experienced a server-side timeout, see if your requests are timing out before or after the limits listed above.

  • If your request consistently fails at the limit, then it's likely a server-side timeout.
  • If your request fails earlier than the limit, it might be due to configuration issues.
    • Check the service logs to determine if there are any other errors.
    • Confirm that the model has worked locally, like from a notebook, or on previous requests on earlier versions.

Client-side timeouts: MLflow configuration

Client-side timeouts typically return error messages that say "timed out" or "4xx Bad Request". Common causes are MLflow environment variable settings where the calling code runs. The following are the most common MLflow environment variables for timeouts. For the full list of timeout variables, see the mlflow.environment_variables documentation.

  • MLFLOW_DEPLOYMENT_PREDICT_TIMEOUT: Specifies the timeout for predict and predict_stream calls made with the MLflow Deployments client, as a number of seconds. Default timeout 120 seconds.
  • MLFLOW_HTTP_REQUEST_TIMEOUT: Specifies the timeout for MLflow HTTP requests, as a number of seconds. Default timeout 120 seconds.
  • MLFLOW_HTTP_REQUEST_MAX_RETRIES: Specifies the maximum number of retries with exponential backoff for MLflow HTTP requests. Default is 7 retries.

Note

The HTTP request timeouts on the client-side are set to 120 seconds, which differs from the server-side's default timeout of 597 seconds for CPU and GPU serving endpoints. If a call can run longer than 120 seconds, set the variable that matches the call where the calling code runs: MLFLOW_DEPLOYMENT_PREDICT_TIMEOUT for predict and predict_stream calls made with the MLflow Deployments client, and MLFLOW_HTTP_REQUEST_TIMEOUT for other MLflow HTTP requests. Variables set on the endpoint apply only to the process that runs your model, and they don't change the client-side timeout.

Do either of the following to determine if a timeout is caused by an MLflow environment variable configuration:

  • Test the model locally using sample inputs, like in a notebook. Confirm that it works as expected before you register the model and deploy it.
    • Examine the time it takes to process the requests.
      • If requests take longer than the default timeouts for MLflow environment variables, or you get a "timed out" message in the notebook, adjust the MLflow environment variables in the environment where your code runs. See Configure MLflow environment variables.
  • Test the model serving endpoint using POST requests.
    • Check the Service logs for your endpoint or the inference tables if you enabled them.
      • Example "timed out" message: Timed out while evaluating the model. Verify that the model evaluates within the timeout. The endpoint returns this message as a 400 error when a model call runs past the server-side limit. See Server-side timeouts.
      • For inference table schema details, see Inference table schema for AI Gateway (legacy).

Configure MLflow environment variables

You can set MLflow environment variables on a model serving endpoint. Do this only when your model code makes MLflow HTTP requests. The following Python example sets MLFLOW_HTTP_REQUEST_TIMEOUT to 300 and MLFLOW_HTTP_REQUEST_MAX_RETRIES to 3 for the process that runs your model.

For further details about the payload to set this up, see the Databricks API page.

import mlflow.deployments

# Get the deployment client
client = mlflow.deployments.get_deploy_client("databricks")

# Define the configuration with environment variables
config = {
   "served_entities": [
       {
           "name": "sklearn_example-1",
           "entity_name": "catalog.schema.model_name",
           "entity_version": "1",
           "workload_size": "Small",
           "workload_type": "CPU",
           "scale_to_zero_enabled": True,
           "environment_vars": {
               "MLFLOW_HTTP_REQUEST_MAX_RETRIES": "3",
               "MLFLOW_HTTP_REQUEST_TIMEOUT": "300"
           }
       },
   ],
   "traffic_config": {
       "routes": [
           {
               "served_entity_name": "sklearn_example-1",
               "traffic_percentage": 100
           }
       ]
   }
}

# Create the endpoint with the specified configuration
endpoint = client.create_endpoint(
   name="model_name-1",
   config=config
)

To set the variables on the endpoint in the Serving UI instead, edit the endpoint, and in Entity details, expand Advanced configuration to add the variable. See Add plain text environment variables.

Client-side timeouts: Third party client APIs

Client-side timeouts typically return error messages that say "timed out" or "4xx Bad Request". Similar to MLflow configurations, third party client APIs can cause client-side timeouts depending on their configuration. These can impact model serving endpoints that consist of pipelines that use these third party client APIs. See custom PyFunc models and PyFunc custom schema agents.

The steps below follow the MLflow configuration checks. Use them to determine if a timeout is caused by third-party client APIs used in your model pipeline:

  • Test the model locally with sample inputs in a notebook.
    • If you see a "timed out" message in the notebook, adjust any relevant parameters for the third party client's timeout window.
    • Example "timed out" message: APITimeoutError: Request timed out.
  • Test the model serving endpoint using POST requests.

OpenAI client example

When you establish an OpenAI client, you can configure the timeout parameter. It changes the maximum time before a request times out on the client side. The default and maximum timeout for an OpenAI client is 10 minutes.

The following example shows how to set a timeout for a third-party client API:

%pip install openai==1.54.0
dbutils.library.restartPython()

from openai import OpenAI
import os

# How to get your Databricks token: https://docs.databricks.com/en/dev-tools/auth/pat.html
DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')
client = OpenAI(
    timeout=10, # Number of seconds before client times out
    api_key=DATABRICKS_TOKEN,
    base_url="<WORKSPACE_URL>/serving-endpoints"
)

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "system",
            "content": "You are an AI assistant"
        },
        {
            "role": "user",
            "content": "Tell me about Large Language Models."
        }
    ],
    model="<endpoint-name>",
    max_tokens=256
)

Set model to the name of the serving endpoint.

Note

For the OpenAI client, you can get around the maximum timeout window by enabling streaming.

Other timeouts

Idle endpoints warming up

If an endpoint is scaled to 0 and it receives a request that warms it up, it can lead to a client-side timeout if it takes too long to warm up. This can be a cause of timeouts in pipelines that use steps like calls to provisioned throughput endpoints or AI Search indices.

Connection timeout

Connection timeouts are related to the time a client waits to establish a connection with the server. If the connection isn't established within this time, the client cancels the attempt. Be aware of the clients used in your model pipeline. Check the service logs and inference tables of the Model Serving endpoint for any connection timeouts. The messaging varies by service.

  • For example, a SocketTimeout (for a service reading/writing to a SQL warehouse over a Java Database Connectivity (JDBC) connection) may look like the following:
    • jdbc:spark://<server-hostname>:443;HttpPath=<http-path>;TransportMode=http;SSL=1[;property=value[;property=value]];SocketTimeout=300
  • To find these, look for error messages containing the term "timed out" or "timeout".

Rate limits

Requests sent above the rate limit of an endpoint can fail. See Resource and payload limits for rate limits based on endpoint types. For third party clients, Databricks recommends that you review the documentation of the third party client you are using.

Additional resources

Resource Description
Model Serving limits and regions Request, payload, and rate limits for Model Serving endpoints.
Troubleshoot Model Serving endpoints Find and fix build and request errors on Model Serving endpoints.