For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

Model Deployment and Predictions

Deploy machine learning models to a GridGain 9 cluster and run simple, batch, SQL-based, and colocated predictions, including advanced custom translators and compute jobs.

Before deploying models, ensure you have configured GridGain ML thread pool settings. See the Thread Pool Configuration section in the quickstart guide.

Model Deployment

Preparing the Model

You can use models from the following sources:

  • Pretrained models from DJL Model Zoo.

  • Locally trained models.

  • Pre-trained models in supported formats with correct model names.

DJL Model Zoo

DJL Model Zoo models come in supported formats pre-configured with serving.properties that have the modelName preconfigured. You can download them easily using a program like the one in the quickstart guide.

Other Sources

The system automatically searches for model files named model.* (e.g., model.onnx, model.pt). You can override this default behavior by adding .name("your-model-name") to your job parameters.

Supported Model Formats

Framework
Supported Formats
Required Files

PyTorch

.pt

Model file + configuration files.

TensorFlow

.pb

Model file + configuration files.

ONNX

.onnx

Model file + configuration files.

Unsupported Formats

  • SafeTensors (.safetensors): Not supported by DJL. Must convert to PyTorch format.

  • Pytorch Pickled (.pth): Not supported by DJL. Must convert to TorchScript (.pt) format.

  • Pickle files (.pkl): Raw pickle files need proper model wrapper.

Deploying the Model

Models are deployed as deployment units using the CLI or REST:

For more information refer to code deployment documentation.

Automated Deployment

GridGain ML provides utility methods to automate model download and deployment for different scenarios.

Standard Models with Custom Classes

For models with custom input/output types, translators, or marshallers:

This method automatically:

  • Downloads all required model files from the specified URLs

  • Creates a temporary directory for the model files

  • Packages custom classes (translators, marshallers) into a JAR

  • Deploys both the model and custom classes to the GridGain cluster

DJL Model Zoo Models

For models from the DJL Model Zoo using djl:// protocol:

This method automatically:

  • Downloads the PyTorch model from DJL model zoo

  • Compiles custom classes from the source directory

  • Generates a JAR containing the custom compiled classes

  • Deploys both the model files and custom classes JAR to the GridGain cluster

TensorFlow Models with Folder Structure

For TensorFlow SavedModel format that requires specific folder structure:

This method automatically:

  • Downloads all required TensorFlow model files

  • Creates the proper folder structure (saved_model.pb in root, variables in variables/ subdirectory)

  • Packages custom classes into a JAR

  • Deploys both the model and custom classes to the GridGain cluster

The downloadAndDeployModelAndJarWithFolderStructure method is specifically designed to handle TensorFlow's folder structure requirements.

Model Properties Reference

Core Properties

Some examples of common model properties that could optionally be used in job parameters:

In case your model requires additional properties, the below attributes could be defined.

Property
Description

application

DJL application type

groupId

Model zoo group ID

artifactId

Model zoo artifact ID

Either translator or translator factory must be provided.

Translator Arguments

Properties without the option. prefixes are passed to the TranslatorFactory.

  1. For built-in translators you will need to check their source code.

  2. For custom translators, you can pass ANY properties (without the option. prefix) and they will be available in your TranslatorFactory's newInstance() method via the arguments' parameter.

Engine Options

Properties that do not match the Core Properties and do not have the option. prefix are passed as engine options.

Examples:

  • option.mapLocation - (PyTorch) Map to CPU before loading.

  • option.ortDevice - (ONNX) Device selection.

  • option.Tags - (TensorFlow) Model tags.

Running Predictions

Simple Predictions

Execute inference with a single input.

Batch Predictions

Execute inference on multiple inputs in a batch.

SQL-Based Predictions

Execute inference using SQL queries on database tables:

Parameterized Queries

Execute inference using parameterized SQL queries:

Colocated Predictions

Execute inference on data stored locally on specific cluster nodes.

Asynchronous Operations

All prediction methods support asynchronous execution:

Execution Modes

GridGain ML examples can run in different modes depending on your deployment scenario. The examples use a base class (MlBaseExample) that supports two execution modes:

All four examples supports both execution modes, we can select either MODE.EMBEDDED or MODE.CLIENT_ONLY

Available Modes

All examples in this documentation support both execution modes.

Embedded Mode (MODE.EMBEDDED)

Runs the ML inference directly within the GridGain server process.

Characteristics:

  • Single JVM process

  • No separate client connection needed

  • Lowest latency for inference operations

  • Ideal for testing and development

Setup:

Client-Only Mode (MODE.CLIENT_ONLY)

Connects to an existing GridGain cluster as a thin client.

Characteristics:

  • Requires a running GridGain cluster

  • Separate client process connects to the cluster

  • Production-ready deployment pattern

  • Network overhead for operations

Setup:

Advanced Usage

When to Use Standard vs Custom Approaches

Use Standard Approach When:

  1. Standard input/output types: Working with primitives or built-in DJL types (e.g., String, Classifications)

  2. Built-in DJL translator functionality: The translator provided by DJL meets your pre/post data processing needs

  3. Simple data flows: No complex pre/post-processing workflows required

This approach is shown in the basic prediction examples above.

Use Custom Compute Jobs When:

  1. Custom input/output types: Implementing user-defined types that require specialized marshalling beyond built-in DJL serialization

  2. Advanced processing logic: Building complex pre/post-processing workflows that extend beyond standard translator capabilities

  3. Non-standard data flows: Creating advanced examples with specialized data handling requirements

  4. Fine-grained execution control: Needing direct control over the model inference pipeline and data transformation steps

Custom compute jobs provide the flexibility to define independent input types, output types, translators, and marshallers when the standard framework cannot accommodate your specific use case.

Download Model

Download a zeroshot classification model files from HuggingFace:

Custom Translator

Create a custom translator and translator factory to pre-process the inputs before prediction and post process the output from the model for consumption.

Step 1: Create a Custom Translator

Step 2: Create a Custom Translator Factory

Step 3: Using Custom Translator

Custom Compute Jobs (Brief Introduction)

When you need full control over the prediction pipeline, including custom marshallers for serialization, you can extend the MlComputeJob class.

Basic Structure

When to Use Custom Compute Jobs

Custom compute jobs are required when:

  • You have custom input/output types that need specialized serialization

  • You need to implement custom marshallers for data transfer

  • You want to use different prediction methods (predict, batchPredict, predictFromSql, predictColocated) with custom types

Adding to Job Parameters

This page is: Copyright © 2026 MariaDB. All rights reserved.

Last updated

Was this helpful?