effidevFlutter・Cloudflareエッジ・クラウドコスト最適化
日本語

FlutterアプリでオンデバイスLLM(Gemma/Phi-3)を動かす: MediaPipe LLM Inference API活用法

Flutter On-Device LLM MediaPipe Gemma Phi-3 Integration

モバイルアプリ開発におけるトレンドである 온디바이스 AI (On-Device AI) は、クラウドサーバーを介さずにスマートフォン内部のGPU/NPUでLLMを直接実行する技術です。

Googleの MediaPipe LLM Inference API を使うことで、Gemma 2BやPhi-3 Miniなどの軽量言語モデルをFlutterアプリ内で完全オフラインで動作させることができます。

ポイント

  • メリット: サーバーコスト$0、完全オフ라인動作、プライバシー保護、超低レイテンシ。
  • MediaPipe LLM Inference: iOS/Android対応のクロスプラットフォーム・オンデバイス推論エンジン。
  • Int4量子化: 4-bit量子化モデルにより、メモリ消費量を1.5GB未満に抑えます。

1. Flutterにおける実装例

class OnDeviceLlmService {
  static const MethodChannel _channel = MethodChannel('dev.effidev.mediapipe_llm');

  Future<void> initializeModel(String modelPath) async {
    await _channel.invokeMethod('initModel', {'modelPath': modelPath});
  }
}