# Batch Prediction Jobs

## Pre-requisites

MinIO should already be installed with Seldon Enterprise Platform. The MinIO browser should be exposed on `/minio/` (note the trailing forward slash).

For trials, the credentials will by default be the same as the Enterprise Platform login, with MinIO using the email as its `Access Key` and the password as its `Secret Key`.

{% hint style="info" %}
Other cloud storage services, such as `S3` and `GCS`, can be specified alternatively with the corresponding secret files configured.
{% endhint %}

On a production cluster, the namespace needs to have been set up with a service account. This can be found under the [argo install documentation](/seldon-enterprise-platform/production-environment/argo-workflows.md).

This demo helps you learn about:

* Deploying a deployment with a pre trained SKlearn iris model
* Running a batch job to get predictions
* Checking the output

## Create a Deployment

1. Click on `Create new deployment` button.
2. Enter the deployment details as follows:

   * Name: *batch-demo*
   * Namespace: *seldon*
   * Type: *Seldon Deployment*

   ![deployment wizard details step](/files/S4iK3Aakhy0haTrXiUFW)
3. Configure the default predictor as follows:
   * Runtime: *Scikit Learn*
   * Model URI: `gs://seldon-models/scv2/samples/mlserver_1.6.0/iris-sklearn`
   * Model Project: *default*
   * Storage Secret: *(leave blank/none)*
   * Model Name: *iris*

{% hint style="warning" %}
The `Model Name` is linked to the name described in the `model-settings.json` file, located in the Google Cloud Storage location. Changing the name in the JSON file would also require changing the `Model Name`, and vice versa.
{% endhint %}

4. Skip `Next` for the remaining steps, then click `Launch`.
5. If your deployment is launched successfully, it will have `Available` status, on the overview page.

## Setup Input Data

1. Download the input data file `iris-input.txt`.

{% file src="/files/Qi4S4WN1pmFcQI74lZ8p" %}

The first few lines of the input file \`iris-input.txt\` should show the following format:

```
{"inputs":[{"name":"predict","data":[0.38606369295833043,0.006894049558299753,0.6104082981607108,0.3958954239450676],"datatype":"FP64","shape":[1,4]}]}
{"inputs":[{"name":"predict","data":[0.7223678219956075,0.608521741883582,0.8596266157372878,0.20041864827775757],"datatype":"FP64","shape":[1,4]}]}
{"inputs":[{"name":"predict","data":[0.8659159480026418,0.2383384971368594,0.7743518759043038,0.8748919374334038],"datatype":"FP64","shape":[1,4]}]}
```

2. Go to the MinIO browser and use the button in the bottom-right to create a bucket. Call it `data`.
3. Again from the bottom-right choose to upload the `iris-input.txt` file to the `data` bucket.

## Run a Batch Job

1. Click the new deployment `batch-demo` in the **Overview page**.
2. Click the **Batch Jobs** in the left pane.
3. Click **Create Your First Job**, enter the following details, and click **Submit**:

   * Input Data Location: `minio://data/iris-input.txt`
   * Output Data Location: `minio://data/iris-output-{{workflow.name}}.txt`
   * Number of Workers: *5*
   * Number of Retries: *3*
   * Batch Size: *10*
   * Minimum Batch Wait Interval (sec) : *0*
   * Method: *Predict*
   * Transport Protocol: *REST*
   * Input Data Type: *Open Inference Protocol (OIP)*
   * Object Store Secret Name: *minio-bucket-envvars*

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>Note</strong>: In this job <code>minio-bucket-envvars</code> is a <a href="/pages/kebmNaqh3i85uKqxEXcP#configuration">pre-created secret</a> in the same namespace as the model, containing environment variables.</p></div>

{% hint style="info" %}
In the `Resources (Optional)` section, you can specify how much memory and CPU are allocated to the containers in this specific batch job workflow. If no values are set on this form, the default values specified in Helm values will be used. Refer to the [Kubernetes documentation on requests and limits](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#requests-and-limits) for details.
{% endhint %}

4\. Give the job a couple of minutes to complete, then refresh the page to see the status.

<details>

<summary>Expand to see batch job status</summary>

<img src="/files/88mhXvkjbufAplr6cqkN" alt="batchjobstatus" data-size="original">

</details>

5\. Inspect the output file in MinIO:

![miniooutput](/files/CVlbx6Z9ln128PWCEy1M)

If you open that file you should see contents such as:

```
{"model_name":"","outputs":[{"data":[0],"name":"predict","shape":[1],"datatype":"INT64"}],"parameters":{"batch_index":0}}
{"model_name":"","outputs":[{"data":[0],"name":"predict","shape":[1],"datatype":"INT64"}],"parameters":{"batch_index":2}}
{"model_name":"","outputs":[{"data":[1],"name":"predict","shape":[1],"datatype":"INT64"}],"parameters":{"batch_index":4}}
{"model_name":"","outputs":[{"data":[0],"name":"predict","shape":[1],"datatype":"INT64"}],"parameters":{"batch_index":1}}
```

If not, see the [argo section](/seldon-enterprise-platform/production-environment/argo-workflows.md) for troubleshooting.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.seldon.ai/seldon-enterprise-platform/demos/seldon-core-v1/batch-requests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
