Package org.gridgain.internal.ml.handler
Class DjlModelHandler
java.lang.Object
org.gridgain.internal.ml.handler.DjlModelHandler
- All Implemented Interfaces:
AutoCloseable,ModelHandler
Implementation of ModelHandler for DJL models.
This handler uses the DJLAdapter to simplify interaction with DJL
Thread Safety: This class is NOT thread-safe. Handler instances are designed for single-use and should not be shared across threads. Each prediction operation should use a fresh handler instance.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<I,O> CompletableFuture<List<O>> batchPredict(List<I> inputs) Executes a batch prediction using the model asynchronously.booleanAtomically checks whether the model handler was already initialized.voidclose()Releases resources associated with the model.Gets engine-specific properties.org.gridgain.ml.model.ModelInfoGets information about the model being handled.Gets metadata about the model.initialize(org.gridgain.ml.model.ModelInfo modelInfo, ModelSource modelSource) Initializes the model handler with a model source asynchronously.<I,O> CompletableFuture<O> predict(I input) Executes a prediction using the model asynchronously.
-
Constructor Details
-
DjlModelHandler
Creates a new DJL model handler.- Parameters:
executor- Executor for ML inference operations
-
-
Method Details
-
initialize
public CompletableFuture<Void> initialize(org.gridgain.ml.model.ModelInfo modelInfo, ModelSource modelSource) Initializes the model handler with a model source asynchronously.- Specified by:
initializein interfaceModelHandler- Parameters:
modelInfo- Information about the model to initializemodelSource- The source from which to load the model- Returns:
- A CompletableFuture that completes when initialization is done
-
predict
Executes a prediction using the model asynchronously.- Specified by:
predictin interfaceModelHandler- Type Parameters:
I- The input typeO- The output type- Parameters:
input- The input data for prediction- Returns:
- A CompletableFuture containing the prediction result
-
batchPredict
Executes a batch prediction using the model asynchronously.- Specified by:
batchPredictin interfaceModelHandler- Type Parameters:
I- The input typeO- The output type- Parameters:
inputs- A list of input data items for batch prediction- Returns:
- A CompletableFuture containing a list of prediction results
-
close
public void close()Releases resources associated with the model.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceModelHandler
-
checkAndMarkInitialized
public boolean checkAndMarkInitialized()Atomically checks whether the model handler was already initialized. If this is the first call, it marks the handler as initialized and returnsfalse. Subsequent calls returntrue, indicating that initialization had already occurred.- Specified by:
checkAndMarkInitializedin interfaceModelHandler- Returns:
trueif the handler was already initialized before this call,falseif this call performed the initial marking.
-
getModelInfo
public org.gridgain.ml.model.ModelInfo getModelInfo()Gets information about the model being handled.- Specified by:
getModelInfoin interfaceModelHandler- Returns:
- Information about the model
-
getEngineProperties
Gets engine-specific properties.- Specified by:
getEnginePropertiesin interfaceModelHandler- Returns:
- Map of engine properties
-
getModelMetadata
Gets metadata about the model.- Specified by:
getModelMetadatain interfaceModelHandler- Returns:
- Map of model metadata
-