loadModelFromAsset function

Future<ExecuTorchModel> loadModelFromAsset(
  1. String assetPath
)

Loads an ExecuTorch model from the Flutter asset bundle.

Works on every platform, including web. The asset must be declared under flutter: assets: in the application's pubspec.yaml.

final model = await loadModelFromAsset('assets/models/model.pte');

Throws ExecuTorchException if the asset is missing or the model fails to load.

The return type is routed, not the bare core interface: on web this package exports its own Wasm-backed class under the name ExecuTorchModel, and that class only implements the core interface. Returning the interface here would make ExecuTorchModel m = await loadModelFromAsset(…) a compile error on web — and a baffling one, since both types print as ExecuTorchModel.

Implementation

Future<impl.ExecuTorchModel> loadModelFromAsset(String assetPath) async {
  final byteData = await rootBundle.load(assetPath);
  return impl.ExecuTorchModel.loadFromBytes(byteData.buffer.asUint8List());
}