Class ConcurrentModelPool<T extends InferenceModel>
Object
ConcurrentModelPool<T>
- Type Parameters:
- T- model-type
- All Implemented Interfaces:
- AutoCloseable
Keeps concurrent copies of a model to be used by different threads.
 
The copies van variously use GPU and CPU for execution, with GPU always being given priority.
- Author:
- Owen Feehan
- 
Constructor SummaryConstructorsConstructorDescriptionConcurrentModelPool(ConcurrencyPlan plan, CreateModelForPool<T> createModel, Logger logger) Creates with a particular plan and function to create models.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Close all models, to indicate they are no longer in use, and to perform tidy-up.<S> SexecuteOrWait(CheckedFunction<ConcurrentModel<T>, S, ConcurrentModelException> functionToExecute) Execute on the next available model (or wait until one becomes available).
- 
Constructor Details- 
ConcurrentModelPoolpublic ConcurrentModelPool(ConcurrencyPlan plan, CreateModelForPool<T> createModel, Logger logger) throws CreateModelFailedException Creates with a particular plan and function to create models.- Parameters:
- plan- a plan determining how many CPUs and GPUs to use for inference.
- createModel- called to create a new model, as needed.
- logger- where feedback is written about how many GPUs or CPUs were selected.
- Throws:
- CreateModelFailedException- if a model cannot be created.
 
 
- 
- 
Method Details- 
executeOrWaitpublic <S> S executeOrWait(CheckedFunction<ConcurrentModel<T>, S, throws ThrowableConcurrentModelException> functionToExecute) Execute on the next available model (or wait until one becomes available).If an exception is thrown while executing on a GPU, the GPU processor is no longer used, and instead an additional CPU node is added. The failed job is tried again. - Type Parameters:
- S- return type
- Parameters:
- functionToExecute- function to execute on a given model, possibly throwing an exception.
- Returns:
- the value returned by functionToExecuteafter it is executed.
- Throws:
- Throwable- if thrown from- functionToExecutewhile executing on a CPU. It is suppressed if thrown on a GPU.
 
- 
closeClose all models, to indicate they are no longer in use, and to perform tidy-up.- Specified by:
- closein interface- AutoCloseable
- Throws:
- Exception- if a model cannot be successfully closed.
 
 
-