public final class InferenceOptions
- Object
- InferenceOptions
Configures how a reusable InferenceSession is created.
Accelerator requests are portable preferences rather than promises.
With fallback enabled, a backend may execute on CPU when the requested
delegate is unavailable. With fallback disabled, opening the session
fails instead of silently changing the execution target. Android’s NNAPI
runtime can mix NPU and CPU operations without reporting full delegation,
and the iOS Core ML delegate can schedule work across the Neural Engine,
GPU, and CPU. Both mobile backends therefore reject
Accelerator.NPU when fallback is disabled. iOS also rejects strict
Accelerator.CORE_ML sessions because the delegate does not report
whether unsupported model operations remained on LiteRT’s CPU path.
Nested types
enum InferenceOptions.Accelerator | Execution targets understood by the portable inference API. |
Constructors
public InferenceOptions() |
Methods
Inherited methods
Constructor details
InferenceOptions
public InferenceOptions()Method details
accelerator
public InferenceOptions accelerator(InferenceOptions.Accelerator value)Parameters
valueInferenceOptions.Accelerator- requested target;
nullrestoresAccelerator.AUTO
Returns
threads
public InferenceOptions threads(int value)Parameters
valueint- requested worker count
Returns
allowFallback
public InferenceOptions allowFallback(boolean value)Controls whether opening may fall back from an unavailable accelerator to CPU execution.
On Android and iOS, setting this to false with
Accelerator.NPU rejects session creation. On iOS it also
rejects Accelerator.CORE_ML. Neither LiteRT’s NNAPI delegate
nor its Core ML delegate can prove that every operation ran on the
requested accelerator instead of CPU or another processor.
Parameters
valuebooleantrueto permit CPU fallback
Returns
getAccelerator
public InferenceOptions.Accelerator getAccelerator()Returns
nullgetThreads
public int getThreads()Returns
isFallbackAllowed
public boolean isFallbackAllowed()