Class Adapter

java.lang.Object
ai.djl.serving.wlm.Adapter
Direct Known Subclasses:
PyAdapter

public abstract class Adapter extends Object
An adapter is a modification producing a variation of a model that can be used during prediction.
  • Field Details

  • Constructor Details

    • Adapter

      protected Adapter(String name, String src)
      Constructs an Adapter.
      Parameters:
      name - the adapter name
      src - the adapter source
  • Method Details

    • newInstance

      public static Adapter newInstance(WorkerPoolConfig<?,?> wpc, String name, String src)
      Constructs a new Adapter.

      After registration, you should call register(WorkerPool). This doesn't affect the worker pool itself.

      Parameters:
      wpc - the worker pool config for the new adapter
      name - the adapter name
      src - the adapter source
      Returns:
      the new adapter
    • unregister

      public static <I, O> void unregister(WorkerPool<I,O> wp, String adapterName)
      Unregisters an adapter in a worker pool.

      This unregisters it in the wpc for new threads and all existing threads.

      Type Parameters:
      I - the input type
      O - the output type
      Parameters:
      wp - the worker pool to remove the adapter from
      adapterName - the adapter name
    • getName

      public String getName()
      Returns the adapter name.
      Returns:
      the adapter name
    • getSrc

      public String getSrc()
      Returns the adapter src.
      Returns:
      the adapter src
    • register

      public <I, O> void register(WorkerPool<I,O> wp)
      Registers this adapter in a worker pool.

      This registers it in the wpc for new threads and all existing threads.

      Type Parameters:
      I - the input type
      O - the output type
      Parameters:
      wp - the worker pool to register this adapter in
    • registerJob

      public <I, O> WorkerJob<I,O> registerJob(WorkerPoolConfig<I,O> wpc, WorkerPoolConfig.ThreadConfig<I,O> threadConfig)
      Creates a WorkerJob to register this adapter in a WorkerThread.
      Type Parameters:
      I - the input type
      O - the output type
      Parameters:
      wpc - the worker pool of the thread
      threadConfig - the thread config to register
      Returns:
      the registration job
    • unregisterJob

      public <I, O> WorkerJob<I,O> unregisterJob(WorkerPoolConfig<I,O> wpc, WorkerPoolConfig.ThreadConfig<I,O> threadConfig)
      Creates a WorkerJob to unregister this adapter from a WorkerThread.
      Type Parameters:
      I - the input type
      O - the output type
      Parameters:
      wpc - the worker pool of the thread
      threadConfig - the thread config to unregister
      Returns:
      the unregistration job
    • registerPredictor

      protected abstract void registerPredictor(ai.djl.inference.Predictor<?,?> predictor)
    • unregisterPredictor

      protected abstract void unregisterPredictor(ai.djl.inference.Predictor<?,?> predictor)