Class DjlModelHandler

java.lang.Object
org.gridgain.internal.ml.handler.DjlModelHandler
All Implemented Interfaces:
AutoCloseable, ModelHandler

public class DjlModelHandler extends Object implements 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 Details

    • DjlModelHandler

      public DjlModelHandler(Executor executor)
      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:
      initialize in interface ModelHandler
      Parameters:
      modelInfo - Information about the model to initialize
      modelSource - The source from which to load the model
      Returns:
      A CompletableFuture that completes when initialization is done
    • predict

      public <I, O> CompletableFuture<O> predict(I input)
      Executes a prediction using the model asynchronously.
      Specified by:
      predict in interface ModelHandler
      Type Parameters:
      I - The input type
      O - The output type
      Parameters:
      input - The input data for prediction
      Returns:
      A CompletableFuture containing the prediction result
    • batchPredict

      public <I, O> CompletableFuture<List<O>> batchPredict(List<I> inputs)
      Executes a batch prediction using the model asynchronously.
      Specified by:
      batchPredict in interface ModelHandler
      Type Parameters:
      I - The input type
      O - 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:
      close in interface AutoCloseable
      Specified by:
      close in interface ModelHandler
    • 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 returns false. Subsequent calls return true, indicating that initialization had already occurred.
      Specified by:
      checkAndMarkInitialized in interface ModelHandler
      Returns:
      true if the handler was already initialized before this call, false if this call performed the initial marking.
    • getModelInfo

      public org.gridgain.ml.model.ModelInfo getModelInfo()
      Gets information about the model being handled.
      Specified by:
      getModelInfo in interface ModelHandler
      Returns:
      Information about the model
    • getEngineProperties

      public Map<String,String> getEngineProperties()
      Gets engine-specific properties.
      Specified by:
      getEngineProperties in interface ModelHandler
      Returns:
      Map of engine properties
    • getModelMetadata

      public Map<String,Object> getModelMetadata()
      Gets metadata about the model.
      Specified by:
      getModelMetadata in interface ModelHandler
      Returns:
      Map of model metadata