executorch_flutter library
ExecuTorch Flutter Plugin - On-device ML inference with ExecuTorch
This package provides Flutter developers with the ability to run ExecuTorch machine learning models on Android, iOS, macOS, Linux, and Windows with high performance and low latency.
Key Features
- High Performance: Native FFI bindings for minimal latency
- Cross Platform: Identical APIs across all supported platforms
- User-Controlled Resources: Explicit model lifecycle with load/dispose
- Easy Integration: Simple API for loading models and running inference
- Backend Query: Check available hardware acceleration backends
Quick Start
import 'package:executorch_flutter/executorch_flutter.dart';
// Load a model from asset bundle
final model = await loadModelFromAsset('assets/models/model.pte');
// Prepare input data
final inputTensor = TensorData(
shape: [1, 3, 224, 224],
dataType: TensorType.float32,
data: imageBytes,
name: 'input',
);
// Run inference
final outputs = await model.forward([inputTensor]);
// Process outputs (List<TensorData>)
for (var output in outputs) {
print('Output shape: ${output.shape}');
}
// Clean up
await model.dispose();
Main Classes
ExecuTorchModel: Main API for loading and running inferenceTensorData: Tensor data representationBackend: Hardware acceleration backend enumerationExecuTorchVersion: Library version information
Processors
ExecuTorchPreprocessor: Base class for input preprocessingExecuTorchPostprocessor: Base class for output postprocessingExecuTorchProcessor: Combined preprocessing and postprocessing
Platform Support
- Android: API 23+ (Android 6.0+), arm64-v8a architecture
- iOS: iOS 13.0+, arm64 (device only)
- macOS: macOS 11.0+, arm64 (Apple Silicon)
- Linux: x64 architecture
- Windows: x64 architecture
For detailed documentation and examples, see the class documentation.
Classes
- BackendQuery
- Query functions for hardware acceleration backend availability.
- ExecuTorchLLM
- On-device large language model for streaming text generation.
- ExecutorchManager
- High-level manager for ExecuTorch inference operations
- ExecutorchManagerBase
- Base implementation of ExecutorchManager with shared logic
- ExecuTorchModel
- High-level wrapper for an ExecuTorch model instance
-
ExecuTorchPostprocessor<
R> - Abstract base class for output postprocessing
-
ExecuTorchPreprocessor<
T> - Abstract base class for input preprocessing
-
ExecuTorchProcessor<
T, R> - Abstract base class combining preprocessing and postprocessing
- ExecuTorchVersion
- Library version information.
- GenConfig
-
Generation parameters for
ExecuTorchLLM.generate. - ModelLoadResult
- Model loading result.
- ProcessorTensorUtils
- Utility class for tensor operations in processors
- TensorData
- Tensor data for input/output.
- TensorUtils
- Utility class for working with ExecuTorch tensors
- Tokenizer
- Converts text to token ids and back, independently of any model.
Enums
- Backend
- Hardware acceleration backends supported by ExecuTorch.
- TensorType
- Tensor data type enumeration.
- TokenizerFormat
- Tokenizer formats the native library can read.
Extensions
- ExecutorchManagerAssets on ExecutorchManager
- Asset-bundle loading for ExecutorchManager.
- TensorTypeExtension on TensorType
- Deprecated extension providing backward compatibility for ExtendedTensorType.
Constants
- executorchVersion → const String
- ExecuTorch version this plugin is built against.
Functions
-
loadModelFromAsset(
String assetPath) → Future< ExecuTorchModel> - Loads an ExecuTorch model from the Flutter asset bundle.
-
setNativeDebugLogging(
bool enabled) → void - Set debug logging on or off.
Typedefs
- ExtendedTensorType = TensorType
- Deprecated alias for TensorType.
Exceptions / Errors
- ExecuTorchException
- Base exception class for all ExecuTorch-related errors.
- ExecuTorchInferenceException
- Inference execution errors.
- ExecuTorchIOException
- Network and file I/O errors.
- ExecuTorchMemoryException
- Memory and resource errors.
- ExecuTorchModelException
- Model loading and lifecycle errors.
- ExecuTorchPlatformException
- Platform-specific integration errors.
- ExecuTorchValidationException
- Tensor validation and data errors.
- GenericProcessorException
- Generic processor exception implementation.
- InvalidInputException
- Exception thrown for invalid processor input.
- InvalidOutputException
- Exception thrown for invalid processor output.
- PostprocessingException
- Exception thrown during postprocessing operations.
- PreprocessingException
- Exception thrown during preprocessing operations.
- ProcessorException
- Base exception class for processor-related errors.