FlexDelegate class

Flex delegate for running models that use SELECT_TF_OPS.

Deprecated: Google no longer supports the Flex delegate for running legacy TensorFlow ops (google-ai-edge/LiteRT#6458). Convert the model to builtin LiteRT ops instead. For on-device training, persist weights with builtin-op get_weights/set_weights signatures (see ModelCheckpoint) rather than SaveV2/RestoreV2 checkpoints. FlexDelegate still works on the platforms below in 4.x and will be removed in flutter_litert 5.0.0.

The Flex delegate enables TensorFlow operations that are not available as TFLite builtins, such as the gradient ops of some training graphs (e.g., Conv2D, BatchNormalization).

Supported on iOS, macOS, Linux and Windows. Not on Android: Android flex was removed in flutter_litert 4.0.0 because LiteRT 2.x has no flex delegate. There isAvailable is false and create throws. Reconvert the model to LiteRT built-in ops, or stay on flutter_litert 3.10.x with flutter_litert_flex 1.3.0.

Add flutter_litert_flex to your pubspec.yaml to bundle the native library on supported platforms:

dependencies:
  flutter_litert: ^4.1.0
  flutter_litert_flex: ^2.1.0

Then create the delegate. The async create works on every supported platform:

final flex = await FlexDelegate.create();
final options = InterpreterOptions();
options.addDelegate(flex);
final interpreter = Interpreter.fromFile(model, options: options);
Implemented types
Annotations
  • @Deprecated('Google no longer supports the Flex delegate (google-ai-edge/LiteRT#6458). ' 'Convert the model to builtin LiteRT ops instead. ' 'FlexDelegate will be removed in flutter_litert 5.0.0.')

Constructors

FlexDelegate()
Creates a FlexDelegate for SELECT_TF_OPS support.
factory

Properties

base → Pointer<TfLiteDelegate>
Get pointer to TfLiteDelegate
no setteroverride
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

delete() → void
Releases native Flex delegate resources.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

debugIsAndroidOverride ↔ bool?
Overrides the Android check in tests. Null uses Platform.isAndroid.
getter/setter pair
isAvailable → bool
Whether the Flex delegate library is available.
no setter

Static Methods

create() → Future<FlexDelegate>
Creates a FlexDelegate asynchronously.