loadModelFromBytes method

  1. @override
Future<ExecuTorchModel> loadModelFromBytes(
  1. Uint8List modelBytes
)
override

Load a model from bytes and cache it.

Subclasses on platforms without dart:ffi must override this. The implementation here delegates to ExecuTorchModel.loadFromBytes, which resolves to the unsupported stub and throws wherever dart:ffi is absent. package:executorch_flutter's web manager overrides it to load through the WebAssembly runner; this is the only method in this class that has that requirement.

Implementation

@override
Future<ExecuTorchModel> loadModelFromBytes(Uint8List modelBytes) async {
  ensureInitialized();

  try {
    final model = await ExecuTorchModel.loadFromBytes(modelBytes);
    loadedModelsMap[model.modelId] = model;
    return model;
  } catch (e) {
    if (e is ExecuTorchException) rethrow;
    throw ExecuTorchModelException(
      'Failed to load model from bytes: $e',
      'bytes_length: ${modelBytes.length}, error: ${e.toString()}',
    );
  }
}