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, and macOS platforms with high performance and low latency.
Key Features
- High Performance: Optimized for mobile inference with ExecuTorch runtime
- Type Safe: Generated platform communication with Pigeon ensures type safety
- Cross Platform: Identical APIs across Android, iOS, and macOS platforms
- User-Controlled Resources: Explicit model lifecycle management with load/dispose
- Easy Integration: Simple API for loading models and running inference
Quick Start
import 'package:executorch_flutter/executorch_flutter.dart';
// Initialize the manager
await ExecutorchManager.instance.initialize();
// Load a model
final model = await ExecutorchManager.instance.loadModel('path/to/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
- ExecutorchManager: Main entry point for ExecuTorch operations
- ExecuTorchModel: Represents a loaded model instance
- TensorData: Tensor data representation
ModelMetadata
: Model information and specifications
Processors
- ExecuTorchPreprocessor: Base class for input preprocessing
- ExecuTorchPostprocessor: Base class for output postprocessing
- ExecuTorchProcessor: Combined preprocessing and postprocessing
ImageClassificationProcessor
: Ready-to-use image classificationTextClassificationProcessor
: Ready-to-use text classificationAudioClassificationProcessor
: Ready-to-use audio classification
Platform Support
- Android: API 23+ (Android 6.0+), arm64-v8a architecture
- iOS: iOS 13.0+, arm64 (device only, simulator not supported)
- macOS: macOS 12.0+ (Monterey), arm64 only (Apple Silicon)
For detailed documentation and examples, see the individual class documentation.
Classes
- ExecuTorchErrorMapper
- Error mapping utilities for cross-platform consistency
- ExecutorchHostApi
- Host API - Called from Dart to native platforms Minimal interface matching native ExecuTorch: load → forward → dispose Plus utility methods: getLoadedModels, setDebugLogging All methods throw PlatformException on error
- ExecutorchManager
- High-level manager for ExecuTorch inference operations
- 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
- ModelLoadResult
- Model loading result On success: returns unique model ID On failure: platform throws exception
- ProcessorTensorUtils
- Utility class for tensor operations in processors
- TensorData
- Tensor data for input/output
- TensorUtils
- Utility class for working with ExecuTorch tensors
Enums
- TensorType
- Tensor data type enumeration
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