---
title: Run batch inference with a registered model
description: "Score data in batch with a Unity Catalog model: load the model by alias with MLflow, apply it with pandas or a Spark UDF, and write predictions to a table."
canonical_url: https://docs.databricks.com/gcp/en/getting-started/starter-journey/predictive-analytics/batch-inference
---

# Run batch inference with a registered model

Score a table of data with a model that's registered in Unity Catalog, and write the predictions to a Delta table. A batch inference job loads the model by alias, such as `Champion`, instead of by version number. When you reassign the alias to a new model version, the job uses the new version on its next run, without code changes.

## <a id="requirements" /> Requirements

You need the following before you run batch inference:

* A model registered in Unity Catalog. See [Register a model in Unity Catalog](https://docs.databricks.com/gcp/en/getting-started/starter-journey/predictive-analytics/save-model-to-unity-catalog.md).

* A model version with the `Champion` alias. The examples on [Register a model in Unity Catalog](https://docs.databricks.com/gcp/en/getting-started/starter-journey/predictive-analytics/save-model-to-unity-catalog.md) assign the `Challenger` alias. After you validate that version, assign `Champion` to it. You must own the registered model, and have the `USE SCHEMA` and `USE CATALOG` privileges on its catalog and schema, to set an alias:

  ```python
  from mlflow import MlflowClient

  MlflowClient().set_registered_model_alias("<catalog>.<schema>.<model>", "Champion", <version>)
  ```

  Or replace `@Champion` in the following examples with `@Challenger`.

* The `EXECUTE` privilege on the registered model, and the `USE CATALOG` and `USE SCHEMA` privileges on its catalog and schema.

* A table of input data with the columns that the model expects. This data can come from feature tables. See [Build feature tables for machine learning](https://docs.databricks.com/gcp/en/getting-started/starter-journey/predictive-analytics/prepare-datasets.md).

## <a id="choose" /> Choose an inference method

Match the method to the size and type of your data:

| Method                            | Use for                                                                 | Example                                                                                                                                          |
| --------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| pandas on one node                | Small batches and validation runs in a notebook                         | [ Score data with pandas](https://docs.databricks.com/gcp/en/getting-started/starter-journey/predictive-analytics/batch-inference.md#pandas)     |
| Spark user-defined function (UDF) | Large tables, distributed across a cluster, in batch or streaming jobs  | [ Score data with a Spark UDF](https://docs.databricks.com/gcp/en/getting-started/starter-journey/predictive-analytics/batch-inference.md#spark) |
| pandas UDF for images             | Computer vision models that score images stored in cloud object storage | [Reference solution for image applications](https://docs.databricks.com/gcp/en/machine-learning/reference-solutions/images-etl-inference.md)     |

## <a id="pandas" /> Score data with pandas

Load the model as a generic Python function, and call `predict()`:

```python
import mlflow

mlflow.set_registry_uri("databricks-uc")

model = mlflow.pyfunc.load_model("models:/<catalog>.<schema>.<model>@Champion")

input_df = spark.table("<catalog>.<schema>.<input-table>").toPandas()
input_df["prediction"] = model.predict(input_df)
```

To load a specific version instead, use `models:/<catalog>.<schema>.<model>/<version>`. See [Load model version by alias for inference workloads](https://docs.databricks.com/gcp/en/machine-learning/manage-model-lifecycle/index.md#load-models-for-inference).

## <a id="spark" /> Score data with a Spark UDF

Load the model as a Spark user-defined function (UDF), so that scoring runs in parallel across the cluster, and write the predictions to a Delta table:

```python
import mlflow

mlflow.set_registry_uri("databricks-uc")

model_udf = mlflow.pyfunc.spark_udf(spark, "models:/<catalog>.<schema>.<model>@Champion")

input_data = spark.table("<catalog>.<schema>.<input-table>")
predictions = input_data.withColumn("prediction", model_udf())

predictions.write.mode("overwrite").saveAsTable("<catalog>.<schema>.<predictions-table>")
```

To restore the model's library dependencies in the UDF, pass `env_manager="virtualenv"` to `spark_udf`. See [Log, load, and register MLflow models](https://docs.databricks.com/gcp/en/mlflow/models.md).

To run the scoring on a schedule, add the notebook to a job. See [Orchestrate workloads with Lakeflow Jobs](https://docs.databricks.com/gcp/en/getting-started/starter-journey/orchestration.md).

## <a id="next-steps" /> Next steps

| Resource                                                                                                                         | Description                                                                   |
| -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| [Build AI agents on Databricks](https://docs.databricks.com/gcp/en/getting-started/starter-journey/agents.md)                    | Build AI agents on top of your governed data                                  |
| [Deploy models for batch inference and prediction](https://docs.databricks.com/gcp/en/machine-learning/model-inference/index.md) | Learn about the batch inference options on Databricks, including AI Functions |
